def main(): """Process command line arguments and call functions to do the real work of cleaning up the Git mirror and Perforce workspaces. """ # Set up argument parsing. parser = p4gf_util.create_arg_parser( "Deletes Git Fusion repositories and workspaces.") parser.add_argument("-a", "--all", action="store_true", help="remove all known Git mirrors") parser.add_argument("-y", "--delete", action="store_true", help="perform the deletion") parser.add_argument("-v", "--verbose", action="store_true", help="print details of deletion process") parser.add_argument('views', metavar='view', nargs='*', help='name of view to be deleted') args = parser.parse_args() # Check that either --all or 'views' was specified. if not args.all and len(args.views) == 0: sys.stderr.write('Missing view names; try adding the --all option.\n') sys.exit(2) 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.")
def init_repo(p4, view_name): """Create view and repo if necessary. Does NOT copy p4 to the repo (that's p4gf_copy_p2g's job). Returns one of the INIT_REPO_* constants. """ client_name = p4gf_context.view_to_client_name(view_name) p4gf_dir = p4gf_util.p4_to_p4gf_dir(p4) view_dirs = p4gf_view_dirs.from_p4gf_dir(p4gf_dir, view_name) result = create_p4_client(p4, view_name, client_name, view_dirs.p4root) if result > INIT_REPO_OK: return result create_perm_groups(p4, view_name) p4gf_copy_p2g.create_git_repo(view_dirs.GIT_DIR) ensure_deny_rewind(view_dirs.GIT_WORK_TREE) install_hook(view_dirs.GIT_DIR) create_p4_client_root(view_dirs.p4root) p4gf_rc.update_file(view_dirs.rcfile, client_name, view_name) LOG.debug("repository creation for %s complete", view_name) # return the result of creating the client, to indicate if the client # had already been set up or not return result