def clone_naver_to(proj_id, path=""): ''' git clone project (to a path if given) >>> clone_naver_to ("aaa", 'a') ''' full_anon_path_naver = get_git_naver_anon(proj_id) cmd = "clone %s %s" % (full_anon_path_naver, path) git.git(cmd)
def destroy(cls, name): """ Destroy the named blueprint. """ if not os.path.isdir(git.repo()): raise NotFoundError(name) try: git.git('branch', '-D', name) except: raise NotFoundError(name)
def submodule_naver_to(proj_id, path=""): ''' git submodule add project (to a path if given) >>> submodule_naver_to ("aaa", 'a') ''' full_anon_path_naver = get_git_naver_anon(proj_id) path_replaced = path.replace('\\', '/') # A/student_repository/tool cmd = "submodule add -f %s %s" % (full_anon_path_naver, path_replaced) git.git(cmd)
def no_pylint_regression(before, after, path): '''Check there are no pylint score regression between before and after. If there was no previous file, check the file lints perfectly.''' command = [] prefix_lint = '{}: lint: '.format(path) prefix_disable = '{}: pylint-disable: '.format(path) for line in git.git(['check-attr', '-a', path]).split('\n'): if line.startswith(prefix_lint): if line[len(prefix_lint):] == 'false': return if line.startswith(prefix_disable): command.append('--disable={}'.format(line[len(prefix_disable):])) if is_python(after): if is_python(before): (score_b, _), (score_a, output_a) = (pylint(f, False, command) for f in [before, after]) if score_a < score_b: error = Exception('pylint regression: {} -> {}'.format( score_b, score_a)) error.output = output_a raise error else: try: pylint(after, True, command) except subprocess.CalledProcessError as process_error: error = Exception('pylint errors') error.output = process_error.output.decode() raise error from None
def downloadFsConfig(): """ Downloads all required config file for the system return path""" try: git('.').clone(repo) except Exception as exp: print(exp) return False else: os.chdir(repoName) print('RepoPath : ' + repoName) return repoName
def getCommits(self): try: dataSetting = self.dataSetting except: print('ERROR, not setting data') g = git.git(path=dataSetting['gitPath']) lCommits = g.getCommits() return lCommits
def commit(self, message=''): """ Create a new revision of this blueprint in the local Git repository. Include the blueprint JSON and any source archives referenced by the JSON. """ git.init() refname = 'refs/heads/{0}'.format(self.name) parent = git.rev_parse(refname) # Start with an empty index every time. Specifically, clear out # source tarballs from the parent commit. if parent is not None: for mode, type, sha, pathname in git.ls_tree(git.tree(parent)): git.git('update-index', '--force-remove', pathname) # Add `blueprint.json` to the index. f = open('blueprint.json', 'w') f.write(self.dumps()) f.close() git.git('update-index', '--add', os.path.abspath('blueprint.json')) # Add source tarballs to the index. for filename in self.sources.itervalues(): git.git('update-index', '--add', os.path.abspath(filename)) # Add `/etc/blueprintignore` and `~/.blueprintignore` to the index. # Since adding extra syntax to this file, it no longer makes sense # to store it as `.gitignore`. f = open('blueprintignore', 'w') for pathname in ('/etc/blueprintignore', os.path.expanduser('~/.blueprintignore')): try: f.write(open(pathname).read()) except IOError: pass f.close() git.git('update-index', '--add', os.path.abspath('blueprintignore')) # Write the index to Git's object store. tree = git.write_tree() # Write the commit and update the tip of the branch. self._commit = git.commit_tree(tree, message, parent) git.git('update-ref', refname, self._commit)
def iter(cls): """ Yield the name of each blueprint. """ if not os.path.isdir(git.repo()): return status, stdout = git.git('branch') for line in stdout.splitlines(): yield line.strip()
def __init__(self, hash_id): self.author_name = git(['show', '-s', '--format=%aN', hash_id]) self.author_email = git(['show', '-s', '--format=%ae', hash_id]) self.subject = git(['show', '-s', '--format=%s', hash_id]) self.message = git(['show', '-s', '--format=%b', hash_id]) self.author_date = git(['show', '-s', '--format=%at', hash_id]) self.author_date = datetime.fromtimestamp(int(self.author_date)) self.author_date = self.author_date.strftime("%Y-%m-%d %H:%M:%S") lines = git(['show', '--name-status', '--format=%n', hash_id]).strip().splitlines() self.files = [line.split()[1] for line in lines] self.mods = [line.split()[0] for line in lines] self.id = git(['rev-parse', hash_id])
def test_git_log_oneline(self): """ test git log command >>> git log --oneline git.py check first two commits included in the message """ msg = git.git(("log", "--oneline", __file__), bVerbose=False) assert_message = f"git message = {msg}" try: self.assertTrue(msg, msg=assert_message) except UnicodeDecodeError: self.assertTrue(msg, msg=assert_message)
def test_git_log(self): """ test git log command >>> git log test_git.py check "Author:", "Date:", "commit" strings are all included in the message """ msg = git.git(("log", __file__), bVerbose=False) try: for token in ("Author:", "Date:", "commit"): self.assertIn(token, msg, msg=f'"{token}" not in "{msg}"') except UnicodeDecodeError: for token in ("Author:", "Date:", "commit"): self.assertIn(token, msg, msg=f'"{token}" not in "{msg}"')
def get(self, **params): self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish('Missing function call') return else: Log.Debug('Recieved a get call for module: ' + module) #TODO ''' Attempt to create a dynamic import, but so far, it sadly breaks access to the PMS API :-( import sys sys.path.append(os.path.join(Core.app_support_path, 'Plug-ins', NAME + '.bundle', 'Contents', 'Code')) mod = import_module(module) modClass = getattr(mod, module)() print 'GED1', dir(modClass) callFunction = getattr(modClass, 'reqprocess') self = modClass().reqprocess(self) ''' if module == 'git': self = git().reqprocess(self) elif module == 'logs': self = logs().reqprocess(self) elif module == 'pms': self = pms().reqprocess(self) elif module == 'settings': self = settings().reqprocess(self) elif module == 'findMedia': self = findMedia().reqprocess(self) elif module == 'jsonExporter': # self = jsonExporter().reqprocess(self) try: m = getattr(module) except Exception, e: print 'Ged json Exception: ' + str(e) elif module == 'language': self = language().reqprocess(self)
def init_or_update_user_umbrella(umbrella_folder, user, section_url_dict): assert os.path.exists( umbrella_folder ), f'init_or_update_user_umbrella: missing folder {umbrella_folder}' assert isinstance( user, str), f'init_or_update_user_umbrella: type({user}) = {type(user)}' assert isinstance( section_url_dict, dict ), f'init_or_update_user_umbrella: type({section_url_dict}) = {type(section_url_dict)}' user_folder = os.path.abspath(os.path.join(umbrella_folder, user)) if not os.path.exists(user_folder): os.makedirs(user_folder) start_folder = os.getcwd() os.chdir(user_folder) if not os.path.exists('.git'): # initialize user umbrella repo init_user_umbrella_repo(section_url_dict) # end initializing user umbrella repo # section loop for section in section_url_dict: if section not in get_remote_list(): print(f'remote add {section} {section_url_dict[section]}') git.git(('remote', 'add', section, section_url_dict[section])) print('git remote -v') git.git(('remote', '-v')) if not os.path.exists(os.path.join(user_folder, section)): print(f"folder missing : {os.path.join(user_folder, section)}") print('subtree add') git.git( ('subtree', 'add', f'--prefix={section}', section, 'master')) else: print(f'subtree pull {section_url_dict[section]}') git.git( ('subtree', 'pull', f'--prefix={section}', section, 'master')) os.chdir(start_folder) return {'name': user, 'path': user_folder}
def init_user_umbrella_repo(user_dict): # initialize user umbrella repo print('git init') git.git(('init', )) # repository info as the first commit with open('repo_list.txt', 'w') as repo_list_file: repo_list_file.write(pprint.pformat(user_dict)) git.git(('add', 'repo_list.txt')) git.git(('commit', '-m', 'initial commit'))
def get(self, **params): module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish('Missing function call') return else: Log.Debug('Recieved a get call for module: ' + module) #TODO ''' Attempt to create a dynamic import, but so far, it sadly breaks access to the PMS API :-( import sys sys.path.append(os.path.join(Core.app_support_path, 'Plug-ins', NAME + '.bundle', 'Contents', 'Code')) mod = import_module(module) modClass = getattr(mod, module)() print 'GED1', dir(modClass) callFunction = getattr(modClass, 'reqprocess') self = modClass().reqprocess(self) ''' if module == 'git': self = git().reqprocess(self) elif module == 'logs': self = logs().reqprocess(self) elif module == 'pms': self = pms().reqprocess(self) elif module == 'settings': self = settings().reqprocess(self) elif module == 'findMedia': self = findMedia().reqprocess(self) elif module == 'language': self = language().reqprocess(self) elif module == 'plex2csv': self = plex2csv().reqprocess(self) elif module == 'wt': self = wt().reqprocess(self) elif module == 'scheduler': print 'Ged WebSrv Scheduler' self = scheduler().reqprocess(self) else: self.clear() self.set_status(412) self.finish('Unknown module call') return
def get_latest_commit(): """最新のコミットのCommitオブジェクトを返す""" commits = [] commits_string = git("log", "-n", "1") # analyzing commitlines = commits_string.split("\n\n") commits_string_list = [] while 0 < len(commitlines): commits_string_list.append("\n".join(commitlines[0:2])) commitlines = commitlines[2:] # parse for commitline in commits_string_list: commitdata = parse_commit(commitline) commits.append(Commit(**commitdata)) return commits[0]
def get_commits(): """シェルからコミットログを取得してCommitオブジェクトにしてリストで返す""" commits = [] commits_string = git("log") # analyzing commitlines = commits_string.split("\n\n") commits_string_list = [] while 0 < len(commitlines): commits_string_list.append("\n".join(commitlines[0:2])) commitlines = commitlines[2:] # parse for commitline in commits_string_list: commitdata = parse_commit(commitline) commits.append(Commit(**commitdata)) return commits
def get(self, **params): module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish('Missing function call') return else: Log.Debug('Recieved a get call for module: ' + module) #TODO ''' Attempt to create a dynamic import, but so far, it sadly breaks access to the PMS API :-( import sys sys.path.append(os.path.join(Core.app_support_path, 'Plug-ins', NAME + '.bundle', 'Contents', 'Code')) mod = import_module(module) modClass = getattr(mod, module)() print 'GED1', dir(modClass) callFunction = getattr(modClass, 'reqprocess') self = modClass().reqprocess(self) ''' if module == 'git': self = git().reqprocess(self) elif module == 'logs': self = logs().reqprocess(self) elif module == 'pms': self = pms().reqprocess(self) elif module == 'settings': self = settings().reqprocess(self) elif module == 'findMedia': self = findMedia().reqprocess(self) elif module == 'language': self = language().reqprocess(self) elif module == 'plex2csv': self = plex2csv().reqprocess(self) elif module == 'wt': self = wt().reqprocess(self) else: self.clear() self.set_status(412) self.finish('Unknown module call') return
def put(self, **params): module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish("<html><body>Missing function call</body></html>") return else: Log.Debug('Recieved a PUT call for module: ' + module) if module == 'settings': self = settings().reqprocessPUT(self) elif module == 'git': self = git().reqprocessPUT(self) elif module == 'pms': self = pms().reqprocessPUT(self) else: self.clear() self.set_status(412) self.finish("<html><body>Unknown module call</body></html>") return
def put(self, **params): self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish("<html><body>Missing function call</body></html>") return else: Log.Debug('Recieved a PUT call for module: ' + module) if module == 'settings': self = settings().reqprocessPUT(self) elif module == 'git': self = git().reqprocessPUT(self) elif module == 'pms': self = pms().reqprocessPUT(self) else: self.clear() self.set_status(412) self.finish("<html><body>Unknown module call</body></html>") return
def get(self, **params): module = self.get_argument('module', 'missing') if module == 'missing': self.clear() self.set_status(404) self.finish("<html><body>Missing function call</body></html>") return else: Log.Debug('Recieved a get call for module: ' + module) #TODO ''' import sys sys.path.append(os.path.join(Core.app_support_path, 'Plug-ins', NAME + '.bundle', 'Contents', 'Code')) mod = import_module(module) modClass = getattr(mod, module)() print 'GED1', dir(modClass) callFunction = getattr(modClass, 'reqprocess') self = modClass().reqprocess(self) ''' if module == 'git': self = git().reqprocess(self) elif module == 'logs': self = logs().reqprocess(self) elif module == 'pms': self = pms().reqprocess(self) elif module == 'settings': self = settings().reqprocess(self) elif module == 'findUnmatched': self = findUnmatched().reqprocess(self) else: self.clear() self.set_status(412) self.finish("<html><body>Unknown module call</body></html>") return
def get_git_log_dict_list(self, filename): """ :param str filename:file under evaluation :return: list(dict) """ # git log with follow rename # TODO : consider using -C option instead of changing folders # TODO : as a method of the evaluator class? # TODO : pair git command & regex pattern ? # some file name may contain space git_cmd_string = self.get_git_cmd(filename) # other candidates # ref : git log help # git log --format="%h, %ai, %an %ae '%s'" --numstat --after=<date> --before=<date> # run git command git_log_msg = git.git(git_cmd_string, bVerbose=False) # extract information from git log message and return its list return self.get_dict_list_from_git_log(git_log_msg)
def run_regression_hooks(before, before_sha, after, after_sha): '''Run regressions hook on the given before/after file versions.''' for line in git.git(['diff', '--name-status', '--diff-filter=ACMR', '{}..{}'.format( before_sha, after_sha)]).split('\n'): if line == '': continue status, file = line.split('\t', maxsplit=1) if status == 'A': before_f = None after_f = '{}/{}'.format(before, file) elif status in ['C', 'M']: before_f = '{}/{}'.format(before, file) after_f = '{}/{}'.format(after, file) elif status.startswith('R'): before_f, after_f = file.split('\t') file = after_f before_f = '{}/{}'.format(before, file) after_f = '{}/{}'.format(after, file) log.info('validate {status} file {path!r}', status=status_to_string(status), path=file) for hook in hooks.REGRESSION_HOOKS: try: hook(before_f, after_f, file) except Exception as error: raise Exception('error on {}'.format(file)) from error
def test_git(self): msg = git.git("", bVerbose=False) expected = "git help" # https://stackoverflow.com/questions/606191/convert-bytes-to-a-string self.assertIn(expected, msg, msg='"%s" not in "%s"' % (expected, msg))
def setUp(self): super(TestGit, self).setUp() self.git_obj = git.git(self.bot)
def get_remote_list(): return [ remote_line.strip() for remote_line in git.git(('remote', ), bVerbose=False).splitlines() ]
def test_git_config(self): msg = git.git(["config"], bVerbose=False) expected = "usage: git config" self.assertIn(expected, msg, msg='"%s" not in "%s"' % (expected, msg))