def env(self, rel_dir=None): '''Return dictionary of env for the given project and optional package. It conists of the environment after sourcing the top level projects/setup.sh followed by the setup.sh in the given package package if rel_dir is given. rel_dir can be absolute path or relative from the projects/ directory. It can include or omit the final /cmt sub directory.''' from command import source import fs environ = self.cfg_environ() #print 'projects.env(): Source %s/setup.sh'%fs.projects() environ = source('./setup.sh', env=environ, dir=fs.projects()) if not rel_dir: rel_dir = self.rel_pkg() #print 'Using rel_dir =', rel_dir if not rel_dir: #print 'No rel_dir given' return environ cmtdir = os.path.join(self.proj_dir(), rel_dir) if cmtdir.rfind('/cmt') < 0: cmtdir = os.path.join(cmtdir,'cmt') import cmt if not os.path.exists(cmtdir+'/setup.sh'): cmt.cmt('config', environ=environ, dir=cmtdir) pass #print 'projects.env(): Source %s/setup.sh'%cmtdir environ = source('./setup.sh', env=environ, dir=cmtdir) return environ
def download(self): '''Download missing or update pre-existing project files. As a side effect the program will be in the projects directory that contains the downloaded project''' log.info(self.name +' download') import fs, ConfigParser projdir = fs.projects() fs.goto(projdir, True) from get import get try: tag = self.tag() except ConfigParser.NoOptionError: tag = None #print 'url="%s" name="%s" tag="%s"'%(self.url(), self.name, tag) get(self.url(), self.name, True, tag=tag) tarfile = os.path.basename(self.url()) if '.tgz' in tarfile or '.tar' in tarfile: untar(tarfile) dot = tarfile.find('.') dirname = tarfile[:dot] import shutil shutil.move(dirname, self.name) pass fs.goback return
def _git_clone(self,url,submodules=False): import fs,git target = fs.projects()+'/gaudi' if os.path.exists(target): log.info('Directory already exists, skipping clone to: %s'%target) return fs.goto(fs.projects(),True) git.clone(url,'gaudi') fs.goback() if submodules: fs.goto(os.path.join(fs.projects(),'gaudi'),True) git.submodule('init') git.submodule('update') fs.goback() return
def init_project(self,deps=None): 'Initialize the LCGCMT project' import fs,os from ConfigParser import NoOptionError setupdir = fs.setup() fs.assure(setupdir) base = fs.setup() tags = ['garpi'] try: extra_tags = eval(self.get_config('extra_tags')) tags += extra_tags except NoOptionError: pass tags = ','.join(tags) #print 'setting extra tags =',tags values = (os.path.dirname(fs.projects()), os.path.basename(fs.projects()),tags) # Bourne Shell sh = open(os.path.join(base,'10_lcgcmt.sh'),'w') sh.write('''#!/bin/sh SITEROOT=%s export SITEROOT CMTPROJECTPATH=$SITEROOT/%s export CMTPROJECTPATH CMTEXTRATAGS=%s export CMTEXTRATAGS '''%values) sh.close() # C(rappy) Shell csh = open(os.path.join(base,'10_lcgcmt.csh'),'w') csh.write('''#!/bin/csh setenv SITEROOT %s setenv CMTPROJECTPATH %s setenv CMTEXTRATAGS %s '''%values) csh.close() return
def _git_checkout(self,tag,pkg=""): import fs,git fs.goto(os.path.join(fs.projects(),'gaudi',pkg)) lbranches,rbranches = git.branches() if tag in lbranches: git.checkout(tag) else: git.checkout('origin/'+tag,tag) fs.goback() return
def _download_cern_svn(self): import fs from svn import svncmd scheme = self.url().split('+') if self.tag() == 'trunk': url = '%s/trunk'%scheme[1] else: url = '%s/tags/GAUDI/%s'%(scheme[1],self.tag()) # installing from a branch not supported/recommended. svncmd('co %s %s/gaudi'%(url,fs.projects())) return
def cmd_inrel(self, cmdstr): 'Run a command in the release package. No-op if none defined.' relpkg = self.rel_pkg() if not relpkg: err = 'Project %s has no release package defined'%self.name log.warning(err) raise CommandFailure, err import fs relpkgcmt = os.path.join(fs.projects(), self.name, relpkg, 'cmt') if not os.path.exists(relpkgcmt): err = 'Project %s has release package defined, but no dir: %s'%(self.name, relpkgcmt) log.warning(err) raise CommandFailure, err import command command.cmd(cmdstr, env=self.env(), dir=relpkgcmt)
def __init__(self, tarfilename, project_objects): from garpi.config import cli import os, fs self.tarfilename = tarfilename self.project_objects = project_objects if self.tarfilename[0] != '/': self.tarfilename = os.path.join(os.getcwd(), self.tarfilename) dstdir = cli.opts.unpack_directory if dstdir != '/': dstdir = os.path.join(os.getcwd(), cli.opts.unpack_directory) if not os.path.exists(dstdir): os.makedirs(dstdir) self.dstdir = dstdir self.srcdir = os.path.dirname(fs.projects()) self.cli = cli return
def _external_files(self): import os, fs, cmt project_area = fs.projects() basedir = os.path.dirname(project_area) snip = len(basedir)+1 #print snip, basedir, project_area ret = [] intdir = os.path.join(project_area, 'lcgcmt/LCG_Interfaces') for pkg in self.externals: intpkg = os.path.join(intdir, pkg, 'cmt') environ = self.lcgcmt.env(intpkg) home = cmt.macro(pkg + '_home', environ=environ, dir=intpkg) #print intpkg, home home = home[snip:] # make relative to base ret.append(home) continue return ret
def do_emit_setenv_config(self, filename=None): 'Emit configuration suitable for use by garpi-setenv' import fs, os if not filename: filename='/dev/stdout' fp = open(filename,'w') fp.write('[defaults]\n') fp.write('base_release = %s\n'%fs.projects()) projects = list(self.projects) projects.reverse() for p in projects: rp = p.rel_pkg() if rp: fp.write('release_package = %s\n'%os.path.join(p.name,rp)) break continue fp.close() return
def _project_files(self): import os, command, fs cmtconfig = os.getenv('CMTCONFIG') project_area = fs.projects() basedir = os.path.dirname(project_area) snip = len(basedir)+1 grist = [] for proj in self.project_objects: projdir = os.path.join(project_area, proj.name) out = command.cmd("find . -type f -print", dir=projdir, output=True) for path in out.split('\n'): if not self._keeper(path): continue if path[:2] == './': path = path[2:] path = os.path.join(projdir, path) path = path[snip:] # Handle InstallArea special if '/InstallArea/' in path: if path[-7:] != '.cmtref': grist.append(path) continue # If not companion symlink, then give up and just add the file linkname = path[:-7] if not os.path.islink(path): grist.append(path) continue # Resolve symlink and save both pathname = readlink(linkname) grist.append((linkname, pathname)) continue if cmtconfig in path: continue # ignore some common cruft if '/cmt/' in path: if '.root' == path[-5:]: continue if '.log' == path[-4:]: continue if '.out' == path[-4:]: continue filename = path.split('/')[-1] if 'setup' in filename: continue if 'cleanup' in filename: continue if 'Makefile' == filename: continue grist.append(path) continue continue # some extra by hand projdir = fs.projects()[snip:] grist.append(os.path.join(projdir, 'setup')) grist.append(os.path.join(projdir, 'setup.sh')) grist.append(os.path.join(projdir, 'setup.csh')) return grist
def proj_dir(self): import fs return os.path.join(fs.projects(), self.name)
def gitcmd(cmdstr): from command import source env = source(fs.projects() + "/setup.sh") return cmd("%s %s" % (gitexe(), cmdstr), env=env, output=True)