def get_branch_files(repository, check_upstream=False): if check_upstream and repository.github.upstream is not None: git.fetch( 'upstream', '--no-tags', '%s:refs/remotes/upstream/%s' % \ (repository.github.branch, repository.github.branch)) diff_output = git.diff( '--name-only', 'origin/%s..upstream/%s' % \ (repository.github.branch, repository.github.branch), strip=False) git.rebase('upstream/%s' % repository.github.branch) else: diff_output = '\n'.join([ line[3:] for line in git.status('status', '-s', strip=False) if len(line) > 3 ]) new_files = get_eligible_files(repository, diff_output, 'en') lstree_output = git.ls_tree('-r', '--name-only', repository.github.branch, strip=False) all_files = get_eligible_files(repository, lstree_output, 'en') return new_files, all_files
def add_disclaimers_to_learn(repository, language): old_dir = os.getcwd() os.chdir(repository.github.git_root) lstree_output = git.ls_tree('-r', '--name-only', repository.github.branch, strip=False) all_files = get_eligible_files(repository, lstree_output, language) for file in all_files: if file[file.rfind('.') + 1:] == 'html': continue if not os.path.exists(file): continue new_title, old_content, new_content = add_disclaimer_learn( file, language) if old_content != new_content: with open(file, 'w') as f: f.write(new_title) f.write('\n') f.write(new_content) os.chdir(old_dir)
def reprocess(target, source, umask=None): target = os.path.abspath(target) with utils.ChangeDir(source): if umask is not None: os.umask(umask) print('starting processing of all recipes') common.clean_output_dir(target) files = git.ls_tree('HEAD') # do a dry run to catch errors for f in files: file = ' '.join(f[3:]) obj_id = f[2] if file.split('.')[-1] != 'rmd': continue r = common.process(obj_id, '/dev/null', settings.XSLT) # do a real run for f in files: file = f[3] obj_id = f[2] if file.split('.')[-1] != 'rmd': continue print('P {}'.format(file)) common.process(obj_id, common.xml_filename(file, target), settings.XSLT) print('finished processing of files')
def reprocess(target, source, umask = None): target = os.path.abspath(target) with utils.ChangeDir(source): if umask is not None: os.umask(umask) print('starting processing of all recipes') common.clean_output_dir(target) files = git.ls_tree('HEAD') # do a dry run to catch errors for f in files: file = ' '.join(f[3:]) obj_id = f[2] if file.split('.')[-1] != 'rmd': continue r = common.process(obj_id, '/dev/null', settings.XSLT) # do a real run for f in files: file = f[3] obj_id = f[2] if file.split('.')[-1] != 'rmd': continue print('P {}'.format(file)) common.process(obj_id, common.xml_filename(file, target), settings.XSLT) print('finished processing of files')
def main(): os.umask(settings.UMASK) print('starting processing of all recipes') clean_output_dir() files = git.ls_tree('HEAD') # do a dry run to catch errors for f in files: file = ' '.join(f[3:]) obj_id = f[2] if file.split('.')[-1] != 'rmd': continue r = process(obj_id,'/dev/null') # do a real run for f in files: file = f[3] obj_id = f[2] if file.split('.')[-1] != 'rmd': continue print('P {}'.format(file)) process(obj_id, xml_filename(file)) index.update_index(settings.TARGET) print('finished processing of commits')
def test_ls_tree(self): with tempfile.TemporaryDirectory() as tmp: with utils.ChangeDir(tmp): self._setup_git() self._second_commit() tree = git.ls_tree('HEAD') self.assertEqual(tree, result['tree'])
def get_test_metadata(ref_name): print('Retrieving functional test metadata for %s' % ref_name) file_names = git.ls_tree('-r', '--name-only', ref_name, 'portal-web/test/functional').split('\n') return { 'testcases': { get_short_name(file_name): get_commands(ref_name, file_name) for file_name in file_names if file_name.find('.testcase') != -1 }, 'macros': { get_short_name(file_name): get_commands(ref_name, file_name) for file_name in file_names if file_name.find('.macro') != -1 } }
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)