def run_main(): """Some initial logging, then run main().""" # Ensure any errors occurring in the setup are sent to stderr, while the # code below directs them to stderr once rather than twice. try: with p4gf_log.ExceptionLogger(squelch=False, write_to_stderr_=True): p4gf_version_3.log_version_extended() log_l10n() p4gf_version_3.version_check() except: # pylint: disable=bare-except # Cannot continue if above code failed. sys.exit(1) # main() already writes errors to stderr, so don't let logger do it again p4gf_log.run_with_exception_logger(main_ignores, write_to_stderr=False)
p4 = connect_p4(client=p4gf_util.get_object_client_name()) if not p4: return 2 # Sanity check the connection (e.g. user logged in?) before proceeding. try: p4.fetch_client() except P4.P4Exception as e: sys.stderr.write("P4 exception occurred: {}".format(e)) sys.exit(1) if args.all: try: delete_all(args, p4) except P4.P4Exception as e: sys.stderr.write("{}\n".format(e)) sys.exit(1) else: # Delete the client(s) for the named view(s). for view in args.views: client_name = p4gf_context.view_to_client_name(view) try: delete_client(args, p4, client_name) except P4.P4Exception as e: sys.stderr.write("{}\n".format(e)) if not args.delete: print("This was report mode. Use -y to make changes.") if __name__ == "__main__": p4gf_log.run_with_exception_logger(main, write_to_stderr=True)
sys.stderr.write(_('Defined views:\n\t')) sys.stderr.write('\n\t'.join(view_list)) sys.stderr.write('\n') sys.exit(2) view_list = args.views for view_name in view_list: sys.argv = [ 'p4gf_auth_server.py' , '--user={}'.format(p4gf_const.P4GF_USER) , 'git-upload-pack' , view_name] p4gf_auth_server.main(poll_only=True) if __name__ == "__main__": # Ensure any errors occurring in the setup are sent to stderr, while the # code below directs them to stderr once rather than twice. try: # thwart pylint identical code detection with two empty lines below with p4gf_log.ExceptionLogger(squelch=False, write_to_stderr_=True): p4gf_log.record_argv() p4gf_version.log_version() log_l10n() p4gf_version.version_check() # pylint: disable=W0702 except: # Cannot continue if above code failed. exit(1) # main() already writes errors to stderr, so don't let logger do it again p4gf_log.run_with_exception_logger(main, write_to_stderr=False)
""" p4gf_util.write_dict_to_file(package_dict, _packet_filename(ctx.config.repo_name)) def write_packet_fast_push(fast_push): """Serialize a very small "this push was handled via FastPush" packet file.""" package = {"fast_push": True} _write_packet_dict(fast_push.ctx, package) def main(): """Either do the work now or fork a process to do it later.""" for h in ['-?', '-h', '--help']: if h in sys.argv: print(_('Git Fusion pre-receive hook.')) return 2 p4gf_version_3.print_and_exit_if_argv() p4gf_branch.init_case_handling() prl = PreReceiveTupleLists.from_stdin(sys.stdin) # Preflight rejects the push by raising an exception, which is handled # in the logging code by printing the message to stderr. with Timer('pre-receive'): return PreflightHook('pre-receive preflight', prl).do_it() if __name__ == "__main__": p4gf_log.run_with_exception_logger(main, write_to_stderr=True, squelch_exceptions=[PreflightException])
#pylint:disable=E0602 #pylint does not know about BrokenPipeError def main_ignores(): """ Calls main() while ignoring certain exceptions that we cannot do anything with and are best served by concisely logging their occurrence. """ try: return main() except BrokenPipeError: LOG.warn("client connection terminated?") #pylint:enable=E0602 if __name__ == "__main__": # Ensure any errors occurring in the setup are sent to stderr, while the # code below directs them to stderr once rather than twice. try: with p4gf_log.ExceptionLogger(squelch=False, write_to_stderr_=True): p4gf_log.record_argv() p4gf_version.log_version() log_l10n() p4gf_version.version_check() # pylint: disable=W0702 except: # Cannot continue if above code failed. sys.exit(1) # main() already writes errors to stderr, so don't let logger do it again p4gf_log.run_with_exception_logger(main_ignores, write_to_stderr=False)