Commit 80234f33 authored by Walter Lampl's avatar Walter Lampl Committed by Graeme Stewart
Browse files

gen_klass of AlgTool: Remove obsolete usage of StoreGateSvc (done by...

gen_klass of AlgTool: Remove obsolete usage of StoreGateSvc (done by AthAlgTool base now) (PyUtils-00-13-22)
parent 161b7f54
#!/usr/bin/env python
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
#
# @file: abootstrap-wkarea.py
# @purpose: install all needed $(CMTCONFIG) directories into a temporary area
# so to not eat our precious AFS disk space.
# also creates a WorkArea CMT package to ease administration
# @author: Sebastien Binet
# @date: February 2007
from __future__ import with_statement
__version__ = "$Revision: 323486 $"
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.
-o, --output-dir <dir> ... directory where to install the bin dirs
-h, --help ... print this help message
-l, --loglevel <level> ... logging level (DEBUG, INFO, WARNING, ERROR, FATAL)
-v, --version ... print version number
"""
return
## Helper class to recursively find files
import fnmatch
class _GlobDirectoryWalker:
"""a forward iterator that traverses a directory tree"""
def __init__(self, directory, pattern="*"):
self.stack = [directory]
if type(pattern) != type([]):
pattern = [ pattern ]
self.pattern = pattern
self.files = []
self.index = 0
return
def __getitem__(self, index):
while 1:
try:
file = self.files[self.index]
self.index = self.index + 1
except IndexError:
# pop next directory from stack
self.directory = self.stack.pop()
self.files = os.listdir(self.directory)
self.index = 0
else:
# got a filename
fullname = osp.join(self.directory, file)
if osp.isdir(fullname) and not osp.islink(fullname):
self.stack.append(fullname)
for pattern in self.pattern:
if fnmatch.fnmatch(file, pattern):
msg.debug(" --> %s",fullname)
return fullname
pass
return
pass # class _GlobDirectoryWalker
## Helper function to find all the bin dirs to be installed
def register_bin_dirs(top_dir = os.getcwd(),
pattern = os.environ['CMTCONFIG']):
"""helper function to find all 'bin' dirs to be installed in the temp space
"""
top_dir = osp.abspath(osp.expanduser(osp.expandvars(top_dir)))
msg.info("registering 'bin dirs' [%s]..." % str(pattern))
msg.info("parsing [%s]..." % top_dir)
if not osp.exists(top_dir):
return []
bin_dirs = [ d for d in _GlobDirectoryWalker(top_dir, pattern)
if osp.isdir(d) and not osp.islink(d)
and d.count("InstallArea") <= 0 ]
msg.info(" ==> found [%i] 'bin dirs' to process", len(bin_dirs))
return bin_dirs
## Main entry point
import shutil, glob
def symlink_bin_dirs(input_dir, output_dir, bin_dirs):
input_dir = osp.abspath(input_dir)
output_dir= osp.abspath(output_dir)
msg.info("."*50)
msg.info("symlinking ...")
if not osp.exists(output_dir):
msg.warning("[%s] does NOT exists : creating it...", output_dir)
os.mkdir(output_dir)
pass
for bin in bin_dirs:
bin = osp.abspath(bin)
root = osp.commonprefix([input_dir, bin]) + os.sep
out_bin = output_dir + os.sep + bin.split(root)[1]
msg.info(" -- %s", bin.split(root)[1])
## remove the linked dir if it exists
## (this assumes the registering of bin_dirs does not register already
## symlinked bin_dirs !! Worse case scenario is to rebuild...)
if osp.exists(out_bin):
msg.debug("... removing [%s] ...", out_bin)
shutil.rmtree(out_bin)
pass
## create all the parent path if it does not exist yet
if not osp.exists(osp.dirname(out_bin)):
os.makedirs(osp.dirname(out_bin))
pass
# symlink the output bin...
shutil.move(bin, out_bin)
os.symlink(out_bin, bin)
# symlink the other directories so relative paths are also working
# and g++ -o bla ../src/Bla.cxx will work
pkg_dir = osp.dirname(bin)
other_dirs = [d for d in glob.glob(pkg_dir + os.sep + "*")
if d != bin and osp.isdir(d)]
#msg.debug(" symlinking [%r]", other_dirs)
for d in other_dirs:
symlink_dest = osp.join(output_dir, d.split(root)[1])
if osp.exists(symlink_dest):
os.remove(symlink_dest)
os.symlink(d, symlink_dest)
msg.info("symlinking [DONE]")
msg.info("."*50)
return
class Options(object):
"""a dummy class to collect options"""
pass
def _processOptions(useropts, userlongopts):
# defaults
input_dir = None
output_dir = None
lvl = logging.INFO
opts = Options()
try:
optlist,args = getopt.getopt(sys.argv[1:],
useropts,
userlongopts)
except getopt.error:
msg.error(str(sys.exc_value))
_usage()
sys.exit(2)
pass
for opt, arg in optlist:
if opt in ('-h', '--help'):
_usage()
sys.exit()
elif opt in ('-v', '--version'):
print "version:",__version__
print "By Sebastien Binet"
sys.exit()
elif opt in ('-i', '--input-dir'):
input_dir = osp.expanduser(osp.expandvars(arg))
elif opt in ('-o', '--output-dir'):
output_dir = osp.expanduser(osp.expandvars(arg))
elif opt in ('-l', '--loglevel'):
lvl = string.upper(arg)
logLevel = getattr(logging, lvl)
msg.setLevel(logLevel)
del lvl,logLevel
pass
else:
pass
pass
if input_dir is None: input_dir = os.getcwd()
if output_dir is None:
fname = osp.join(os.getcwd(), ".abootstrap.cfg")
if osp.exists(fname):
# (try) to get them from a previous run of abootstrap-wrkarea
with open(fname, 'r') as sticky_file:
from ConfigParser import SafeConfigParser
cfg = SafeConfigParser()
cfg.readfp(sticky_file)
ath_cfg = dict(cfg.items('abootstrap'))
hostname = ath_cfg['hostname']
input_dir = ath_cfg['input-dir']
output_dir = ath_cfg['output-dir']
del cfg
pass
if output_dir is None:
# use parent-dir...
output_dir = osp.join('/tmp',
'$USER',
'aboot-tmp-'+osp.basename(os.getcwd()))
opts.input_dir = osp.abspath(osp.expanduser(osp.expandvars(input_dir)))
opts.output_dir= osp.abspath(osp.expanduser(osp.expandvars(output_dir)))
return opts
if __name__ == "__main__":
msg = logging.getLogger('AthBoot')
msg.setLevel(logging.INFO)
## process user options
opts = _processOptions(_useropts, _userlongopts)
msg.info("#"*50)
msg.info(" input-dir: [%s]", opts.input_dir)
msg.info(" output-dir: [%s]", opts.output_dir)
msg.info("#"*50)
msg.info("")
import shutil
# removing output dir
if osp.exists(opts.output_dir):
shutil.rmtree(opts.output_dir)
# remove InstallArea if any
if osp.exists('InstallArea'):
shutil.rmtree('InstallArea')
# create $CMTCONFIG directories...
msg.info("creating WorkArea...")
import commands as com
sc,out = com.getstatusoutput('setupWorkArea.py')
if sc:
print out
sys.exit(1)
orig_dir = os.getcwd()
os.chdir('WorkArea/cmt')
## msg.info("cmt bro cmt config...")
## sc,out = com.getstatusoutput('cmt bro cmt config')
## if sc:
## print out
## sys.exit(1)
msg.info("creating $CMTCONFIG directories...")
sc,out = com.getstatusoutput('cmt bro \"/bin/rm -rf ../$CMTCONFIG; /bin/mkdir -p ../$CMTCONFIG; echo 1\"')
if sc:
print out
sys.exit(1)
os.chdir(orig_dir)
msg.info('registering bin dirs...')
bin_dirs = register_bin_dirs(opts.input_dir)
msg.info('installing symlinks...')
symlink_bin_dirs(opts.input_dir, opts.output_dir, bin_dirs)
for d in ('python', os.environ['CMTCONFIG']):
d = osp.join('InstallArea', d)
if not osp.exists(d):
msg.info('creating [%s] (to prevent CMT bug)...', d)
os.makedirs(d)
## to remember where we put those binary files, in case we logged on a
## different lxplus node...
with open(osp.join(opts.input_dir, ".abootstrap.cfg"), 'w') as f:
import socket
f.writelines([
"[abootstrap]\n",
"hostname = %s\n" % socket.gethostname(),
"input-dir = %s\n" % opts.input_dir,
"output-dir = %s\n" % opts.output_dir,
])
pass
msg.info("## Bye.")
sys.exit(0)
#!/usr/bin/env python
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# @file PyUtils.acmd
# @purpose main command line script for the general purpose athena scripts
# @author Sebastien Binet
# @date January 2010
from __future__ import with_statement
__version__ = "$Revision: 276499 $"
__author__ = "Sebastien Binet"
__doc__ = "main command line script for the general purpose athena scripts"
import PyUtils.acmdlib as acmdlib
def main():
import PyUtils.scripts
import PyUtils.Logging as L
msg = L.logging.getLogger('Acmd')
msg.setLevel(L.logging.INFO)
## if 0:
## acmdlib.register_file('acmd_plugins.cfg')
## else:
## import os
## if os.path.exists('acmd_plugins.py'):
## execfile('acmd_plugins.py')
commands = {}
plugins = list(acmdlib.ext_plugins.get(group=acmdlib.ACMD_GROUPNAME))
#print plugins
for i, plugin in enumerate(plugins):
#print i, plugin.name
commands[plugin.name] = plugin
if 1:
acmdlib._load_commands()
parser = acmdlib.ACMD_PARSER
args = parser.parse_args()
msg.info('running sub-command [%s]...', args.command)
cmd_name = args.command
import sys
sys_args = sys.argv[1:]
if sys_args[0] != cmd_name:
# special case of a sub(sub,...) command:
# acmd a b c cmd arg1 arg2 ...
# -> a.b.c.cmd
idx = sys_args.index(cmd_name)
cmd_name = '.'.join(sys_args[:idx+1])
cmd = commands[cmd_name].load()
exitcode = 1
try:
exitcode = cmd(args)
except Exception:
exitcode = 1
import sys
print sys.exc_info()[0]
print sys.exc_info()[1]
raise
return exitcode
if __name__ == "__main__":
import sys
sys.exit(main())
This diff is collapsed.
#!/usr/bin/env python
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# @file avn.py
# @purpose an atlas oriented SVN helper script
# @date October 2009
# credits: Scott Snyder provided the first version.
__doc__ = """
an atlas oriented SVN helper script
-----------------------------------
examples of usage:
$ cd Control/AthenaServices
$ avn ci -m 'some interesting comment'
$ avn tag AthenaServices-99-99-99 -m 'some interesting comment'
$ avn diff @AthenaServices-66-66-66 @AthenaServices-99-99-99
$ avn diff @AthenaServices-66-66-66/src @AthenaServices-99-99-99/src
$ avn diff @AthenaServices-66-66-66/src/f.cxx @AthenaServices-99-99-99/src/f.cxx
$ avn lstags
$ avn switch @TRUNK
$ avn switch @AthenaServices-01-33-06-branch
$ avn up
$ avn -n some_command # => dryrun (does not execute the command)
"""
__version__ = "$Revision: 508489 $"
__author__ = "Sebastien Binet"
import sys
import os
import commands
import re
import string
import subprocess
tagchars = string.ascii_letters + string.digits + '-' + '_'
# patterns taken from atlas svn-hooks...
_is_tag_name_valid_tc = re.compile("(^[A-Za-z_]+-[A-Za-z_]+-[0-9]{2}-[0-9]{2}-[0-9]{2}$)|(^[A-Za-z_]+-[A-Za-z_]+-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}$)").match
_is_tag_name_valid = re.compile("(^[A-Za-z0-9_]+-[0-9]{2}-[0-9]{2}-[0-9]{2}$)|(^[A-Za-z0-9_]+-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}$)").match
class AvnObject(object):
"""dummy object to hold options and variables
"""
@property
def url(self):
url = None
try:
url = self._url
except AttributeError:
lines = commands.getoutput('svn info').split('\n')
for l in lines:
if l.startswith('URL: '):
url = self._url = l[5:]
break
if url is None:
err = "Can't find svn URL."
print >> sys.stderr, err
raise RuntimeError(err)
return url
@property
def root(self):
root = None
try:
root = self._root
except AttributeError:
lines = commands.getoutput('svn info').split('\n')
for l in lines:
if l.startswith('Repository Root: '):
root = self._root = l[17:]
break
if root is None:
err = "Can't find svn repository root. will assume to be $SVNROOT"
print >> sys.stderr, err
root = self._root = os.environ['SVNROOT']
return root
@property
def testarea(self):
try:
return self._testarea
except AttributeError:
if not 'TestArea' in os.environ:
err = 'TestArea is not defined.'
print sys.stderr, err
raise RuntimeError(err)
self._testarea = os.path.realpath(os.environ['TestArea'])
return self._testarea
@property
def cwd(self):
cwd = os.getcwd()
if not cwd.startswith(self.testarea):
err = 'Current directory is not within TestArea.'
print >> sys.stderr, err
raise RuntimeError(err)
return cwd
@property
def packpath(self):
try:
return self._packpath
except AttributeError:
testarea = self.testarea
packpath = self.cwd[len(testarea):]
if packpath.startswith('/'):
packpath = packpath[1:]
path = None
while not os.path.exists (os.path.join (testarea, packpath, 'cmt')):
comp = os.path.basename (packpath)
packpath = os.path.dirname (packpath)
if path is None:
path = comp
else:
path = os.path.join (comp, path)
if packpath == '':
err = "Can't find cmt directory."
print >> sys.stderr, err
raise RuntimeError(err)
self._path = path
self._packpath = packpath
return self._packpath
@property
def path(self):
packpath = self.packpath # side-effect will compute self._path
return self._path
pass # class AvnObject
def mungtag(s, allow_use_cmt=False):
if allow_use_cmt:
try:
return mungtag(s)
except Exception:
import PyCmt.Cmt as Cmt
cmt = Cmt.CmtWrapper()
pkg = cmt.find_pkg(s.split('-')[0])
if pkg:
avn._packpath = os.path.join(pkg.path, pkg.name)
avn._path = None
if s in ('HEAD','TRUNK'):
thisurl = os.path.join (avn.root, avn.packpath, 'trunk')
elif s == 'THIS':
thisurl = avn.url
elif s.endswith ('-branch'):
thisurl = os.path.join (avn.root, avn.packpath, 'branches', s)
else:
thisurl = os.path.join (avn.root, avn.packpath, 'tags', s)
if not (avn.path is None):
thisurl = os.path.join (thisurl, avn.path)
return thisurl
def mungarg(s,do_mung=True):
if do_mung:
beg = 0
while True:
beg = s.find ('@', beg)
if beg < 0: break
end = beg + 1
while end < len(s) and s[end] in tagchars:
end += 1
if beg == end:
beg += 1
continue
s = s[:beg] + mungtag(s[beg+1:end], allow_use_cmt=True) + s[end:]
if s.find(' ') >= 0:
s = "'" + s + "'"
return s
avn = AvnObject()
"""the one and only one Atlas Svn helper object"""
del AvnObject
### ---------------------------------------------------------------------------
### command functions
def avn_help():
print __doc__
print "normal svn help output follows"
print "-"*80
print
return
def avn_tag(args):
cmd_args = args[:]
for i,tag in enumerate(cmd_args):
if tag[0] == '-':
if tag.startswith(('-r', '--revision')):
has_r_switch = True
continue
if tag.find(':') < 0:
if tag[0] == '@':
tag = tag[1:]
if _is_tag_name_valid(tag):
tag = mungtag(tag)
cmd_args[i] = tag
pass
pass
pass
cmd_args = ['cp', avn.url,] + cmd_args[1:]
return cmd_args
def avn_lstags(args):
cmd_args = ['ls', os.path.join (avn.root, avn.packpath, 'tags'),
os.path.join (avn.root, avn.packpath, 'branches')]
return cmd_args
def avn_ls(args):
cmd_args = args[:]
if cmd_args[1].find('//') < 0:
cmd_args[1] = os.path.join (avn.root, avn.packpath, cmd_args[1])
return cmd_args
def avn_diff(args):
cmd_args = args[:]
## if cmd_args[1][0] != '-' and cmd_args[2][0] != '-':
## rev_ref = mungtag(cmd_args[1], allow_use_cmt=True)
## rev_chk = mungtag(cmd_args[2], allow_use_cmt=True)
## if len(cmd_args) == 4:
## file_or_dir = cmd_args[3]
<