MCPcopy Create free account
hub / github.com/danvk/webdiff / run

Function run

webdiff/app.py:301–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

299
300
301def run():
302 global DIFF, PORT, HOSTNAME, GIT_CONFIG
303 try:
304 parsed_args = argparser.parse(sys.argv[1:], VERSION)
305 except argparser.UsageError as e:
306 sys.stderr.write('Error: %s\n\n' % e)
307 usage_and_die()
308
309 GIT_CONFIG = options.get_config()
310 WEBDIFF_CONFIG = GIT_CONFIG['webdiff']
311 DIFF = argparser.diff_for_args(parsed_args, WEBDIFF_CONFIG)
312
313 if DEBUG:
314 sys.stderr.write('Invoked as: %s\n' % sys.argv)
315 sys.stderr.write('Args: %s\n' % parsed_args)
316 sys.stderr.write('Diff: %s\n' % DIFF)
317 sys.stderr.write('GitConfig: %s\n' % GIT_CONFIG)
318
319 PORT = pick_a_port(parsed_args, WEBDIFF_CONFIG)
320 HOSTNAME = (
321 parsed_args.get('host')
322 or os.environ.get('WEBDIFF_HOST')
323 or WEBDIFF_CONFIG['host']
324 )
325 if HOSTNAME == '<hostname>':
326 _hostname = platform.node()
327 # platform.node will return empty string if it can't find the hostname
328 if not _hostname:
329 sys.stderr.write('Warning: hostname could not be determined\n')
330 else:
331 HOSTNAME = _hostname
332
333 run_in_process = os.environ.get('WEBDIFF_RUN_IN_PROCESS') or (
334 DEBUG and not DEBUG_DETACH
335 )
336
337 if not os.environ.get('WEBDIFF_LOGGED_MESSAGE'):
338 # Printing this in the main process gives you your prompt back more cleanly.
339 print(
340 """Serving diffs on http://%s:%s
341Close the browser tab when you&#x27;re done to terminate the process."""
342 % (HOSTNAME, PORT)
343 )
344 os.environ['WEBDIFF_LOGGED_MESSAGE'] = '1'
345
346 if run_in_process:
347 run_http()
348 else:
349 os.environ['WEBDIFF_RUN_IN_PROCESS'] = '1'
350 os.environ['WEBDIFF_PORT'] = str(PORT)
351 if os.environ.get('WEBDIFF_FROM_GIT_DIFFTOOL'):
352 # git difftool will clean up these directories when we detach.
353 # To make them accessible to the child process, we make a (shallow) copy.
354 assert 'dirs' in parsed_args
355 dir_a, dir_b = parsed_args['dirs']
356 copied_dir_a = make_resolved_dir(dir_a)
357 copied_dir_b = make_resolved_dir(dir_b)
358 os.environ['WEBDIFF_DIR_A'] = copied_dir_a

Callers 1

app.pyFile · 0.70

Calls 4

make_resolved_dirFunction · 0.90
usage_and_dieFunction · 0.85
pick_a_portFunction · 0.85
run_httpFunction · 0.85

Tested by

no test coverage detected