| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 | 2 # coding: utf-8 |
| 3 | 3 |
| 4 import argparse | 4 import argparse |
| 5 import datetime | 5 import datetime |
| 6 import errno | 6 import errno |
| 7 import hashlib | 7 import hashlib |
| 8 import io | 8 import io |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 | 91 |
| 92 class Parameters: | 92 class Parameters: |
| 93 """This class loads config file and parses command line parameters. | 93 """This class loads config file and parses command line parameters. |
| 94 Values are stored in attibutes of this class instance. | 94 Values are stored in attibutes of this class instance. |
| 95 """ | 95 """ |
| 96 def __init__(self): | 96 def __init__(self): |
| 97 cli_parameters = vars(Parameters._parse_command_line()) | 97 cli_parameters = vars(Parameters._parse_command_line()) |
| 98 config_parameters = Parameters._load_config(cli_parameters["config"]) | 98 config_parameters = Parameters._load_config(cli_parameters["config"]) |
| 99 for field in cli_parameters.keys(): | 99 for field in cli_parameters.keys(): |
| 100 config_value = config_parameters[field] if field in config_parameter s else None | 100 value = cli_parameters[field] |
| 101 value = cli_parameters[field] if cli_parameters[field] is not None e lse config_value | 101 if value is None: |
|
tschuster
2016/11/21 18:07:55
Can't you just write:
value = cli_parameters[field
sergei
2016/11/22 09:23:31
Changed. Now lines are not so long and you are rig
| |
| 102 value = config_parameters.get(field) | |
| 102 setattr(self, field, value) | 103 setattr(self, field, value) |
| 103 | 104 |
| 104 @staticmethod | 105 @staticmethod |
| 105 def _parse_command_line(): | 106 def _parse_command_line(): |
| 106 parser = argparse.ArgumentParser(description='Run crawler') | 107 parser = argparse.ArgumentParser(description='Run crawler') |
| 107 parser.add_argument( | 108 parser.add_argument( |
| 108 '-c', '--config', type=str, | 109 '-c', '--config', type=str, |
| 109 help='path to config file, example is config.json.example' | 110 help='path to config file, example is config.json.example' |
| 110 ) | 111 ) |
| 111 parser.add_argument( | 112 parser.add_argument( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 237 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 237 DEPENDENCY_SCRIPT = os.path.join(BASE_DIR, "ensure_dependencies.py") | 238 DEPENDENCY_SCRIPT = os.path.join(BASE_DIR, "ensure_dependencies.py") |
| 238 | 239 |
| 239 try: | 240 try: |
| 240 subprocess.check_call([sys.executable, DEPENDENCY_SCRIPT, BASE_DIR]) | 241 subprocess.check_call([sys.executable, DEPENDENCY_SCRIPT, BASE_DIR]) |
| 241 except subprocess.CalledProcessError as e: | 242 except subprocess.CalledProcessError as e: |
| 242 print >>sys.stderr, e | 243 print >>sys.stderr, e |
| 243 print >>sys.stderr, "Failed to ensure dependencies being up-to-date!" | 244 print >>sys.stderr, "Failed to ensure dependencies being up-to-date!" |
| 244 | 245 |
| 245 run() | 246 run() |
| LEFT | RIGHT |