def clone(self, args=None): # Update the root folder first root_config = git_get_current_branch(self.root_dir) if not root_config: print("Not a git repository") else: git_fetch(self.root_dir, root_config) git_checkout(self.root_dir, root_config) git_pull(self.root_dir, root_config) config = self.get_project_config(reload=True) for m in config["modules"]: module_dir = os.path.join(self.root_dir, m["folder"]) if os.path.exists(module_dir): git_fetch(self.root_dir, m) git_checkout(self.root_dir, m) git_pull(self.root_dir, m)
def switch_subproject(release, git_wrkspc, svn_wrkspc, svn_rel_base, save_snapshot=False, command_verbose=False, debug=False, verbose=False): # switch Git sandbox to next release if verbose: print("-- switch Git to %s" % (release, )) try: git_checkout(branch_name=release, sandbox_dir=git_wrkspc, debug=debug, verbose=command_verbose) git_submodule_update(initialize=True, sandbox_dir=git_wrkspc, debug=debug, verbose=command_verbose) except GitBadPathspecException: print("ERROR: No Git branch for %s" % (release, )) return False # clean Git repo after update __delete_untracked(git_wrkspc, debug=debug, verbose=command_verbose) if save_snapshot: __status_snapshot(git_wrkspc, release, suffix="check", debug=debug, verbose=command_verbose) # switch SVN sandbox to next release if verbose: print("-- switch SVN to %s" % (release, )) rel_url = os.path.join(svn_rel_base, release) for _ in svn_switch(rel_url, sandbox_dir=svn_wrkspc, debug=debug, verbose=command_verbose): pass return True
def checkout(self, args=None): config = self.get_project_config() for m in config["modules"]: git_checkout(self.root_dir, m)
def main(branch, root): serializer_directory = os.path.join(root, 'apiv2/serializers') view_directory = os.path.join(root, 'apiv2/views') files = [os.path.join(root, 'apiv2/fields.py')] changed_files = get_changed_files(branch) current_ff = FieldFinder.crawl(serializer_directory, view_directory, files=files) with git_checkout(branch) as current_branch: previous_ff = FieldFinder.crawl(serializer_directory, view_directory, files=files) affected_serializers = current_ff.difference(previous_ff) if affected_serializers: print('From {} -> {}\n'.format( colored(branch, consts.Colours.INFO, attrs=['bold']), colored(current_branch, consts.Colours.INFO, attrs=['bold']))) if affected_serializers.added: for serializer_name in affected_serializers.added: name_desc = colored('+ ' + serializer_name + '\n', consts.Colours.ADDED, attrs=['underline', 'bold']) fields_dict = (current_ff.find_serializer_fields( serializer_name).as_dict()) fields_pp = '\n'.join( '++ ' + line for line in pformat(fields_dict).split('\n')) fields_pp = colored(fields_pp, consts.Colours.ADDED) print(name_desc + fields_pp + '\n') if affected_serializers.removed: removed_pp = [ '- ' + serializer_name for serializer_name in affected_serializers.removed ] cprint(removed_pp, consts.Colours.REMOVED) registry = current_ff.serializer_registry for filename in changed_files: for serializer_name in registry.get_classes_in_file(filename): # this case handled above if serializer_name in affected_serializers.added: continue current_fields = current_ff.find_serializer_fields(serializer_name) previous_fields = previous_ff.find_serializer_fields( serializer_name) diff = current_fields.stringify_diff(previous_fields) if diff: name_desc = colored(serializer_name, consts.Colours.ADDED, attrs=['underline', 'bold']) print(name_desc) print(diff)
def main(): cmds = load_cmds(tools) parser = setupCmdLine(cmds) opts, args = parser.parse_args() try: git_repo = args[0] except: exit_msg(parser.get_usage()) runlist = [cmd(primary_opt, debug=opts.debug) for cmd, primary_opt in zip(cmds, map(lambda x: getattr(opts, x.name, None), cmds)) if primary_opt] if len(runlist) == 0: exit_msg("Must specify a command to be run") out = {} if opts.update: in_paths = [opts.update] out_path = opts.update else: in_paths = opts.in_paths out_path = opts.out_path for in_path in in_paths: d = json.load(open(in_path, "r")) for commit, vals in d.iteritems(): if not commit in out: out[commit] = vals else: out[commit]["results"].update(vals["results"]) try: git_new = tempfile.mkdtemp() log("Temp dir created: %s", git_new) log("Cloning repo: %s -> %s", git_repo, git_new) git_clone(git_repo, git_new) skip = [] process =[] for comm in git_log(git_new): if comm["commit"] in out and all([c.name in out[comm["commit"]]["results"] for c in runlist]): skip.append(comm) else: process.append(comm) log("%d commits: processing %d, skipping %d" % (len(skip)+len(process), len(process), len(skip))) for idx, comm in enumerate(process): sha1 = comm["commit"] rec = { "date" : comm["date"].strftime("%Y-%m-%d %H-%M-%S %z"), "author" : comm["author"] } if sha1 in out and "results" in out[sha1]: rec["results"] = out[sha1] else: rec["results"] = {} if opts.reload: schedule = runlist else: schedule = [cmd for cmd in runlist if cmd.name not in rec["results"]] log("Checking out revision %s [%d/%d]", comm["commit"], idx+1, len(process)) git_checkout(git_new, sha1) for cmd in schedule: rec["results"][cmd.name] = {} try: rec["results"][cmd.name] = cmd.run(git_new) except CmdError,e: log("Command '%r' failed with %d", e.cmd, e.ret) log("Output: %s", e.out) except Exception, e: log("Failed to get output of command: %r",e)
def checkout(root, config, args=None): for m in config["modules"]: git_checkout(root_dir, m, args)