def installWorkArea(installDir, cmtWorkAreaPkg): msg = logging.getLogger("WorkAreaMgr") workAreaDir = os.path.join(installDir, cmtWorkAreaPkg.name) cmtDir = os.path.join(workAreaDir, CmtStrings.CMTDIR) if os.path.exists(installDir): if os.access(installDir, os.W_OK): if os.path.exists(workAreaDir): if not os.path.exists(cmtDir): os.mkdir(cmtDir) pass pass else: os.makedirs(os.path.join(workAreaDir, cmtDir)) pass else: msg.error("Can't write under [%s] !!" % installDir) raise OSError pass else: try: os.makedirs(installDir) installWorkArea(installDir, cmtWorkAreaPkg) except OSError, what: msg.error( "Install dir for WorkArea does NOT exist and can't create it !!" ) raise OSError, what pass
def scan( scanDir = os.curdir, suppressList = ["WorkArea"] ): """Search for CMT packages in the given directory and walk down the directory tree. Return the list of found CMT packages. """ msg = logging.getLogger( "WorkAreaMgr" ) msg.info( "Scanning [%s]" % scanDir ) # return value cmtPackages = [] # retrieve all cmt-ised directories in the scan directory scanDir = os.path.abspath( scanDir ) cmtDirs = [] try: cmtDirs = listCmtDirs(scanDir) except KeyboardInterrupt: msg.warning( "Scanning has been STOPPED ! (by you)" ) pass for cmtDir in cmtDirs: cmtPkg = createCmtPkg(cmtDir) if cmtPkg != None and \ cmtPkg.name not in suppressList: cmtPackages.append( cmtPkg ) pass return cmtPackages
def createWorkArea(workAreas=[], installDir=None, runTimePkg='offline', suppressList=None): msg = logging.getLogger("WorkAreaMgr") if suppressList == None: suppressList = ["WorkArea"] else: suppressList.append("WorkArea") pass atlasRunTime = runTimePkg[0].upper() + runTimePkg[1:] defaultWorkArea = os.environ[CmtStrings.CMTPATH].split(os.pathsep)[0] if len(workAreas) <= 0: workAreas = [defaultWorkArea] if installDir == None: installDir = defaultWorkArea pass msg.info(80 * "#") msg.info("Creating a WorkArea CMT package under: [%s] " % installDir) try: installWorkArea(installDir, CmtPkg("WorkArea", WORKAREA_VERSION, "")) except Exception, err: msg.error("Could NOT create WorkArea package !!") msg.error("%r", err) msg.info(80 * "#") sys.exit(3)
def createWorkArea(workAreas = None, installDir = None, runTimePkg = None, suppressList = None): msg = logging.getLogger("WorkAreaMgr") if workAreas is None: workAreas = [] if suppressList is None: suppressList = [ "WorkArea" ] else: suppressList.append( "WorkArea" ) pass if runTimePkg is None: runTimePkg = os.getenv('AtlasProject', 'AtlasOffline') pass atlasRunTime = _translate_runtimepkg_name(runTimePkg) defaultWorkArea = _get_currentpath() if len(workAreas) <= 0: workAreas = [ defaultWorkArea ] if installDir == None: installDir = defaultWorkArea pass msg.info( 80*"#" ) msg.info( "Creating a WorkArea CMT package under: [%s] " % installDir ) try: installWorkArea( installDir, CmtPkg( "WorkArea", WORKAREA_VERSION, "" ) ) except Exception,err: msg.error( "Could NOT create WorkArea package !!" ) msg.error( "%r", err) msg.info( 80*"#" ) sys.exit(3)
def installWorkArea( installDir, cmtWorkAreaPkg ): msg = logging.getLogger("WorkAreaMgr") workAreaDir = os.path.join( installDir, cmtWorkAreaPkg.name ) cmtDir = os.path.join( workAreaDir, CmtStrings.CMTDIR ) if os.path.exists(installDir): if os.access(installDir, os.W_OK): if os.path.exists( workAreaDir ): if not os.path.exists( cmtDir ): os.mkdir( cmtDir ) pass pass else: os.makedirs( os.path.join( workAreaDir, cmtDir ) ) pass else: msg.error( "Can't write under [%s] !!" % installDir ) raise OSError pass else: try: os.makedirs(installDir) installWorkArea( installDir, cmtWorkAreaPkg ) except OSError, what: msg.error( "Install dir for WorkArea does NOT exist and can't create it !!" ) raise OSError, what pass
def get_latest_pkg_tag(fullPkgName): """Return the most recent SVN tag of the package. Return: Tag or None on error """ msg = logging.getLogger( "WorkAreaMgr" ) svnroot = os.environ.get("SVNROOT") if svnroot==None: msg.error("SVNROOT is not set.") return None _cmd = "svn ls %s" % os.path.join(svnroot, fullPkgName, "tags") if fullPkgName.startswith('Gaudi'): _cmd = "svn ls %s" % os.path.join(svnroot, 'tags', fullPkgName) msg.debug('running [%s]...', _cmd) p = subprocess.Popen(_cmd, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE) tags = p.communicate()[0].splitlines() if len(tags)==0 or p.returncode!=0: return None pkg_name = os.path.basename(fullPkgName) # enforce atlas convention of tags (pkgname-xx-yy-zz-aa) tags = [t for t in tags if t.startswith(pkg_name)] latest_tag = rstrip(tags[-1],"/\n ") return latest_tag
def scan(scanDir=os.curdir, suppressList=["WorkArea"]): """Search for CMT packages in the given directory and walk down the directory tree. Return the list of found CMT packages. """ msg = logging.getLogger("WorkAreaMgr") msg.info("Scanning [%s]" % scanDir) # return value cmtPackages = [] # retrieve all cmt-ised directories in the scan directory scanDir = os.path.abspath(scanDir) cmtDirs = [] try: cmtDirs = listCmtDirs(scanDir) except KeyboardInterrupt: msg.warning("Scanning has been STOPPED ! (by you)") pass for cmtDir in cmtDirs: cmtPkg = createCmtPkg(cmtDir) if cmtPkg != None and \ cmtPkg.name not in suppressList: cmtPackages.append(cmtPkg) pass return cmtPackages
def listCMakeDirs( path ): """Return the list of paths pointing at 'CMake' directories, accessible from the `path` path. """ msg = logging.getLogger( "WorkAreaMgr" ) cmakeDirs = [] # fill list of CMake directories for root, dirs, files in os.walk(path): if _is_in_ignore_dir_list(root): continue if 'version.cmake' in files: msg.debug("\t==> found %s" % root) cmakeDirs.append(root) return cmakeDirs
def listCmtDirs( path ): """Return the list of paths pointing at 'cmt' directories, accessible from the `path` path. """ msg = logging.getLogger( "WorkAreaMgr" ) cmtDirs = [] # fill list of CMT directories for root, dirs, files in os.walk(path): for d in dirs[:]: if _is_in_ignore_dir_list(d): dirs.remove(d) for d in dirs: if d == CmtStrings.CMTDIR: full_name = os.path.join(root, d) msg.debug("\t==> found %s" % full_name) cmtDirs.append(full_name) return cmtDirs
def listCmtDirs( path ): """Return the list of paths pointing at 'cmt' directories, accessible from the `path` path. """ msg = logging.getLogger( "WorkAreaMgr" ) cmtDirs = [] # fill list of CMT directories import os import os.path as osp for root, dirs, files in os.walk(path): for d in dirs[:]: if _is_in_ignore_dir_list(d): dirs.remove(d) for d in dirs: if d == CmtStrings.CMTDIR: full_name = osp.join(root, d) msg.debug("\t==> found %s" % full_name) cmtDirs.append(full_name) return cmtDirs
def createUseList(workAreas, suppressList=["WorkArea"]): msg = logging.getLogger("WorkAreaMgr") cmtPackages = [] uses = [] for workArea in workAreas: cmtPackages.extend(scan(workArea, suppressList)) pass # Handle duplicate CMT packages: pkgs = {} duplicates = {} for cmtPkg in cmtPackages: if not pkgs.has_key(cmtPkg.name): pkgs[cmtPkg.name] = cmtPkg pass else: # we found a duplicate... # check that the new one has a more recent version if pkgs[cmtPkg.name].version < cmtPkg.version: pkgs[cmtPkg.name] = cmtPkg pass duplicates[cmtPkg.name] = pkgs[cmtPkg.name] pass pass if len(duplicates) > 0: msg.warning("Found duplicate(s): (listing the ones we kept)") for k in duplicates.keys(): msg.warning("--") msg.warning(" Package: %s" % duplicates[k].name) msg.warning(" Version: %s" % duplicates[k].version) msg.warning(" Path: %s" % duplicates[k].path) pass pass del duplicates cmtPackages = [pkg for pkg in pkgs.values()] del pkgs msg.info("Found %i packages in WorkArea" % len(cmtPackages)) if len(suppressList) >= 1: # -1 because WorkArea is removed by default msg.info( "=> %i package(s) in suppression list" % \ int(len(suppressList) - 1) ) for cmtPkg in cmtPackages: # swallow the WorkArea path so we have a "cmt path" to put # in the req file for workArea in workAreas: cmtPkg.path = cmtPkg.path.replace(workArea + os.sep, '') cmtPkg.path = cmtPkg.path.replace(workArea, '') pass if cmtPkg.path.endswith(os.sep): cmtPkg.path = os.path.split(cmtPkg.path) pass use = "use %s \t%s \t%s" % ( cmtPkg.name, #cmtPkg.version, "*", cmtPkg.path) msg.debug("\t%s" % use) uses.append(use) pass return uses
def createCmtPkg( cmtDir ): """ the cmtDir is assumed to be of the form Xyz/cmt One has also to handle the case with or without version-directory """ msg = logging.getLogger("WorkAreaMgr") pkgName = None # the CMTREQFILE should provide the name of package # so we extract it from this file try: reqFile = open( os.path.join( cmtDir, CmtStrings.CMTREQFILE ), 'r' ) for line in reqFile.readlines(): line = line.strip() if len(line) > 0 and \ line[0] != "#" and \ line.count("package ") > 0: pkgName = line.splitlines()[0]\ .split("package ")[1]\ .replace("\r","")\ .split("#")[0]\ .strip() break pass reqFile.close() del reqFile except IOError: ## No CMTREQFILE in this directory ## ==> not a CMT package then ? ## check if there is any CMT project file instead if not os.path.exists( os.path.join(cmtDir, CmtStrings.CMTPROJFILE) ): msg.warning( "[%s] does NOT contain any '%s' nor '%s' file !!" % \ ( cmtDir, CmtStrings.CMTREQFILE, CmtStrings.CMTPROJFILE ) ) return None if pkgName == None: msg.warning( "No 'package Foo' stmt in %s of %s" % \ ( CmtStrings.CMTREQFILE, cmtDir ) ) return None msg.debug( "\t\t==> Analysing [%s]" % cmtDir ) # first we try the no-version-directory case as it is the ATLAS # default now. if CmtStrings.CMTVERSIONFILE in os.listdir(cmtDir): version = open( os.path.join( cmtDir, CmtStrings.CMTVERSIONFILE ), 'r' )\ .readline() version = version.splitlines()[0].strip() pkgDir = os.path.split(cmtDir)[0].strip() pkgPath = os.path.split(pkgDir)[0].strip() pass # Now we *MAY* be in the case where: # /somePath/MyPkg/MyPkg-00-00-00/cmt # or # /somePath/MyPkg/v1r2p3/cmt # however this is not supported anymore: warn and fallback to previous # case anyway (as user might have screwed up) else: msg.warning("No [%s] file in [%s] directory", CmtStrings.CMTVERSIONFILE, cmtDir) msg.warning("Can't reliably infer package version/dir!") version = '*' pkgDir = os.path.split(cmtDir)[0].strip() pkgPath = os.path.split(pkgDir)[0].strip() msg.warning("Will use:") msg.warning( "\t\t\t- name = %s" % pkgName ) msg.warning( "\t\t\t- version = %s" % version ) msg.warning( "\t\t\t- path = %s" % pkgPath ) pass msg.debug( "\t\t\t- name = %s" % pkgName ) msg.debug( "\t\t\t- version = %s" % version ) msg.debug( "\t\t\t- path = %s" % pkgPath ) if pkgName.count(os.sep) > 0 : msg.warning( "About to create a funny CMT package !" ) msg.warning( "'PkgName' contains '%s'. Please fix it!" % os.sep ) msg.warning( "\t- name = %s" % pkgName ) msg.warning( "\t- version = %s" % version ) msg.warning( "\t- path = %s" % pkgPath ) # Ok, so, I fix it - but user is warned... pkgName = os.path.basename(pkgName) pass return CmtPkg( pkgName, version, pkgPath )
def createUseList(workAreas, suppressList = ["WorkArea"]): msg = logging.getLogger( "WorkAreaMgr" ) cmtPackages = [] uses = [] for workArea in workAreas: cmtPackages.extend( scan( workArea, suppressList ) ) pass # Handle duplicate CMT packages: pkgs = {} duplicates = {} for cmtPkg in cmtPackages: if not pkgs.has_key(cmtPkg.name): pkgs[cmtPkg.name] = cmtPkg pass else: # we found a duplicate... # check that the new one has a more recent version if pkgs[cmtPkg.name].version < cmtPkg.version: pkgs[cmtPkg.name] = cmtPkg pass duplicates[cmtPkg.name] = pkgs[cmtPkg.name] pass pass if len(duplicates) > 0: msg.warning( "Found duplicate(s): (listing the ones we kept)" ) for k in duplicates.keys(): msg.warning( "--" ) msg.warning( " Package: %s" % duplicates[k].name ) msg.warning( " Version: %s" % duplicates[k].version ) msg.warning( " Path: %s" % duplicates[k].path ) pass pass del duplicates cmtPackages = [ pkg for pkg in pkgs.values() ] del pkgs msg.info( "Found %i packages in WorkArea" % len(cmtPackages) ) if len(suppressList) >= 1: # -1 because WorkArea is removed by default msg.info( "=> %i package(s) in suppression list" % \ int(len(suppressList) - 1) ) for cmtPkg in cmtPackages: # swallow the WorkArea path so we have a "cmt path" to put # in the req file for workArea in workAreas: cmtPkg.path = cmtPkg.path.replace( workArea+os.sep, '' ) cmtPkg.path = cmtPkg.path.replace( workArea, '' ) pass if cmtPkg.path.endswith( os.sep ): cmtPkg.path = os.path.split(cmtPkg.path) pass use = "use %s \t%s \t%s -no_auto_imports" % \ ( cmtPkg.name, "*", #cmtPkg.version, cmtPkg.path ) msg.debug( "\t%s" % use ) uses.append( use ) pass return uses
# @author: Sebastien Binet # @date: February 2007 from __future__ import with_statement __version__ = "$Revision$" import os import os.path as osp import glob import sys ### basic logging and messages ----------------------------------------------- from PyCmt.Logging import logging msg = logging.getLogger("AthBoot") ########################## # recognized user options ########################## import getopt _useropts = 'i:o:hl:v' _userlongopts = [ 'input-dir=', 'output-dir=', 'help', 'loglevel=', 'version' ] def _usage(): print """Accepted command line options (CLI): -i, --input-dir <dir> ... directory where the original WorkArea is sitting.
__doc__ = "A simple build system" __author__ = "Sebastien Binet <*****@*****.**>" __version__ = "$Revision$" ### imports ------------------------------------------------------------------- import sys import os import os.path as osp import imp import inspect import re from PyCmt.Logging import logging ### globals ------------------------------------------------------------------- msg = logging.getLogger('PkgBuilder') msg.setLevel(logging.INFO) #msg.setLevel(logging.VERBOSE) # FIXME: should be more easily configurable _DO_RELOCATE = True #_DO_RELOCATE = False ### utils --------------------------------------------------------------------- def relpath(path, start=osp.curdir): """Return a relative version of a path""" if not path: raise ValueError("no path specified")
def createCmtPkg(cmtDir): """ the cmtDir is assumed to be of the form Xyz/cmt One has also to handle the case with or without version-directory """ msg = logging.getLogger("WorkAreaMgr") pkgName = None # the CMTREQFILE should provide the name of package # so we extract it from this file try: reqFile = open(os.path.join(cmtDir, CmtStrings.CMTREQFILE), 'r') for line in reqFile.readlines(): line = line.strip() if len(line) > 0 and \ line[0] != "#" and \ line.count("package ") > 0: pkgName = line.splitlines()[0]\ .split("package ")[1]\ .replace("\r","")\ .split("#")[0]\ .strip() break pass reqFile.close() del reqFile except IOError: ## No CMTREQFILE in this directory ## ==> not a CMT package then ? ## check if there is any CMT project file instead if not os.path.exists(os.path.join(cmtDir, CmtStrings.CMTPROJFILE)): msg.warning( "[%s] does NOT contain any '%s' nor '%s' file !!" % \ ( cmtDir, CmtStrings.CMTREQFILE, CmtStrings.CMTPROJFILE ) ) return None if pkgName == None: msg.warning( "No 'package Foo' stmt in %s of %s" % \ ( CmtStrings.CMTREQFILE, cmtDir ) ) return None msg.debug("\t\t==> Analysing [%s]" % cmtDir) # first we try the no-version-directory case as it is the ATLAS # default now. if CmtStrings.CMTVERSIONFILE in os.listdir(cmtDir): version = open( os.path.join( cmtDir, CmtStrings.CMTVERSIONFILE ), 'r' )\ .readline() version = version.splitlines()[0].strip() pkgDir = os.path.split(cmtDir)[0].strip() pkgPath = os.path.split(pkgDir)[0].strip() pass # Now we *MAY* be in the case where: # /somePath/MyPkg/MyPkg-00-00-00/cmt # or # /somePath/MyPkg/v1r2p3/cmt # however this is not supported anymore: warn and fallback to previous # case anyway (as user might have screwed up) else: msg.warning("No [%s] file in [%s] directory", CmtStrings.CMTVERSIONFILE, cmtDir) msg.warning("Can't reliably infer package version/dir!") version = '*' tmpDir = os.path.split(cmtDir)[0].strip() pkgDir = os.path.split(tmpDir)[0].strip() pkgPath = os.path.split(pkgDir)[0].strip() msg.warning("Will use:") msg.warning("\t\t\t- name = %s" % pkgName) msg.warning("\t\t\t- version = %s" % version) msg.warning("\t\t\t- path = %s" % pkgPath) pass msg.debug("\t\t\t- name = %s" % pkgName) msg.debug("\t\t\t- version = %s" % version) msg.debug("\t\t\t- path = %s" % pkgPath) if pkgName.count(os.sep) > 0: msg.warning("About to create a funny CMT package !") msg.warning("'PkgName' contains '%s'. Please fix it!" % os.sep) msg.warning("\t- name = %s" % pkgName) msg.warning("\t- version = %s" % version) msg.warning("\t- path = %s" % pkgPath) # Ok, so, I fix it - but user is warned... pkgName = os.path.basename(pkgName) pass return CmtPkg(pkgName, version, pkgPath)
__doc__ = "A simple build system" __author__ = "Sebastien Binet <*****@*****.**>" __version__= "$Revision$" ### imports ------------------------------------------------------------------- import sys import os import os.path as osp import imp import inspect from PyCmt.Logging import logging ### globals ------------------------------------------------------------------- msg = logging.getLogger('PkgBuilder') msg.setLevel(logging.INFO) #msg.setLevel(logging.VERBOSE) # FIXME: should be more easily configurable _DO_RELOCATE = True #_DO_RELOCATE = False ### utils --------------------------------------------------------------------- def relpath(path, start=osp.curdir): """Return a relative version of a path""" if not path: raise ValueError("no path specified") start_list = osp.abspath(start).split(osp.sep)