Exemple #1
0
def cmsenv(_arg):
    "cmsenv command"
    # in CMS cmsenv is an alias to: eval `scramv1 runtime -sh`'
    msg  = 'Within cmssh it is not required to use cmsenv\n'
    msg += 'please use ' + msg_green('cmsrel') + ' command and '
    msg += 'CMS release environment will be set for you'
    print_info(msg)
Exemple #2
0
def check_voms_proxy():
    "Check status of user VOMS proxy"
    cmd = 'voms-proxy-info -timeleft'
    out, err = execmd(cmd)
    if  err:
        print_error('Fail to check user proxy info')
        return

    if  int(out) < 3600: # time left is less then 1 hour
        msg  = 'Your VOMS proxy will expire in %s sec (< 1 hour). ' % out
        msg += 'Please run ' + msg_green('vomsinit') + ' command to renew it'
        print_warning(msg)
Exemple #3
0
def check_voms_proxy():
    "Check status of user VOMS proxy"
    cmd = 'voms-proxy-info -timeleft'
    out, err = execmd(cmd)
    if err:
        print_error('Fail to check user proxy info')
        return

    if int(out) < 3600:  # time left is less then 1 hour
        msg = 'Your VOMS proxy will expire in %s sec (< 1 hour). ' % out
        msg += 'Please run ' + msg_green('vomsinit') + ' command to renew it'
        print_warning(msg)
Exemple #4
0
def cmsexe(cmd):
    """
    Execute given command within CMSSW environment
    """
    vdir = os.environ.get('VO_CMS_SW_DIR', None)
    arch = os.environ.get('SCRAM_ARCH', None)
    if not vdir or not arch:
        msg = 'Unable to identify CMSSW environment, please run first: '
        msg = msg_red(msg)
        msg += msg_blue('cmsrel <rel>\n')
        releases = os.listdir(os.environ['CMSSW_RELEASES'])
        msg += '\nInstalled releases: ' + msg_green(', '.join(releases))
        print msg
        return
    cmd = "eval `scramv1 runtime -sh`; %s" % cmd
    run(cmd, shell=True, call=True)
Exemple #5
0
def cmsexe(cmd):
    """
    Execute given command within CMSSW environment
    """
    vdir = os.environ.get('VO_CMS_SW_DIR', None)
    arch = os.environ.get('SCRAM_ARCH', None)
    if  not vdir or not arch:
        msg  = 'Unable to identify CMSSW environment, please run first: '
        msg  = msg_red(msg)
        msg += msg_blue('cmsrel <rel>\n')
        releases = os.listdir(os.environ['CMSSW_RELEASES'])
        msg += '\nInstalled releases: ' + msg_green(', '.join(releases))
        print msg
        return
    cmd = "eval `scramv1 runtime -sh`; %s" % cmd
    run(cmd, shell=True, call=True)
Exemple #6
0
def installed_releases():
    "Print a list of releases installed on a system"
    _osname, osarch = osparameters()
    releases = []
    for idir in os.listdir(os.environ['VO_CMS_SW_DIR']):
        if idir.find(osarch) != -1:
            rdir = os.path.join(\
                os.environ['VO_CMS_SW_DIR'], '%s/cms/cmssw' % idir)
            if os.path.isdir(rdir):
                for rel in os.listdir(rdir):
                    releases.append('%s/%s' % (rel, idir))
    if releases:
        releases.sort()
        print "\nInstalled releases:"
        for rel in releases:
            print rel
    else:
        msg = "\nYou don't have yet CMSSW release installed on your system."
        msg += "\nPlease use " + msg_green('install CMSSW_X_Y_Z') \
                + ' command to install one'
        print msg
Exemple #7
0
def installed_releases():
    "Print a list of releases installed on a system"
    _osname, osarch = osparameters()
    releases = []
    for idir in os.listdir(os.environ['VO_CMS_SW_DIR']):
        if  idir.find(osarch) != -1:
            rdir = os.path.join(\
                os.environ['VO_CMS_SW_DIR'], '%s/cms/cmssw' % idir)
            if  os.path.isdir(rdir):
                for rel in os.listdir(rdir):
                    releases.append('%s/%s' % (rel, idir))
    if  releases:
        releases.sort()
        print "\nInstalled releases:"
        for rel in releases:
            print rel
    else:
        msg  = "\nYou don't have yet CMSSW release installed on your system."
        msg += "\nPlease use " + msg_green('install CMSSW_X_Y_Z') \
                + ' command to install one'
        print msg
Exemple #8
0
def cms_help_msg():
    """cmsHelp message"""
    msg = 'Available cmssh commands:\n'
    msg += msg_green('find        ') \
        + ' search CMS meta-data (query DBS/Phedex/SiteDB)\n'
    msg += msg_green('dbs_instance') \
        + ' show/set DBS instance, default is DBS global instance\n'
    msg += msg_green('mkdir/rmdir ') + ' mkdir/rmdir command, ' \
        + 'e.g. mkdir /path/foo or rmdir T3_US_Cornell:/store/user/foo\n'
    msg += msg_green('ls          ') \
        + ' list file/LFN, e.g. ls local.file or ls /store/user/file.root\n'
    msg += msg_green('rm          ') + ' remove file/LFN, ' \
        + 'e.g. rm local.file or rm T3_US_Cornell:/store/user/file.root\n'
    msg += msg_green('cp          ') \
        + ' copy file/LFN, e.g. cp local.file or cp /store/user/file.root .\n'
    msg += msg_green('info        ') \
        + ' provides detailed info about given CMS entity, ' \
        + 'e.g. info run=160915\n'
    msg += msg_green('das         ') + ' query DAS service\n'
    msg += msg_green('das_json    ') \
        + ' query DAS and return data in JSON format\n'
    msg += msg_green('jobs        ') \
        + ' status of job queue or CMS jobs\n'
    msg += msg_green('read        ') \
        + ' read URL/local file content\n'
    msg += msg_green('root        ') + ' invoke ROOT\n'
    msg += msg_green('du          ') \
        + ' display disk usage for given site, e.g. du T3_US_Cornell\n'
    msg += '\nAvailable CMSSW commands (once you install any CMSSW release):\n'
    msg += msg_green('releases    ') \
        + ' list available CMSSW releases, accepts <list|all> args\n'
    msg += msg_green('install     ') \
        + ' install CMSSW release, e.g. install CMSSW_5_0_0\n'
    msg += msg_green('cmsrel      ') \
        + ' switch to given CMSSW release and setup its environment\n'
    msg += msg_green('arch        ') \
        + ' show or switch to given CMSSW architecture, accept <list|all> args\n'
    msg += msg_green('scram       ') + ' CMSSW scram command\n'
    msg += msg_green('cmsRun      ') \
        + ' cmsRun command for release in question\n'
    msg += '\nAvailable GRID commands: <cmd> either grid or voms\n'
    msg += msg_green('vomsinit    ') \
        + ' setup your proxy (aka voms-proxy-init)\n'
    msg += msg_green('vomsinfo    ') \
        + ' show your proxy info (aka voms-proxy-info)\n'
    msg += '\nQuery results are accessible via %s function, e.g.\n' \
        % msg_blue('results()')
    msg += '   find dataset=/*Zee*\n'
    msg += '   for r in results(): print r, type(r)\n'
    msg += '\nList cmssh commands    : ' + msg_blue('commands')
    msg += '\ncmssh command help     : ' + msg_blue('cmshelp <command>')
    msg += '\nInstall python software: ' + \
                msg_blue('pip <search|(un)install> <package>')
    return msg
Exemple #9
0
def cmsrel(rel):
    """
    cmssh release setup command, it setups CMSSW environment and creates user based
    directory structure.
    Examples:
        cmssh> cmsrel # reset CMSSW environment to cmssh one
        cmssh> cmsrel CMSSW_5_2_4
    """
    ipython = get_ipython()
    rel = rel.strip()
    if not rel or rel in ['reset', 'clear', 'clean']:
        path = os.environ['CMSSH_ROOT']
        for idir in ['external', 'lib', 'root']:
            pdir = os.path.join(path, 'install/lib/release_%s' % idir)
            if os.path.islink(pdir):
                os.remove(pdir)
            if os.path.isdir(pdir):
                shutil.rmtree(pdir)
            os.makedirs(pdir)
        # Set cmssh prompt
        prompt = 'cms-sh'
        ipython.prompt_manager.in_template = '%s|\#> ' % prompt
        return

    # check if given release name is installed on user system
    rel_arch = None
    for arch in cms_architectures():
        rel_dir = '%s/cms/cmssw/%s' % (arch, rel)
        if os.path.isdir(os.path.join(os.environ['VO_CMS_SW_DIR'], rel_dir)):
            rel_arch = arch
            break
    if not rel_arch:
        msg = 'Release ' + msg_red(rel)
        msg += ' is not yet installed on your system.\n'
        msg += 'Use ' + msg_green('releases')
        msg += ' command to list available releases.\n'
        msg += 'Use ' + msg_green('install %s' % rel)
        msg += ' command to install given release.'
        print msg
        return

    # set release architecture
    os.environ['SCRAM_ARCH'] = rel_arch

    # setup environment
    cmssw_dir = os.environ.get('CMSSW_RELEASES', os.getcwd())
    if not os.path.isdir(cmssw_dir):
        os.makedirs(cmssw_dir)
    root = os.environ['CMSSH_ROOT']
    idir = os.environ['CMSSH_INSTALL_DIR']
    base = os.path.realpath('%s/CMSSW' % root)
    path = '%s/%s/cms/cmssw/%s' % (base, rel_arch, rel)
    os.environ['CMSSW_BASE'] = os.path.join(cmssw_dir, rel)
    os.environ['CMSSW_RELEASE_BASE'] = path
    for pkg in ['FWCore', 'DataFormats']:
        pdir = '%s/%s' % (idir, pkg)
        if os.path.exists(pdir):
            shutil.rmtree(pdir)
        os.mkdir(pdir)
        touch(os.path.join(pdir, '__init__.py'))
    pkgs = [
        'Framework', 'GuiBrowsers', 'Integration', 'MessageLogger',
        'MessageService', 'Modules', 'ParameterSet', 'PythonUtilities',
        'Services', 'Utilities'
    ]
    for pkg in pkgs:
        link = '%s/src/FWCore/%s/python' % (path, pkg)
        dst = '%s/FWCore/%s' % (idir, pkg)
        os.symlink(link, dst)
    link = '%s/src/DataFormats/FWLite/python' % path
    dst = '%s/DataFormats/FWLite' % idir
    os.symlink(link, dst)
    for lib in ['external', 'lib']:
        link = '%s/%s/%s' % (path, lib, rel_arch)
        dst = '%s/install/lib/release_%s' % (root, lib)
        if os.path.islink(dst):
            os.remove(dst)
        else:
            shutil.rmtree(dst)
        os.symlink(link, dst)

    # switch to given release
    os.environ['CMSSW_VERSION'] = rel
    os.environ['CMSSW_WORKAREA'] = os.path.join(cmssw_dir, rel)
    if os.path.isdir(os.path.join(cmssw_dir, rel + '/src')):
        os.chdir(os.path.join(cmssw_dir, rel + '/src'))
    else:
        os.chdir(cmssw_dir)
        cmd = "scramv1 project CMSSW %s" % rel
        run(cmd)
        os.chdir(os.path.join(rel, 'src'))

    # get ROOT from run-time environment
    cmd = 'eval `scramv1 runtime -sh`; env | grep ^ROOTSYS='
    stdout, _stderr = execmd(cmd)
    rootsys = stdout.replace('\n', '').replace('ROOTSYS=', '')
    dst = '%s/install/lib/release_root' % root
    if os.path.exists(dst):
        if os.path.islink(dst):
            os.remove(dst)
        else:
            shutil.rmtree(dst)
    os.symlink(rootsys, dst)

    # set edm utils for given release
    ipython = get_ipython()
    rdir = '%s/bin/%s' % (rel_dir, rel_arch)
    reldir = os.path.join(os.environ['VO_CMS_SW_DIR'], rdir)
    for name in os.listdir(reldir):
        fname = os.path.join(reldir, name)
        if name.find('edm') == 0 and os.path.isfile(fname):
            # we use Magic(cmd).execute we don't need
            # to add scramv1 command in front of edm one, since
            # execute method will run in current shell environment
            # old command for reference:
            # cmd = "eval `scramv1 runtime -sh`; %s" % fname
            cmd = fname
            ipython.register_magic_function(Magic(cmd).execute, 'line', name)

    # Set cmssh prompt
    ipython.prompt_manager.in_template = '%s|\#> ' % rel

    # final message
    print "%s is ready, cwd: %s" % (rel, os.getcwd())
Exemple #10
0
def cms_help_msg():
    """cmsHelp message"""
    msg  = 'Available cmssh commands:\n'
    msg += msg_green('find        ') \
        + ' search CMS meta-data (query DBS/Phedex/SiteDB)\n'
    msg += msg_green('dbs_instance') \
        + ' show/set DBS instance, default is DBS global instance\n'
    msg += msg_green('mkdir/rmdir ') + ' mkdir/rmdir command, ' \
        + 'e.g. mkdir /path/foo or rmdir T3_US_Cornell:/store/user/foo\n'
    msg += msg_green('ls          ') \
        + ' list file/LFN, e.g. ls local.file or ls /store/user/file.root\n'
    msg += msg_green('rm          ') + ' remove file/LFN, ' \
        + 'e.g. rm local.file or rm T3_US_Cornell:/store/user/file.root\n'
    msg += msg_green('cp          ') \
        + ' copy file/LFN, e.g. cp local.file or cp /store/user/file.root .\n'
    msg += msg_green('info        ') \
        + ' provides detailed info about given CMS entity, ' \
        + 'e.g. info run=160915\n'
    msg += msg_green('das         ') + ' query DAS service\n'
    msg += msg_green('das_json    ') \
        + ' query DAS and return data in JSON format\n'
    msg += msg_green('jobs        ') \
        + ' status of job queue or CMS jobs\n'
    msg += msg_green('read        ') \
        + ' read URL/local file content\n'
    msg += msg_green('root        ') + ' invoke ROOT\n'
    msg += msg_green('du          ') \
        + ' display disk usage for given site, e.g. du T3_US_Cornell\n'
    msg += '\nAvailable CMSSW commands (once you install any CMSSW release):\n'
    msg += msg_green('releases    ') \
        + ' list available CMSSW releases, accepts <list|all> args\n'
    msg += msg_green('install     ') \
        + ' install CMSSW release, e.g. install CMSSW_5_0_0\n'
    msg += msg_green('cmsrel      ') \
        + ' switch to given CMSSW release and setup its environment\n'
    msg += msg_green('arch        ') \
        + ' show or switch to given CMSSW architecture, accept <list|all> args\n'
    msg += msg_green('scram       ') + ' CMSSW scram command\n'
    msg += msg_green('cmsRun      ') \
        + ' cmsRun command for release in question\n'
    msg += '\nAvailable GRID commands: <cmd> either grid or voms\n'
    msg += msg_green('vomsinit    ') \
        + ' setup your proxy (aka voms-proxy-init)\n'
    msg += msg_green('vomsinfo    ') \
        + ' show your proxy info (aka voms-proxy-info)\n'
    msg += '\nQuery results are accessible via %s function, e.g.\n' \
        % msg_blue('results()')
    msg += '   find dataset=/*Zee*\n'
    msg += '   for r in results(): print r, type(r)\n'
    msg += '\nList cmssh commands    : ' + msg_blue('commands')
    msg += '\ncmssh command help     : ' + msg_blue('cmshelp <command>')
    msg += '\nInstall python software: ' + \
                msg_blue('pip <search|(un)install> <package>')
    return msg
Exemple #11
0
def cmsrel(rel):
    """
    cmssh release setup command, it setups CMSSW environment and creates user based
    directory structure.
    Examples:
        cmssh> cmsrel # reset CMSSW environment to cmssh one
        cmssh> cmsrel CMSSW_5_2_4
    """
    ipython = get_ipython()
    rel = rel.strip()
    if  not rel or rel in ['reset', 'clear', 'clean']:
        path = os.environ['CMSSH_ROOT']
        for idir in ['external', 'lib', 'root']:
            pdir = os.path.join(path, 'install/lib/release_%s' % idir)
            if os.path.islink(pdir):
                os.remove(pdir)
            if  os.path.isdir(pdir):
                shutil.rmtree(pdir)
            os.makedirs(pdir)
        # Set cmssh prompt
        prompt = 'cms-sh'
        ipython.prompt_manager.in_template = '%s|\#> ' % prompt
        return

    # check if given release name is installed on user system
    rel_arch = None
    for arch in cms_architectures():
        rel_dir = '%s/cms/cmssw/%s' % (arch, rel)
        if  os.path.isdir(os.path.join(os.environ['VO_CMS_SW_DIR'], rel_dir)):
            rel_arch = arch
            break
    if  not rel_arch:
        msg  = 'Release ' + msg_red(rel)
        msg += ' is not yet installed on your system.\n'
        msg += 'Use ' + msg_green('releases')
        msg += ' command to list available releases.\n'
        msg += 'Use ' + msg_green('install %s' % rel)
        msg += ' command to install given release.'
        print msg
        return

    # set release architecture
    os.environ['SCRAM_ARCH'] = rel_arch

    # setup environment
    cmssw_dir = os.environ.get('CMSSW_RELEASES', os.getcwd())
    if  not os.path.isdir(cmssw_dir):
        os.makedirs(cmssw_dir)
    root = os.environ['CMSSH_ROOT']
    idir = os.environ['CMSSH_INSTALL_DIR']
    base = os.path.realpath('%s/CMSSW' % root)
    path = '%s/%s/cms/cmssw/%s' % (base, rel_arch, rel)
    os.environ['CMSSW_BASE'] = os.path.join(cmssw_dir, rel)
    os.environ['CMSSW_RELEASE_BASE'] = path
    for pkg in ['FWCore', 'DataFormats']:
        pdir = '%s/%s' % (idir, pkg)
        if  os.path.exists(pdir):
            shutil.rmtree(pdir)
        os.mkdir(pdir)
        touch(os.path.join(pdir, '__init__.py'))
    pkgs = ['Framework', 'GuiBrowsers', 'Integration', 'MessageLogger',
            'MessageService', 'Modules', 'ParameterSet', 'PythonUtilities',
            'Services', 'Utilities']
    for pkg in pkgs:
        link = '%s/src/FWCore/%s/python' % (path, pkg)
        dst  = '%s/FWCore/%s' % (idir, pkg)
        os.symlink(link, dst)
    link = '%s/src/DataFormats/FWLite/python' % path
    dst  = '%s/DataFormats/FWLite' % idir
    os.symlink(link, dst)
    for lib in ['external', 'lib']:
        link = '%s/%s/%s' % (path, lib, rel_arch)
        dst  = '%s/install/lib/release_%s' % (root, lib)
        if  os.path.islink(dst):
            os.remove(dst)
        else:
            shutil.rmtree(dst)
        os.symlink(link, dst)

    # switch to given release
    os.environ['CMSSW_VERSION'] = rel
    os.environ['CMSSW_WORKAREA'] = os.path.join(cmssw_dir, rel)
    if  os.path.isdir(os.path.join(cmssw_dir, rel + '/src')):
        os.chdir(os.path.join(cmssw_dir, rel + '/src'))
    else:
        os.chdir(cmssw_dir)
        cmd = "scramv1 project CMSSW %s" % rel
        run(cmd)
        os.chdir(os.path.join(rel, 'src'))

    # get ROOT from run-time environment
    cmd = 'eval `scramv1 runtime -sh`; env | grep ^ROOTSYS='
    stdout, _stderr = execmd(cmd)
    rootsys = stdout.replace('\n', '').replace('ROOTSYS=', '')
    dst     = '%s/install/lib/release_root' % root
    if  os.path.exists(dst):
        if  os.path.islink(dst):
            os.remove(dst)
        else:
            shutil.rmtree(dst)
    os.symlink(rootsys, dst)

    # set edm utils for given release
    ipython = get_ipython()
    rdir    = '%s/bin/%s' % (rel_dir, rel_arch)
    reldir  = os.path.join(os.environ['VO_CMS_SW_DIR'], rdir)
    for name in os.listdir(reldir):
        fname = os.path.join(reldir, name)
        if  name.find('edm') == 0 and os.path.isfile(fname):
            # we use Magic(cmd).execute we don't need
            # to add scramv1 command in front of edm one, since
            # execute method will run in current shell environment
            # old command for reference:
            # cmd = "eval `scramv1 runtime -sh`; %s" % fname
            cmd = fname
            ipython.register_magic_function(Magic(cmd).execute, 'line', name)

    # Set cmssh prompt
    ipython.prompt_manager.in_template = '%s|\#> ' % rel

    # final message
    print "%s is ready, cwd: %s" % (rel, os.getcwd())