def checkout( self, root=None, tag=None, date=None, az=None, ## Native path nonrecursive=None, zap=None, download_only=None, system_id=None, profile=None, build_type=None): import distributions import cvs import shell try: if self.checkin_dep_only: return except AttributeError: pass if self.type == "cvs": distributions.setup() tmpdir = distributions.tmpdir() tmpdir = os.path.join(tmpdir, "module") cvs.Checkout(tag or self.cvs_tag, self.cvs_path or self.name, root or self.cvs_root, tmpdir, date or self.cvs_date, nonrecursive, zap) if ((tag or self.cvs_tag) and (date or self.cvs_date) and not os.path.exists(tmpdir)): cvs.Checkout(self.cvs_tag, self.cvs_path or self.name, root or self.cvs_root, tmpdir, self.cvs_date, nonrecursive, zap) if not os.path.exists(tmpdir): raise cvs.cvs_error shell.mkdir(os.path.dirname(az or self.path())) os.rename(tmpdir, az or self.path()) distributions.cleanup() elif self.type == "distribution": df = distributions.DistFinder(self.name, root or self.cvs_root, tag or self.tag, date or self.cvs_date) fun = df.get_distribution if download_only: fun = df.download_distribution if not system_id: system_id = sysinfo.id return df.get_distribution( sysinfo.PLATFORM_HASH.get(system_id).distribution_id, profile, build_type)
def find_distribution_cvs(self, locations): log.trace('entry', [locations]) for dir in locations: log.debug('Trying to find %s' % dir) if not self.cvs_dir_check(dir): log.debug('Failed cvs_dir_check on "%s" - skipping.' % dir) continue # Once we have a dir, let's do something with it. message = "Looking for %s in %s (don't worry if this fails)" % ( self.cvs_path, dir) log.debug(message) outmsg.verbose(message) try: cvs.Checkout(self.cvs_tag, dir, self.cvs_root, os.path.join(tmpdir(), dir), self.cvs_timestamp) except cvs.cvs_error: ## Ignore cvs errors, report them as missing distributions instead log.warn('Failed to check out %s - skipping' % dir) return dir = os.path.join(os.curdir, tmpdir(), dir) try: for f in os.listdir(dir): if string.lower(f) not in ["cvs"]: return dir except OSError: pass log.trace('exit') return None
def find_distribution_rna(self, locations): for dir in locations: if not self.cvs_dir_check(dir): continue dir = dir + ".rna" outmsg.verbose("Looking for %s in %s (don't worry if this fails)" % (self.cvs_path, dir)) try: cvs.Checkout(self.cvs_tag, dir, self.cvs_root, os.path.dirname(os.path.join(tmpdir(), dir)), self.cvs_timestamp) except cvs.cvs_error: ## Ignore cvs errors, report them as missing distributions instead return dir = os.path.join(os.curdir, tmpdir(), dir) try: print "DOES %s exist????" % dir if os.path.isfile(dir): return dir except OSError: pass return None
def process_module(self, imodule): if imodule.type in ["cvs", "distribution"]: tmpdir="branch_tmp_"+str(distributions.my_get_thread_ident()) shell.rm(tmpdir) try: if imodule.type == "cvs": imodule.checkout( date = self.source_date, tag = self.source_tag, as = tmpdir) else: cvs.Checkout(self.source_tag or imodule.cvs_tag, "distribution", imodule.cvs_root, tmpdir, self.source_date or imodule.cvs_date) cmd='cvs tag %s %s "%s"' %( self.cvs_flags,self.dash_b, self.tag ) print "Running: %s (in %s + %s)" % (cmd, os.getcwd(), tmpdir) status, output = shell.run(cmd, dir = tmpdir) print output if status: print "Tagging module %s failed\n" % imodule.id except cvs.cvs_error: print "Tagging module %s failed\n" % imodule.id shell.rm(tmpdir)
def cvs_dir_check(self, loc): log.trace('entry', [loc]) global cvs_directory_cache parts = string.split(loc, "/") log.debug('Parts = %s' % parts) x = len(parts) - 2 while x > 0: part = string.join(parts[:x], "/") log.debug("CHECKING %s" % part) # cvs_dir_cache holds the result of prior dir_check results. # Thus, a key with a value of 0 means prior failure, which forces # the early exit rather than a re-check. if not self.cvs_dir_cache.get(part, 1): log.debug('Prior check reported failure on %s' % part) log.trace('exit', [0]) return 0 # Here, prior success of the cache check means prior success, so # we abort the loop and start the check. if self.cvs_dir_cache.get(part, 0): log.debug('Prior check reported success on %s' % part) break x = x - 1 y = (len(parts) + x - 1) / 2 if y <= x: log.debug('y <= x - early exit') log.trace('exit', [1]) return 1 part = string.join(parts[:y], "/") log.info("TESTING %s" % part) ## Nonrecursive checkout p = os.path.join(tmpdir(), "dir_cache_test") try: cvs.Checkout("", part, self.cvs_root, p, None, 1) except cvs.cvs_error: pass # FIFME: This relies on the cvs client implementation. On Linux, # checking out a dir with no files still puts a local dir and a CVS # subdir. On Windows, it doesn't touch the local filesystem, so # this returns True on Linux, and False on Windows. ret = os.path.exists(p) if ret: shell.rm(p) # This is where we store the results of the check into a cache to # cut down on CVS server load. self.cvs_dir_cache[part] = ret log.info("RESULT => %s" % repr(ret)) log.trace('exit', [ret]) return ret
def process_module(self, imodule): if imodule.type in ["cvs", "distribution"]: revisions=0 tmpdir="diff_tmp_"+str(distributions.my_get_thread_ident()) shell.rm(tmpdir) try: if imodule.type == "cvs": imodule.checkout( date = self.source_date, tag = self.source_tag, as = tmpdir) else: cvs.Checkout(self.source_tag or imodule.cvs_tag, "distribution", imodule.cvs_root, tmpdir, self.source_date or imodule.cvs_date) tag = "-b" try: tag=string.strip(open(os.path.join(tmpdir,"CVS","Tag"),"r").read()) ## Fixme: what if the sticky tag is a date?? if tag and tag[0] == "T": tag = "-r"+tag[1:] else: tag = "-b" except IOError: pass cmd='cvs log%s -N %s >cvs-log-temp-file' %( self.date_range, tag ) print "Running: %s (in %s + %s)" % (cmd, os.getcwd(), tmpdir) status, output = shell.run(cmd, dir = tmpdir) print output output=open(os.path.join(tmpdir,"cvs-log-temp-file"),"r").read() output=string.replace(output,"\r\n","\n") root="UNKNOWN" try: root=open(os.path.join(tmpdir,"CVS","Root"),"r").read() root=string.strip(root) except IOError: pass base_repository="UNKNOWN" try: base_repository=open(os.path.join(tmpdir,"CVS","Repository"),"r").read() base_repository=string.strip(base_repository) except IOError: pass viewcvs_base = cvs.GetViewCVSUrl(imodule.cvs_root, imodule.cvs_path or imodule.name) blocks=string.split(output, "=============================================================================") for file in blocks[:-2]: data=string.split(file,"----------------------------\nrevision ") wf=string.split(data[0],"Working file: ",1)[1] wf=string.split(wf,"\n",1)[0] local_name=os.path.join(imodule.name, wf) print " - %s, %d revisions" % (wf, len(data)-1) viewcvs_url=None if viewcvs_base: viewcvs_url=posixpath.join(viewcvs_base,wf) cvs_file=os.path.join(base_repository, wf) for revision in data[1:]: revdata=string.split(revision,";",3) author=string.split(revdata[1])[1] ## Ignore build farm checkins if author in [ "mserver", "drmbuild", "buildq", "codecbuild" ]: continue tmp=string.split(revdata[0]) rev=tmp[0] t="%s %s" % (tmp[2],tmp[3]) t=time.strptime(t,"%Y/%m/%d %H:%M:%S") t=time.mktime(t)-time.timezone author=string.split(revdata[1])[1] comment=string.split(revdata[3],"\n",1)[1] if string.split(comment,":",1)[0] == "branches": comment=string.split(comment,"\n",1)[1] ci=Checkin(author, t, comment) ci.add(File(local_name, rev, root, cvs_file, viewcvs_url)) self.checkins.append(ci) revisions = revisions + 1 if status: print "Diff module %s failed\n" % imodule.id except cvs.cvs_error: print "Diff module %s failed\n" % imodule.id shell.rm(tmpdir) print "%d revisions in %s" % (revisions, imodule.id)
def do_checkout(self, prefix, base, tag, cvspath, repository, local_path, timestamp): outmsg.send("Updating [%s] %s files..." % (prefix, base)) cvs.Checkout(tag, cvspath, repository, local_path, timestamp)