Esempio n. 1
0
def github_issues(arg=None):
    """
    Retrieve information about cmssh tickets, e.g.
    Examples:
        cmssh> tickets     # list all cmssh tickets
        cmssh> ticket 14   # get details for given ticket id
        cmssh> ticket new  # post new ticket from cmssh
        # or post it at https://github.com/vkuznet/cmssh/issues/new
    """
    if arg == 'new':
        msg = 'You can post new ticket via web interface at\n'
        msg += 'https://github.com/vkuznet/cmssh/issues/new\n'
        msg += 'otherwise it will be posted as anonymous gist ticket'
        print_info(msg)
        if not user_input('Proceed', default='N'):
            return
        email = raw_input('Your Email : ')
        if not email:
            msg = "You did your email address"
            print_error(msg)
            return
        desc = ''
        msg = 'Type your problem, attach traceback, etc. Once done print '
        msg += msg_blue('EOF') + ' and hit ' + msg_blue('Enter') + '\n'
        print msg
        while True:
            try:
                uinput = raw_input()
                if uinput.strip() == 'EOF':
                    break
                desc += uinput + '\n'
            except KeyboardInterrupt:
                break
        if not desc:
            msg = "You did not provide bug description"
            print_error(msg)
            return
        if not user_input('Send this ticket', default='N'):
            print_info('Aborting your action')
            return
        key = 'cmssh-%s' % time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.gmtime(time.time()))
        files = {key: {'content': desc}}
        res = post_ticket(key, files)
        if res.has_key('html_url'):
            print_status('New gist ticket %s' % res['html_url'])
            title = 'cmssh gist %s' % res['html_url']
            if isinstance(res, dict):
                ticket = pprint.pformat(res)
            else:
                ticket = res
            to_user = base64.decodestring('dmt1em5ldEBnbWFpbC5jb20=\n')
            send_email(to_user, email, title, ticket)
    else:
        res = get_tickets(arg)
        RESMGR.assign(res)
        pprint.pprint(res)
Esempio n. 2
0
def github_issues(arg=None):
    """
    Retrieve information about cmssh tickets, e.g.
    Examples:
        cmssh> tickets     # list all cmssh tickets
        cmssh> ticket 14   # get details for given ticket id
        cmssh> ticket new  # post new ticket from cmssh
        # or post it at https://github.com/vkuznet/cmssh/issues/new
    """
    if  arg == 'new':
        msg  = 'You can post new ticket via web interface at\n'
        msg += 'https://github.com/vkuznet/cmssh/issues/new\n'
        msg += 'otherwise it will be posted as anonymous gist ticket'
        print_info(msg)
        if  not user_input('Proceed', default='N'):
            return
        email = raw_input('Your Email : ')
        if  not email:
            msg = "You did your email address"
            print_error(msg)
            return
        desc  = ''
        msg   = 'Type your problem, attach traceback, etc. Once done print '
        msg  += msg_blue('EOF') + ' and hit ' + msg_blue('Enter') + '\n' 
        print msg
        while True:
            try:
                uinput = raw_input()
                if  uinput.strip() == 'EOF':
                    break
                desc += uinput + '\n'
            except KeyboardInterrupt:
                break
        if  not desc:
            msg = "You did not provide bug description"
            print_error(msg)
            return
        if  not user_input('Send this ticket', default='N'):
            print_info('Aborting your action')
            return
        key   = 'cmssh-%s' % time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()))
        files = {key: {'content': desc}}
        res   = post_ticket(key, files)
        if  res.has_key('html_url'):
            print_status('New gist ticket %s' % res['html_url'])
            title = 'cmssh gist %s' % res['html_url']
            if  isinstance(res, dict):
                ticket = pprint.pformat(res)
            else:
                ticket = res
            to_user = base64.decodestring('dmt1em5ldEBnbWFpbC5jb20=\n')
            send_email(to_user, email, title, ticket)
    else:
        res = get_tickets(arg)
        RESMGR.assign(res)
        pprint.pprint(res)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 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)
Esempio n. 6
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)
Esempio n. 7
0
def cmscrab(arg):
    """
    Execute CRAB command, help is available at
    https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCrabFaq
    """
    msg = \
    'CRAB FAQ: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCrabFaq'
    print_info(msg)
    # check if release version and work area are set (should be set at cmsrel)
    rel = os.environ.get('CMSSW_VERSION', None)
    work_area = os.environ.get('CMSSW_WORKAREA', None)
    if not rel or not work_area:
        msg = 'In order to run crab command you must '
        msg += 'run ' + msg_blue('cmsrel') + ' command'
        print_error(msg)
        return
    # check existence of crab.cfg
    crab_dir = os.path.join(work_area, 'crab')
    crab_cfg = os.path.join(crab_dir, 'crab.cfg')
    if not os.path.isdir(crab_dir):
        os.makedirs(crab_dir)
    os.chdir(crab_dir)
    if not os.path.isfile(crab_cfg):
        msg = 'No crab.cfg file found in %s' % crab_dir
        print_warning(msg)
        msg = 'Would you like to create one'
        if user_input(msg, default='N'):
            with open('crab.cfg', 'w') as config:
                config.write(crabconfig())
            msg = 'Your crab.cfg has been created, please edit it '
            msg += 'appropriately and re-run crab command'
            print_info(msg)
            print "cwd:", os.getcwd()
        return
    if os.uname()[0] == 'Darwin' and arg == '-submit':
        crab_submit_remotely(rel, work_area)
        return
    cmd = 'source $CRAB_ROOT/crab.sh; crab %s' % arg
    cmsexe(cmd)
Esempio n. 8
0
def cmscrab(arg):
    """
    Execute CRAB command, help is available at
    https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCrabFaq
    """
    msg = \
    'CRAB FAQ: https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideCrabFaq'
    print_info(msg)
    # check if release version and work area are set (should be set at cmsrel)
    rel = os.environ.get('CMSSW_VERSION', None)
    work_area = os.environ.get('CMSSW_WORKAREA', None)
    if  not rel or not work_area:
        msg  = 'In order to run crab command you must '
        msg += 'run ' + msg_blue('cmsrel') + ' command'
        print_error(msg)
        return
    # check existence of crab.cfg
    crab_dir = os.path.join(work_area, 'crab')
    crab_cfg = os.path.join(crab_dir, 'crab.cfg')
    if  not os.path.isdir(crab_dir):
        os.makedirs(crab_dir)
    os.chdir(crab_dir)
    if  not os.path.isfile(crab_cfg):
        msg = 'No crab.cfg file found in %s' % crab_dir
        print_warning(msg)
        msg = 'Would you like to create one'
        if  user_input(msg, default='N'):
            with open('crab.cfg', 'w') as config:
                config.write(crabconfig())
            msg  = 'Your crab.cfg has been created, please edit it '
            msg += 'appropriately and re-run crab command'
            print_info(msg)
            print "cwd:", os.getcwd()
        return
    if  os.uname()[0] == 'Darwin' and arg == '-submit':
        crab_submit_remotely(rel, work_area)
        return
    cmd = 'source $CRAB_ROOT/crab.sh; crab %s' % arg
    cmsexe(cmd)