Skip to content
Snippets Groups Projects

Improvements to lb-run

Merged Marco Clemencic requested to merge clemenci/LbScripts:lb-run-improvements into master
1 file
+ 44
23
Compare changes
  • Side-by-side
  • Inline
@@ -14,8 +14,12 @@
import os
import sys
import traceback
import logging
import EnvConfig
import LbPlatformUtils
from LbConfiguration.SP2.lookup import (getEnvXmlPath, findProject,
findDataPackage, getLCGRelocation,
getHepToolsInfo, NotFoundError,
@@ -27,6 +31,14 @@ from LbConfiguration.SP2.version import (isValidVersion, expandVersionAlias,
from LbConfiguration.SetupProject import FixProjectCase
HOST_PLATFORM = LbPlatformUtils.dirac_platform()
def supported(binary_tag):
'return True if the current host supports the given binary_tag'
return LbPlatformUtils.can_run(HOST_PLATFORM,
LbPlatformUtils.requires(binary_tag))
auto_override_projects = [('Compat', 'latest')]
@@ -364,24 +376,15 @@ class SP2(EnvConfig.Script):
Return the "best" platform
'''
try:
from LbPlatformUtils import dirac_platform, can_run, requires
from itertools import ifilter
host = dirac_platform()
def supported(binary_tag):
'return True if the current host supports the given binary_tag'
return can_run(host, requires(binary_tag))
platforms = listPlatforms(self.project, self.version)
return ifilter(supported, platforms).next()
except StopIteration:
# a StopIteration from 'next()' means iterator empty
self.log.error('current host does not support and of %s/%s '
self.log.error('current host does not support any of %s/%s '
'available platforms', self.project, self.version)
except ImportError as x:
self.log.error('cannot guess best platform (ImportError: %s)', x)
raise SystemExit(1)
raise SystemExit(64)
def _makeEnv(self):
# FIXME: when we drop Python 2.4, this should become
@@ -415,6 +418,10 @@ class SP2(EnvConfig.Script):
if self.opts.platform.lower() == 'best':
self.opts.platform = self._findBestPlatform()
elif not supported(self.opts.platform):
self.log.error('current host does not support platform %s',
self.opts.platform)
sys.exit(66)
# special handling of the virtual project ROOT
# (unless we only want to list)
@@ -540,7 +547,12 @@ class SP2(EnvConfig.Script):
self.opts.actions.append(('set', ('CMTCONFIG', self.opts.platform)))
self.opts.actions.append(('set', ('BINARY_TAG', self.opts.platform)))
super(SP2, self)._makeEnv()
try:
super(SP2, self)._makeEnv()
except SystemExit as exc:
# make sure that an exit from underlying _makeEnv has the right
# bit set
raise SystemExit(exc.code | 64)
def compatMain(self, reason=None):
'''
@@ -577,20 +589,29 @@ class SP2(EnvConfig.Script):
self.env = control.vars()
if self.cmd:
sys.exit(self.runCmd())
return self.runCmd()
else:
self.dump()
return 0
def main(self):
from lookup import NotFoundError
try:
if not self.opts.use_setupproject:
super(SP2, self).main()
else:
self.compatMain()
except (NotFoundError, IOError, OSError), x:
if self.opts.path_to_project or self.opts.no_setupproject:
# SetupProject does not support --path-to-project
self.log.error('%s', x)
sys.exit(1)
self.compatMain(x)
try:
if not self.opts.use_setupproject:
super(SP2, self).main()
else:
sys.exit(self.compatMain())
except (NotFoundError, IOError, OSError), x:
if self.opts.path_to_project or self.opts.no_setupproject:
# SetupProject does not support --path-to-project
self.log.error('%s', x)
sys.exit(64)
sys.exit(self.compatMain(x))
except SystemExit:
# pass through SystemExit exceptions (sys.exit)
raise
except:
# force a special exit code for unhandled exceptions
traceback.print_exc()
raise SystemExit(65)
Loading