Beispiel #1
0
def project_bootnewproject(opts, args):
    if len(args) != 0:
        SCRAM.scramfatal("Error parsing arguments. See \"scram -help\" for usage info.")
    areaname = ''
    bootstrapfile = opts.bootstrap
    installarea = opts.install_base_dir
    bs = BootStrapProject(installarea)
    area = bs.boot(bootstrapfile)
    XX = """
Beispiel #2
0
def cmd_list(args):
    parser = ArgumentParser(add_help=False)
    parser.add_argument('-A', '--all',
                        dest='all',
                        action='store_true',
                        default=False,
                        help='List all release for all available architectures.')
    parser.add_argument('-c', '--compact',
                        dest='compact',
                        action='store_true',
                        default=False,
                        help='Show compact results.')
    parser.add_argument('-e', '--exists',
                        dest='exists',
                        action='store_true',
                        default=False,
                        help='Show only valid projects.')
    opts, args = parser.parse_known_args(args)
    db = ProjectDB()
    project = args[0] if len(args) > 0 else ''
    version = args[1] if len(args) > 1 else ''
    if version == '':
        version = project
        project = project.split('_', 1)[0]
        if not db.hasProject(project):
            project = ''
    projects = db.listall(project.upper(), version, opts.exists, opts.all)
    if not projects:
        msg = ""
        if not SCRAM.FORCED_ARCH:
            msg = " for architecture %s" % environ['SCRAM_ARCH']
        if not version:
            SCRAM.scramwarning(">>>> No SCRAM project %s version %s available%s. <<<<" % (project, version, msg))
            SCRAM.printerror("You can run \"scram list %s\" to see the available versions." % project)
        elif project:
            SCRAM.scramwarning(">>>> No SCRAM project %s available%s. <<<<" % (project, msg))
            SCRAM.printerror("You can run \"scram list\" to see the available projects and their versions.")
        else:
            SCRAM.scramwarning(">>>> There are no SCRAM project yet installed%s. <<<<" % msg)
        return False
    headstring = "| {:12s}  | {:24s} | {:33} |".format("Project Name", "Project Version", "Project Location")
    for arch in projects:
        if not opts.compact:
            print("\nListing installed projects available for platform >> %s\n" % arch)
            print(headstring)
        for item in projects[arch]:
            pstring = ""
            if opts.compact:
                pstring = "{:15s} {:25s} {:50s}".format(item[0], item[1], item[2])
            else:
                pstring = "  {:15s} {:25s}  \n{:41s}--> {:30s}".format(item[0], item[1], "", item[2])
            print(pstring)
    return True
Beispiel #3
0
def cmd_unsetenv(args):
    print(args)
    from SCRAM.Core.RuntimeEnv import RUNTIME_SHELLS
    print(RUNTIME_SHELLS)
    if (len(args) != 1) or (args[0] not in RUNTIME_SHELLS):
        SCRAM.scramfatal("Error parsing arguments. See \"scram -help\" for usage info.")
    from SCRAM.Core.RuntimeEnv import RuntimeEnv
    area = Core()
    area.checklocal()
    rt = RuntimeEnv(area.localarea())
    rt.unsetenv(RUNTIME_SHELLS[args[0]])
    return True
Beispiel #4
0
def cmd_project(args):
    parser = ArgumentParser(add_help=False)
    parser.add_argument('-l', '--log',
                        dest='log',
                        action='store_true',
                        default=False,
                        help='See the detail log message while creating a dev area')
    parser.add_argument('-s', '--symlinks',
                        dest='symlinks',
                        action='store_true',
                        default=False,
                        help='Creates symlinks for various product build directories.')
    parser.add_argument('-u', '--update',
                        dest='update',
                        action='store_true',
                        default=False,
                        help='Command-line argument -u|--update is no more supported.')
    parser.add_argument('-d', '--dir',
                        dest='install_base_dir',
                        type=str,
                        default=None,
                        help='Project installation base directory.')
    parser.add_argument('-b', '--boot',
                        dest='bootstrap',
                        type=str,
                        default=None,
                        help='Creates a release area using the bootstrap file')
    parser.add_argument('-n', '--name',
                        dest='install_name',
                        type=str,
                        default=None,
                        help='Specify the name of the SCRAM-base development area directory.')
    opts, args = parser.parse_known_args(args)
    SCRAM.INTERACTIVE = True if opts.log else False

    if opts.bootstrap:
        return project_bootnewproject(opts, args)
    if len(args) == 0:
        SCRAM.scramfatal("Error parsing arguments. See \"scram -help\" for usage info.")
    project = args[0]
    version = args[1] if len(args) > 1 else None
    releasePath = None
    if version is None:
        if isdir(project) and project.startswith('/'):
            area = ConfigArea(SCRAM.FORCED_ARCH)
            releasePath = area.searchlocation(project)
            if not releasePath:
                SCRAM.scramerror("Not a valid scram-based release area: %s" % project)
            project = basename(releasePath)
        version = project
        project = project.split('_', 1)[0]
    return project_bootfromrelease(project.upper(), version, releasePath, opts)
Beispiel #5
0
def tool_info(args, area):
    if not args:
        SCRAM.scramfatal("No tool name given: see \"scram tool -help\" for usage info.")

    toolmanager = ToolManager(area)
    toolname = args[0].lower()
    tool = toolmanager.gettool(toolname)
    if not tool:
        SCRAM.scramerror(">>>> Tool %s is not setup for this project area. <<<<" % toolname)
    msg = "Tool info as configured in location %s" % area.location()
    msglen = len(msg)
    msg += "\n%s\n" % ("+" * len(msg))
    msg += "Name : %s\n" % toolname
    msg += "Version : %s\n" % tool['TOOLVERSION']
    msg += "%s\n" % ("+" * 20)
    SCRAM.printmsg(msg)
    tooldata = ToolFile.summarize_tool(tool)
    for tag in sorted(tooldata):
        SCRAM.printmsg('%s=%s' % (tag, tooldata[tag]))
    SCRAM.printmsg("")
    return True
Beispiel #6
0
def tool_list(args, area):
    toolmanager = ToolManager(area)
    tools = toolmanager.toolsdata()
    if not tools:
        SCRAM.scramerror(">>>> No tools set up for current arch or area! <<<<")

    msg = "Tool list for location %s" % area.location()
    msglen = len(msg)
    msg += "\n%s\n" % ("+" * len(msg))
    SCRAM.printmsg("\n%s" % msg)
    for tool in sorted(tools):
        SCRAM.printmsg(" {:40s} {:20s}".format(tool, tools[tool]['TOOLVERSION']))
    SCRAM.printmsg("")
    return True
Beispiel #7
0
def tool_remove(args, area):
    if len(args) < 1:
        SCRAM.scramfatal("No tool name given: see \"scram tool -help\" for usage info.")

    toolname = args[0].lower()
    toolmanager = ToolManager(area)
    if not toolmanager.hastool(toolname):
        SCRAM.errormsg(">>>> Tool %s is not defined for this project area. <<<<" % toolname)
    SCRAM.printmsg("Removing tool %s from current project area configuration." % toolname)
    toolmanager.remove_tool(toolname)
    return True
Beispiel #8
0
def tool_tag(args, area):
    if len(args) < 1:
        SCRAM.scramfatal("No tool name given: see \"scram tool -help\" for usage info.")

    toolmanager = ToolManager(area)
    toolname = args[0].lower()
    tool = toolmanager.gettool(toolname)
    if not tool:
        SCRAM.scramerror(">>>> Tool %s is not setup for this project area. <<<<" % toolname)
    tag = None if len(args) == 1 else args[1]
    msg = ToolFile.get_feature(tool, tag)
    if msg:
        SCRAM.printmsg(msg)
    return True
Beispiel #9
0
def cmd_setup(args):
    parser = ArgumentParser(add_help=False)
    parser.add_argument('-i', '--interactive',
                        dest='interactive',
                        action='store_true',
                        default=False,
                        help='Obsolete command-line argument')
    opts, args = parser.parse_known_args(args)
    if len(args) > 1:
        SCRAM.scramfatal("Error parsing arguments. See \"scram -help\" for usage info.")
    area = Core()
    area.checklocal()
    area.init_env()
    larea = area.localarea()
    toolmanager = ToolManager(larea)
    tool = ''
    if args:
        tool = args[0]
    if tool:
        if not exists(tool):
            toolname = tool.lower()
            if toolname != 'self':
                toolbox = larea.toolbox()
                tool = join(toolbox, 'selected', '%s.xml' % toolname)
                if not exists(tool):
                    tool = join(toolbox, 'available', '%s.xml' % toolname)
                    if not exists(tool):
                        SCRAM.scramfatal('Can not setup tool "%s" because of missing "%s.xml" '
                                         'file under %s directory."' % (toolname, toolname, toolbox))
            else:
                tool = toolname
        else:
            tool = abspath(tool)
    toolmanager = ToolManager(larea)
    _init_self_env(toolmanager, tool)
    if tool:
        if tool != 'self':
            toolmanager.coresetup(tool)
    else:
        SCRAM.printmsg("Setting up all tools in current area")
        if not isdir(larea.toolcachename()):
            create_productstores(larea)
            toolmanager.setupself()
        toolmanager.setupalltools()
    return True
Beispiel #10
0
def cmd_tool(args):
    area = Core()
    area.checklocal()
    if not args or args[0].lower() not in ['list', 'info', 'tag', 'remove']:
        SCRAM.scramfatal("Error parsing arguments. See \"scram -help\" for usage info.")
    return eval('tool_%s' % args[0].lower())(args[1:], area.localarea())
Beispiel #11
0
def cmsos():
    e, os = SCRAM.run_command('cmsos')
    if e:
        return None
    return '_'.join(os.split('_', 2)[:2])
Beispiel #12
0
def project_bootfromrelease(project, version, releasePath, opts):
    installdir = opts.install_base_dir if opts.install_base_dir else getcwd()
    installname = opts.install_name if opts.install_name else version
    relarea = None
    if not (project and version):
        SCRAM.scramfatal("Insufficient arguments: see \"scram project -help\" for usage info.")
    db = ProjectDB()
    relarea = None
    if releasePath:
        relarea = db.getAreaObject([project, version, releasePath, None], SCRAM.FORCED_ARCH)
    else:
        relarea = db.getarea(project, version, force=SCRAM.COMMANDS_OPTS.force)
    xarch = environ['SCRAM_ARCH']
    if not relarea or not isdir(relarea.archdir()):
        if db.deprecated:
            return False
        archs = list(db.listcache)
        errmsg = 'ERROR: Project "%s" version "%s" is not available for arch %s.\n' % (project, version, xarch)
        if len(archs) > 1:
            errmsg += '       "%s" is currently available for following archs.\n' % (project)
            errmsg += '       Please set SCRAM_ARCH properly and re-run the command.\n    %s' % '\n    '.join(archs)
        else:
            errmsg += '       Please make sure you have used the correct name/version.\n'
            errmsg += '       You can run \"scram list $projectname\" to get the list of available versions.'
        SCRAM.printerror(errmsg)
        return False
    arch = relarea.arch()
    SCRAM.FORCED_ARCH = arch
    environ['SCRAM_ARCH'] = arch
    if isdir(join(installdir, installname, relarea.admindir(), arch)):
        SCRAM.printerror("WARNING: There already exists %s/%s area for SCRAM_ARCH %s." %
                         (installdir, installname, arch))
        return True

    # Re-run if different SCRAM version is needed to bootstrap the area.
    # remote_versioncheck(relarea)

    SCRAM.printmsg("Creating a developer area based on project %s version %s"
                   % (project, version), SCRAM.INTERACTIVE)
    environ['RELEASETOP'] = relarea.location()
    localarea = Core()
    symlink = 1 if opts.symlinks else 0
    area = relarea.satellite(installdir, installname, symlink, localarea.localarea())
    chdir(area.location())
    c = Core()
    c.init_env()
    create_productstores(c.localarea())
    if relarea.basedir:
        with open(join(area.config(), 'scram_basedir'), 'w') as ref:
            ref.write(relarea.basedir)
    XXX = """
    my $toolmanager = $self->toolmanager($area);
    $toolmanager->update ($area);

    # Write the cached info:
    $toolmanager->writecache();

        my $temp=$area->location()."/".$area->{admindir}."/".$ENV{SCRAM_ARCH};
        if (-f "${temp}/MakeData/Tools.mk")
           {
           my $t1=(stat("${temp}/MakeData/Tools.mk"))[9];
           utime $t1-1,$t1-1,"${temp}/MakeData/Tools.mk";
           if (-f "${temp}/timestamps/self")
              {
              utime $t1,$t1,"${temp}/timestamps/self";
              }
           }
"""
    SCRAM.printmsg("\n\nInstallation procedure complete.", SCRAM.INTERACTIVE)
    SCRAM.printmsg("Developer area located at:\n\n\t\t%s\n\n" % area.location(), SCRAM.INTERACTIVE)
    if xarch != arch:
        SCRAM.printmsg("WARNING: Release %s is not available for architecture %s" %
                       (version, xarch))
        SCRAM.printmsg("         Developer's area is created for available architecture %s." %
                       (arch))
    os = cmsos()
    if not arch.startswith(os):
        SCRAM.printmsg("WARNING: Developer's area is created for architecture %s while your current OS is %s." %
                       (arch, os))
    if not SCRAM.COMMANDS_OPTS.force:
        os = db.productionArch(project, version, area.location())
        if os and os != arch:
            msg = "WARNING: Developer's area is created for non-production architecture %s. " \
                  "Production architecture for this release is %s" % (arch, os)
            SCRAM.printmsg(msg)
    tc = db.getProjectModule(project)
    if tc:
        tc.getData(version, relarea.location())
    if 'SCRAM_IGNORE_PROJECT_HOOK' not in environ:
        proj_hook = join(area.config(), 'SCRAM', 'hooks', 'project-hook')
        if exists(proj_hook):
            SCRAM.run_command(proj_hook)
    if '/afs/cern.ch/' in environ['SCRAM_TOOL_HOME']:
        msg = "****************************** WARNING ******************************\n" \
              "You are using CMSSW from CERN AFS space. Please note that, by the start of 2017, " \
              "new CMSSW releases shall only be available via CVMFS.\n" \
              "See the announcement https://hypernews.cern.ch/HyperNews/CMS/get/swDevelopment/3374.html"
        SCRAM.printmsg(msg)
    return True
Beispiel #13
0
 def checklocal(self):
     if not self.islocal():
         SCRAM.scramfatal("Unable to locate the top of local release. "
                          "Please run this command from a SCRAM-based area.")
Beispiel #14
0
def cmd_db(args):
    parser = ArgumentParser(add_help=False)
    parser.add_argument('-s', '--show',
                        dest='show',
                        action='store_true',
                        default=False,
                        help='Show all the external databases linked in to your SCRAM db')
    parser.add_argument('-l', '--link',
                        dest='link',
                        type=str,
                        default=None,
                        help='Link/Add an external scram db <path> in to local scram db.')
    parser.add_argument('-u', '--unlink',
                        dest='unlink',
                        type=str,
                        default=None,
                        help='Unlink/Remove an already linked external db <path> from the local scram db.')
    opts, args = parser.parse_known_args(args)
    db = ProjectDB()
    if opts.link:
        environ['SCRAM_LOOKUPDB'] = environ['SCRAM_LOOKUPDB_WRITE']
        if isdir(opts.link):
            if not db.link(opts.link):
                SCRAM.scramerror("Can not link to SCRAM-DB. No such directory: %s" % opts.link)
            else:
                SCRAM.printmsg("Current SCRAM database: %s" % environ['SCRAM_LOOKUPDB'])
                SCRAM.printmsg("Linked \"%s\" to current SCRAM database." % opts.link)
    elif opts.unlink:
        environ['SCRAM_LOOKUPDB'] = environ['SCRAM_LOOKUPDB_WRITE']
        if db.unlink(opts.unlink):
            SCRAM.printmsg("Current SCRAM database: %s" % environ['SCRAM_LOOKUPDB'])
            SCRAM.printmsg("Unlinked \"%s\" from current SCRAM database." % opts.unlink)
    else:
        SCRAM.printmsg("Current SCRAM database: %s" % environ['SCRAM_LOOKUPDB'])
        links = db.listlinks()
        flag = False
        for db_type in ["local", "linked"]:
            if db_type not in links or not links[db_type]:
                continue
            flag = True
            msg = "The following SCRAM databases are linked "
            if 'local' == db_type:
                msg += "directly:"
            else:
                msg += "in-directly:"
            SCRAM.printmsg(msg)
            for extdb in links[db_type]:
                SCRAM.printmsg("\t%s" % extdb)
            SCRAM.printmsg("")
        if not flag:
            SCRAM.printmsg("There are no SCRAM databases linked.")
    return True
Beispiel #15
0
def remote_versioncheck(area):
    sversion = area.scram_version()
    if not sversion:
        SCRAM.scramerror("Unable to determine SCRAM version used to config. remote area.")
    spawnversion(sversion)
Beispiel #16
0
 def setenv(self, shell, where=stdout):
     if self.recursive:
         return
     ref = where
     shell_data = self.shell[shell]
     sep = shell_data['SEP']
     udata = {}
     data = []
     index = 0
     if not self._unsetenv:
         env_prefix = self.env_backup_prefix
         env = self._runtime()
         for d in env['variables']:
             for var, val in data.items():
                 udata[var] = 1
                 data.append({var: val[0]})
         for var in env['path']:
             if '_SRTOPT_' in var:
                 continue
             udata[var] = 1
             benv = '%s%s%s' % (env_prefix, var, self.backup_type[var])
             val = self._fixpathvar(var, sep)
             if benv in environ:
                 val = environ[benv] + val
             data.append({var: val})
         if shell == 'RTBOURNE':
             data.append({'SCRAM_RTBOURNE_SET': environ['SCRAMRT_SET']})
             for var, val in env['xenv'].items():
                 udata[var] = 1
                 data.append({var: val})
     for var, val in environ.items():
         if var not in udata:
             data.insert(0, {var: val})
             udata[var] = 1
     oenv = self.OENV
     unset = ""
     unset_vars = ""
     for v in oenv:
         if v in udata:
             continue
         if v in environ:
             del environ[v]
         if shell == 'RTBOURNE':
             continue
         unset += " %s" % v
         if not v.startswith('SCRAMRT_') and \
            not v.endswith('_SCRAMRT') and \
            not v.endswith('_SCRAMRTDEL'):
             unset_vars += "      %s\n" % v
     if unset:
         if unset_vars and not self._unsetenv:
             SCRAM.printerror(
                 "**** Following environment variables are going to be unset.\n%s"
                 % unset_vars)
         print("%s %s;" % (shell_data['UNEXPORT'], unset), file=ref)
     for d in data:
         for var, val in d.items():
             if shell == 'RTBOURNE':
                 if var.startswith('SCRAMRT_') or \
                    var.endswith('_SCRAMRT') or \
                    var.endswith('_SCRAMRTDEL'):
                     if var != 'SCRAMRT_SET':
                         del environ[var]
                         continue
                 environ[var] = val
                 continue
             if var != 'PATH' and var in oenv:
                 if val == oenv[var]:
                     continue
             environ[var] = val
             print('%s %s%s\"%s\";' %
                   (shell_data['EXPORT'], var, shell_data['EQUALS'], val),
                   file=stdout)
     return True
     XX = """