def _get_repo(self, name): root = repository_path(name) if os.path.isdir(root): repo = GitRepoManager() repo.open_repo(root) return repo
def get_review_status(record): ms = 0 ritems = [] root = repository_path(record.repository_identifier) if os.path.isdir(root): repo = Repo(root) for m, func in (('blanks', is_blank_reviewed), ('intercepts', is_intercepts_reviewed), ('icfactors', is_icfactors_reviewed)): p = analysis_path(record, record.repository_identifier, modifier=m) if os.path.isfile(p): with open(p, 'r') as rfile: obj = json.load(rfile) date = repo.git.log('-1', '--format=%cd', p) items = func(obj, date) if items: if reviewed(items): ms += 1 ritems.extend(items) # setattr(record, '{}_review_status'.format(m), (reviewed, date)) record.review_items = ritems ret = 'Intermediate' # intermediate if not ms: ret = 'Default' # default elif ms == 3: ret = 'All' # all record.review_status = ret
def load_spectrometer_parameters(self, spec_sha): if spec_sha: name = add_extension(spec_sha, '.json') p = repository_path(self.repository_identifier, name) sd = get_spec_sha(p) self.source_parameters = sd['spectrometer'] self.gains = sd['gains'] self.deflections = sd['deflections']
def get_frozen_flux(repo, irradiation): path = repository_path(repo, '{}.json'.format(irradiation)) fd = {} if path: fd = dvc_load(path) for fi in fd.values(): fi['j'] = ufloat(*fi['j'], tag='J') return fd
def push_repositories(ps, remote='origin', branch='master', quiet=True): for p in ps: pp = repository_path(p) # repo = Repo(pp) repo = GitRepoManager() repo.open_repo(pp) if repo.smart_pull(remote=remote, branch=branch, quiet=quiet): repo.push(remote=remote, branch=branch)
def _fetch(self): period = 60 while 1: for name in list_local_repos(): r = Repo(repository_path(name)) try: r.git.fetch() except GitCommandError as e: self.warning('error examining {}. {}'.format(name, e)) time.sleep(1) time.sleep(period)
def list_local_repos(): for i in os.listdir(paths.repository_dataset_dir): if i.startswith('.'): continue elif i.startswith('~'): continue d = repository_path(i) if os.path.isdir(d): gd = os.path.join(d, '.git') if os.path.isdir(gd): r = Repo(d) yield i, r.active_branch.name
def find_interpreted_age_path(idn, repositories, prefixlen=3): prefix = idn[:prefixlen] suffix = '{}*.ia.json'.format(idn[prefixlen:]) # ret = [] # for e in repositories: # pathname = os.path.join(paths.repository_dataset_dir, # e, prefix, 'ia', suffix) # ps = glob.glob(pathname) # if ps: # ret.extend(ps) ret = [p for repo in repositories for p in glob.glob(repository_path(repo, prefix, 'ia', suffix))] return ret
def repository_has_staged(ps, remote='origin', branch='master'): if not hasattr(ps, '__iter__'): ps = (ps,) changed = [] # repo = GitRepoManager() for p in ps: pp = repository_path(p) repo = Repo(pp) if repo.git.log('{}/{}..HEAD'.format(remote, branch), '--oneline'): changed.append(p) return changed
def update(self, fetch=True): name = self.name p = repository_path(name) try: try: a, b = ahead_behind(p, fetch=fetch) except InvalidGitRepositoryError: return True self.ahead = a self.behind = b self.status = '{},{}'.format(a, b) self.refresh_needed = True return True except GitCommandError: pass
def perform(self, event): from git import Repo from git.exc import InvalidGitRepositoryError from pychron.paths import paths remote = 'origin' branch = 'master' repos = [] for d in os.listdir(paths.repository_dataset_dir): if d.startswith('.') or d.startswith('~'): continue try: r = Repo(repository_path(d)) except InvalidGitRepositoryError: continue repos.append(r) n = len(repos) pd = myProgressDialog(max=n - 1, can_cancel=True, can_ok=False) pd.open() shared = False for r in repos: pd.change_message('Fetch {}'.format(os.path.basename( r.working_dir))) c = r.git.log('{}/{}..HEAD'.format(remote, branch), '--oneline') if c: r.git.pull() d = os.path.basename(r.working_dir) if confirm(None, 'Share changes made to {}.\n\n{}'.format(d, c)) == YES: r.git.push(remote, branch) shared = True msg = 'Changes successfully shared' if shared else 'No changes to share' information(None, msg)
def initialize(self, repository, pull=True): """ setup git repos. repositories are guaranteed to exist. The automated run factory clones the required projects on demand. :return: """ self.debug('^^^^^^^^^^^^^ Initialize DVCPersister {} pull={}'.format(repository, pull)) self.dvc.initialize() repository = format_repository_identifier(repository) self.active_repository = repo = GitRepoManager() root = repository_path(repository) repo.open_repo(root) remote = 'origin' if repo.has_remote(remote) and pull: self.info('pulling changes from repo: {}'.format(repository)) self.active_repository.pull(remote=remote, use_progress=False)
def perform(self, event): from git import Repo from git.exc import InvalidGitRepositoryError from pychron.paths import paths remote = 'origin' branch = 'master' repos = [] for d in os.listdir(paths.repository_dataset_dir): if d.startswith('.') or d.startswith('~'): continue try: r = Repo(repository_path(d)) except InvalidGitRepositoryError: continue repos.append(r) n = len(repos) pd = myProgressDialog(max=n - 1, can_cancel=True, can_ok=False) pd.open() shared = False for r in repos: pd.change_message('Fetch {}'.format(os.path.basename(r.working_dir))) c = r.git.log('{}/{}..HEAD'.format(remote, branch), '--oneline') if c: r.git.pull() d = os.path.basename(r.working_dir) if confirm(None, 'Share changes made to {}.\n\n{}'.format(d, c)) == YES: r.git.push(remote, branch) shared = True msg = 'Changes successfully shared' if shared else 'No changes to share' information(None, msg)