def create_local_branch(self, component, aspect, branch, use_master): err = 0 if not self.source_reporoot: return 1 bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) aspectdir = bi.get_branchdir(self.local_reporoot) if not os.path.isdir(os.path.dirname(aspectdir)): os.makedirs(os.path.dirname(aspectdir)) if not os.path.isdir(aspectdir): if use_master: print '\nBranching %s into local repository from %s ...' % (bi.branchpath, self.master_reporoot) else: print '\nBranching %s into local repository from %s ...' % (bi.branchpath, self.source_reporoot) mstbr = bi.get_branchdir(self.master_reporoot) srcbr = bi.get_branchdir(self.source_reporoot) lclbr = bi.get_branchdir(self.local_reporoot) if use_master: self.branch(mstbr, lclbr, quiet=True, quiet_stderr=True) else: self.branch(srcbr, lclbr, quiet=True, quiet_stderr=True) with open(lclbr+'/.bzr/branch/branch.conf', 'w') as bconf: bconf.write('parent_location = %s\n' %mstbr) bconf.write('push_location = %s\n' % mstbr) bconf.write('submit_location = %s\n' % mstbr) return err
def create_local_branch(self, component, aspect, branch, use_master): err = 0 if not self.source_reporoot: return 1 bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) aspectdir = bi.get_branchdir(self.local_reporoot) if not os.path.isdir(os.path.dirname(aspectdir)): os.makedirs(os.path.dirname(aspectdir)) if not os.path.isdir(aspectdir): if use_master: print '\nBranching %s into local repository from %s ...' % ( bi.branchpath, self.master_reporoot) else: print '\nBranching %s into local repository from %s ...' % ( bi.branchpath, self.source_reporoot) mstbr = bi.get_branchdir(self.master_reporoot) srcbr = bi.get_branchdir(self.source_reporoot) lclbr = bi.get_branchdir(self.local_reporoot) if use_master: self.branch(mstbr, lclbr, quiet=True, quiet_stderr=True) else: self.branch(srcbr, lclbr, quiet=True, quiet_stderr=True) with open(lclbr + '/.bzr/branch/branch.conf', 'w') as bconf: bconf.write('parent_location = %s\n' % mstbr) bconf.write('push_location = %s\n' % mstbr) bconf.write('submit_location = %s\n' % mstbr) return err
def tag(self, tag, component, aspect, branch, revisionid): bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) cmd, out = _prep_cmd(cmd_tag()) revision = None if revisionid: revision = bzrlib.option._parse_revision_str("revid:%s" % str(revisionid)) return cmd.run(revision=revision, tag_name=tag, directory=bi.get_branchdir(self.master_reporoot))
def update_local_branch(self, component, aspect, branch): ''' update (pull) the local branch from the parent ''' try: if self.source_reporoot: source_revid = self.get_source_revid(branch, component, aspect) local_revid = self.get_local_revid(branch, component, aspect) if source_revid != local_revid: ## print 'source_revid', source_revid, 'local_revid', local_revid ## from pprint import pprint ## pprint(traceback.format_stack()) bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) branchdir = bi.get_branchdir(self.local_reporoot) print '\nUpdating %s/%s/%s in local repository from %s ...' % (branch, component, aspect, self.source_reporoot) return pull(branchdir, bi.get_branchdir(self.source_reporoot)) except DivergedBranches, e: # Only throw this error in the case that the aspect is not report if aspect != 'report': raise e
def tags(self, component, aspect, branch, reporoot=None, lastRevision=True): if reporoot == None: reporoot = self.master_reporoot revision = None if lastRevision: revision = bzrlib.option._parse_revision_str("last:1") bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) cmd, out = _prep_cmd(cmd_tags()) cmd.run(revision=revision, directory=bi.get_branchdir(reporoot)) return out.getvalue().strip()
def get_file_contents(reporoot, component, aspect, branch, filepath, revision=None): """return the contents of a specific file directly from the local repository without a working copy. """ bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) directory = bi.get_branchdir(reporoot) output, err= cat(filepath, revision=revision, directory=directory) if err: print output if not err: return output
def update_local_branch(self, component, aspect, branch): ''' update (pull) the local branch from the parent ''' try: if self.source_reporoot: source_revid = self.get_source_revid(branch, component, aspect) local_revid = self.get_local_revid(branch, component, aspect) if source_revid != local_revid: ## print 'source_revid', source_revid, 'local_revid', local_revid ## from pprint import pprint ## pprint(traceback.format_stack()) bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) branchdir = bi.get_branchdir(self.local_reporoot) print '\nUpdating %s/%s/%s in local repository from %s ...' % ( branch, component, aspect, self.source_reporoot) return pull(branchdir, bi.get_branchdir(self.source_reporoot)) except DivergedBranches, e: # Only throw this error in the case that the aspect is not report if aspect != 'report': raise e
def get_file_contents(reporoot, component, aspect, branch, filepath, revision=None): """return the contents of a specific file directly from the local repository without a working copy. """ bi = BranchInfo(branchname=branch, componentname=component, aspectname=aspect) directory = bi.get_branchdir(reporoot) output, err = cat(filepath, revision=revision, directory=directory) if err: print output if not err: return output
def replicatereport(reporoot, server): tmp = reporoot.replace('\\','/').rstrip('/') reportroot = tmp[:tmp.rfind('/')] + '/reportroot' lock_file = '%s/lock' % reportroot with FileLock(lock_file, 5): timeFile = '%s/lastupdate.txt' % reportroot if server and os.path.exists(timeFile): finished = open(timeFile, 'r') finished = finished.read() date, t = finished.split() year, month, day = date.split('-') hour, min, sec = t.split(':') sec, micro = sec.split('.') finished = datetime.datetime(int(year), int(month), int(day), int(hour), int(min), int(sec), int(micro)) if datetime.datetime.now() - finished < datetime.timedelta(minutes = 1): return while True: try: p = subprocess.Popen('bzr fast-branches %s' % reporoot, stdout = subprocess.PIPE, shell=True) reports = [] output = p.stdout.read() for x in output.split('\n'): if x.strip(): parts = x.split() if len(parts) == 4: reports.append(parts) elif len(parts) == 3: parts.append('none') reports.append(parts) reports = [r for r in reports if r[2] == 'report'] print 'xxxxxxxxxxxx' for report in reports: bi = BranchInfo(branchname=report[0], componentname=report[1], aspectname=report[2]) branchdir = bi.get_branchdir(reporoot) reportdir = bi.get_branchdir(reportroot) if not os.path.exists(reportdir): print 'Checking out %s.' % reportdir os.makedirs(reportdir) os.system('bzr co --lightweight %s %s' % (branchdir, reportdir)) else: print 'Updating %s.' % reportdir os.system('bzr up -q %s' % reportdir) for branch in os.listdir(reportroot): rdir = os.path.join(reportroot, branch).replace('\\','/') bdir = os.path.join(reporoot, branch).replace('\\','/') if not os.path.exists(bdir): print 'Removing %s' % rdir shutil.rmtree(rdir,True,handleRmtree) else: for comp in os.listdir(rdir): crdir = os.path.join(rdir, comp).replace('\\','/') cbdir = os.path.join(bdir, comp).replace('\\','/') if not os.path.exists(cbdir): print 'Removing %s' % crdir shutil.rmtree(crdir,True,handleRmtree) except KeyboardInterrupt: sys.exit(0) except: print(sys.exc_info()[1]) time.sleep(10) if server: finished = open(timeFile, 'w') finished.write(str(datetime.datetime.now())) finished.close() break time.sleep(60)
def replicatereport(reporoot, server): tmp = reporoot.replace('\\', '/').rstrip('/') reportroot = tmp[:tmp.rfind('/')] + '/reportroot' lock_file = '%s/lock' % reportroot with FileLock(lock_file, 5): timeFile = '%s/lastupdate.txt' % reportroot if server and os.path.exists(timeFile): finished = open(timeFile, 'r') finished = finished.read() date, t = finished.split() year, month, day = date.split('-') hour, min, sec = t.split(':') sec, micro = sec.split('.') finished = datetime.datetime(int(year), int(month), int(day), int(hour), int(min), int(sec), int(micro)) if datetime.datetime.now() - finished < datetime.timedelta( minutes=1): return while True: try: p = subprocess.Popen('bzr fast-branches %s' % reporoot, stdout=subprocess.PIPE, shell=True) reports = [] output = p.stdout.read() for x in output.split('\n'): if x.strip(): parts = x.split() if len(parts) == 4: reports.append(parts) elif len(parts) == 3: parts.append('none') reports.append(parts) reports = [r for r in reports if r[2] == 'report'] print 'xxxxxxxxxxxx' for report in reports: bi = BranchInfo(branchname=report[0], componentname=report[1], aspectname=report[2]) branchdir = bi.get_branchdir(reporoot) reportdir = bi.get_branchdir(reportroot) if not os.path.exists(reportdir): print 'Checking out %s.' % reportdir os.makedirs(reportdir) os.system('bzr co --lightweight %s %s' % (branchdir, reportdir)) else: print 'Updating %s.' % reportdir os.system('bzr up -q %s' % reportdir) for branch in os.listdir(reportroot): rdir = os.path.join(reportroot, branch).replace('\\', '/') bdir = os.path.join(reporoot, branch).replace('\\', '/') if not os.path.exists(bdir): print 'Removing %s' % rdir shutil.rmtree(rdir, True, handleRmtree) else: for comp in os.listdir(rdir): crdir = os.path.join(rdir, comp).replace('\\', '/') cbdir = os.path.join(bdir, comp).replace('\\', '/') if not os.path.exists(cbdir): print 'Removing %s' % crdir shutil.rmtree(crdir, True, handleRmtree) except KeyboardInterrupt: sys.exit(0) except: print(sys.exc_info()[1]) time.sleep(10) if server: finished = open(timeFile, 'w') finished.write(str(datetime.datetime.now())) finished.close() break time.sleep(60)