Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: run.py

Issue 29356103: Issue 3943 - add support of configuration file
Left Patch Set: Created Oct. 6, 2016, 1:03 p.m.
Right Patch Set: address comments Created Nov. 22, 2016, 9:20 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « config.json.example ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld