|
78 | 78 | parser.add_argument('project')
|
79 | 79 | parser.add_argument('-D', '--debug', action='store_true',
|
80 | 80 | help='Enable debug prints')
|
81 |
| - parser.add_argument('-c', '--config', required=True, |
| 81 | + parser.add_argument('-c', '--config', |
82 | 82 | help='config file in JSON/YAML format')
|
83 | 83 | parser.add_argument('-m', '--messages',
|
84 | 84 | help='path to the Messages binary')
|
|
95 | 95 |
|
96 | 96 | logger = logging.getLogger(os.path.basename(sys.argv[0]))
|
97 | 97 |
|
98 |
| - config = read_config(logger, args.config) |
99 |
| - if config is None: |
100 |
| - logger.error("Cannot read config file from {}".format(args.config)) |
101 |
| - sys.exit(1) |
| 98 | + if args.config: |
| 99 | + config = read_config(logger, args.config) |
| 100 | + if config is None: |
| 101 | + logger.error("Cannot read config file from {}".format(args.config)) |
| 102 | + sys.exit(1) |
| 103 | + else: |
| 104 | + config = {} |
102 | 105 |
|
103 | 106 | # Make sure the log directory exists.
|
104 |
| - try: |
105 |
| - logdir = config["logdir"] |
106 |
| - except: |
107 |
| - logger.error("'logdir' does not exist in configuration") |
108 |
| - sys.exit(1) |
109 |
| - else: |
| 107 | + logdir = config.get("logdir") |
| 108 | + if logdir: |
110 | 109 | check_create_dir(logdir)
|
111 | 110 |
|
112 | 111 | if args.messages:
|
|
129 | 128 | logger.debug("Source root = {}".format(source_root))
|
130 | 129 |
|
131 | 130 | project_config = None
|
132 |
| - try: |
133 |
| - projects = config['projects'] |
134 |
| - if projects: |
135 |
| - if projects.get(args.project): |
136 |
| - project_config = projects.get(args.project) |
137 |
| - else: |
138 |
| - for proj in projects.keys(): |
139 |
| - try: |
140 |
| - pattern = re.compile(proj) |
141 |
| - except re.error: |
142 |
| - logger.error("Not a valid regular expression: {}". |
143 |
| - format(proj)) |
144 |
| - continue |
145 |
| - |
146 |
| - if pattern.match(args.project): |
147 |
| - logger.debug("Project '{}' matched pattern '{}'". |
148 |
| - format(args.project, proj)) |
149 |
| - project_config = projects.get(proj) |
150 |
| - break |
151 |
| - except KeyError: |
152 |
| - # The project has no config, that's fine - defaults will be used. |
153 |
| - pass |
| 131 | + projects = config.get('projects') |
| 132 | + if projects: |
| 133 | + if projects.get(args.project): |
| 134 | + project_config = projects.get(args.project) |
| 135 | + else: |
| 136 | + for proj in projects.keys(): |
| 137 | + try: |
| 138 | + pattern = re.compile(proj) |
| 139 | + except re.error: |
| 140 | + logger.error("Not a valid regular expression: {}". |
| 141 | + format(proj)) |
| 142 | + continue |
| 143 | + |
| 144 | + if pattern.match(args.project): |
| 145 | + logger.debug("Project '{}' matched pattern '{}'". |
| 146 | + format(args.project, proj)) |
| 147 | + project_config = projects.get(proj) |
| 148 | + break |
154 | 149 |
|
155 | 150 | hookdir = config.get('hookdir')
|
156 | 151 | if hookdir:
|
|
236 | 231 |
|
237 | 232 | # Log messages to dedicated log file if running in batch mode.
|
238 | 233 | if args.batch:
|
| 234 | + if not logdir: |
| 235 | + logger.error("The logdir property is required in batch mode") |
| 236 | + sys.exit(1) |
239 | 237 | logfile = os.path.join(logdir, args.project + ".log")
|
240 | 238 | logger.debug("Switching logging to the {} file".
|
241 | 239 | format(logfile))
|
|
274 | 272 | args.project + "-mirror.lock"))
|
275 | 273 | try:
|
276 | 274 | with lock.acquire(timeout=0):
|
| 275 | + proxy = config.get('proxy') if use_proxy else None |
277 | 276 | if prehook:
|
278 | 277 | logger.info("Running pre hook")
|
279 | 278 | if run_hook(logger, prehook,
|
280 |
| - os.path.join(source_root, args.project), |
281 |
| - config['proxy'] if use_proxy else None, |
| 279 | + os.path.join(source_root, args.project), proxy, |
282 | 280 | hook_timeout) != 0:
|
283 | 281 | logger.error("pre hook failed")
|
284 | 282 | logging.shutdown()
|
|
308 | 306 | repo_type,
|
309 | 307 | args.project,
|
310 | 308 | config.get('commands'),
|
311 |
| - config['proxy'] if use_proxy else None, |
| 309 | + proxy, |
312 | 310 | None,
|
313 | 311 | command_timeout)
|
314 | 312 | if not repo:
|
|
326 | 324 | if posthook:
|
327 | 325 | logger.info("Running post hook")
|
328 | 326 | if run_hook(logger, posthook,
|
329 |
| - os.path.join(source_root, args.project), |
330 |
| - config['proxy'] if use_proxy else None, |
| 327 | + os.path.join(source_root, args.project), proxy, |
331 | 328 | hook_timeout) != 0:
|
332 | 329 | logger.error("post hook failed")
|
333 | 330 | logging.shutdown()
|
|
0 commit comments