Beispiel #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)
Beispiel #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)
Beispiel #3
0
def cms_jobs(arg=None):
    """
    cmssh jobs command lists local job queue or provides information
    about jobs at give site or for given user. It accepts the following
    list of options:

    - list, which lists local transfer jobs
    - site, which lists jobs at given site
    - dashboard, which lists jobs of current user
    - user, which lists jobs of given user

    Examples:
        cmssh> jobs
        cmssh> jobs list
        cmssh> jobs site=T2_US_UCSD
        cmssh> jobs dashboard
        cmssh> jobs user=my_cms_user_name
    """
    res = None
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    if arg:
        arg = arg.strip()
    if not arg or arg == 'list':
        print_info('Local data transfer')
        dqueue(arg)
    elif arg == 'dashboard':
        userdn = os.environ.get('USER_DN', None)
        if userdn:
            user = get_dashboardname(userdn)
            print_info('Dashboard information, user=%s' % user)
            res = jobsummary({'user': user})
    elif pat_site.match(arg):
        site = arg.replace('site=', '')
        print_info('Dashboard information, site=%s' % site)
        res = jobsummary({'site': site})
    elif pat_user.match(arg):
        user = arg.replace('user='******'')
        print_info('Dashboard information, user=%s' % user)
        res = jobsummary({'user': user})
    if res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)
Beispiel #4
0
def cms_jobs(arg=None):
    """
    cmssh jobs command lists local job queue or provides information
    about jobs at give site or for given user. It accepts the following
    list of options:

    - list, which lists local transfer jobs
    - site, which lists jobs at given site
    - dashboard, which lists jobs of current user
    - user, which lists jobs of given user

    Examples:
        cmssh> jobs
        cmssh> jobs list
        cmssh> jobs site=T2_US_UCSD
        cmssh> jobs dashboard
        cmssh> jobs user=my_cms_user_name
    """
    res = None
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if  orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    if  arg:
        arg = arg.strip()
    if  not arg or arg == 'list':
        print_info('Local data transfer')
        dqueue(arg)
    elif arg == 'dashboard':
        userdn = os.environ.get('USER_DN', None)
        if  userdn:
            user = get_dashboardname(userdn)
            print_info('Dashboard information, user=%s' % user)
            res  = jobsummary({'user': user})
    elif  pat_site.match(arg):
        site = arg.replace('site=', '')
        print_info('Dashboard information, site=%s' % site)
        res  = jobsummary({'site': site})
    elif  pat_user.match(arg):
        user = arg.replace('user='******'')
        print_info('Dashboard information, user=%s' % user)
        res  = jobsummary({'user': user})
    if  res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)
Beispiel #5
0
def cms_das_json(query):
    """
    cmssh command which queries DAS data-service with provided query and
    returns results in JSON data format
    Examples:
        cmssh> das_json dataset=/ZMM*
    """
    host = 'https://cmsweb.cern.ch'
    idx = 0
    limit = 0
    debug = 0
    res = das_client(host, query, idx, limit, debug, 'json')
    RESMGR.assign([res])
    pprint.pprint(res)
Beispiel #6
0
def cms_das_json(query):
    """
    cmssh command which queries DAS data-service with provided query and
    returns results in JSON data format
    Examples:
        cmssh> das_json dataset=/ZMM*
    """
    host  = 'https://cmsweb.cern.ch'
    idx   = 0
    limit = 0
    debug = 0
    res   = das_client(host, query, idx, limit, debug, 'json')
    RESMGR.assign([res])
    pprint.pprint(res)
Beispiel #7
0
def lookup(arg):
    """
    Perform lookup of given query in CMS data-services.
    """
    arg = arg.strip()
    debug = get_ipython().debug
    args = arg.split('|')
    if len(args) == 1:  # no filter
        res = CMSMGR.lookup(arg)
    else:
        gen = CMSMGR.lookup(args[0].strip())
        for flt in args[1:]:
            res = apply_filter(flt.strip(), gen)
    RESMGR.assign(res)
    list_results(res, debug)
Beispiel #8
0
def lookup(arg):
    """
    Perform lookup of given query in CMS data-services.
    """
    arg = arg.strip()
    debug = get_ipython().debug
    args  = arg.split('|')
    if  len(args) == 1: # no filter
        res = CMSMGR.lookup(arg)
    else:
        gen = CMSMGR.lookup(args[0].strip())
        for flt in args[1:]:
            res = apply_filter(flt.strip(), gen)
    RESMGR.assign(res)
    list_results(res, debug)
Beispiel #9
0
def cms_releases(arg=None):
    """
    List available CMS releases. Optional parameters either <list> or <all>
    Examples:
        cmssh> releases      # show installed CMSSW releases
        cmssh> releases list # list available CMSSW releases on given platform
        cmssh> releases all  # show all known CMS releases, including online, tests, etc.
    """
    if arg:
        print "CMSSW releases for %s platform" % platform()
        res = release_info(release=None, rfilter=arg)
        RESMGR.assign(res)
        releases = [str(r) for r in res]
        releases = list(set(releases))
        releases.sort()
        for rel in releases:
            print rel
    installed_releases()
Beispiel #10
0
def cms_releases(arg=None):
    """
    List available CMS releases. Optional parameters either <list> or <all>
    Examples:
        cmssh> releases      # show installed CMSSW releases
        cmssh> releases list # list available CMSSW releases on given platform
        cmssh> releases all  # show all known CMS releases, including online, tests, etc.
    """
    if  arg:
        print "CMSSW releases for %s platform" % platform()
        res = release_info(release=None, rfilter=arg)
        RESMGR.assign(res)
        releases = [str(r) for r in res]
        releases = list(set(releases))
        releases.sort()
        for rel in releases:
            print rel
    installed_releases()
Beispiel #11
0
def cms_ls(arg):
    """
    cmssh ls command lists local files/dirs/CMS storate elements or
    CMS entities (se, site, dataset, block, run, release, file).
    Examples:
        cmssh> ls # UNIX command
        cmssh> ls -l local_file
        cmssh> ls T3_US_Cornell:/store/user/valya
        cmssh> ls run=160915
    """
    arg = arg.strip()
    res = []
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    startswith = None
    entities = \
        ['se', 'site', 'lfn', 'dataset', 'block', 'run', 'release', 'file']
    for item in entities:
        if arg.startswith(item + '='):
            startswith = item
    if os.path.isfile(orig_arg) or os.path.isdir(orig_arg):
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    elif pat_se.match(arg):
        arg = arg.replace('site=', '')
        res = list_se(arg, debug)
    elif pat_site.match(arg):
        arg = arg.replace('site=', '')
        res = site_info(arg, debug)
    elif pat_lfn.match(arg):
        arg = arg.replace('file=', '')
        arg = arg.replace('lfn=', '')
        res = file_info(arg, debug)
    elif pat_block.match(arg):
        arg = arg.replace('block=', '')
        res = block_info(arg, debug)
    elif pat_dataset.match(arg):
        arg = arg.replace('dataset=', '')
        try:
            res = dataset_info(arg, debug)
        except IndexError:
            msg = "Given pattern '%s' does not exist on local filesystem or in DBS" % arg
            print_error(msg)
    elif pat_run.match(arg):
        arg = arg.replace('run=', '')
        res = run_info(arg, debug)
    elif pat_release.match(arg):
        arg = arg.replace('release=', '')
        res = release_info(arg, debug)
    elif startswith:
        msg = 'No pattern is allowed for %s look-up' % startswith
        print_error(msg)
    else:
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    if res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)
Beispiel #12
0
def cms_ls(arg):
    """
    cmssh ls command lists local files/dirs/CMS storate elements or
    CMS entities (se, site, dataset, block, run, release, file).
    Examples:
        cmssh> ls # UNIX command
        cmssh> ls -l local_file
        cmssh> ls T3_US_Cornell:/store/user/valya
        cmssh> ls run=160915
    """
    arg = arg.strip()
    res = []
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if  orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    startswith = None
    entities = \
        ['se', 'site', 'lfn', 'dataset', 'block', 'run', 'release', 'file']
    for item in entities:
        if  arg.startswith(item + '='):
            startswith = item
    if  os.path.isfile(orig_arg) or os.path.isdir(orig_arg):
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    elif pat_se.match(arg):
        arg = arg.replace('site=', '')
        res = list_se(arg, debug)
    elif  pat_site.match(arg):
        arg = arg.replace('site=', '')
        res = site_info(arg, debug)
    elif pat_lfn.match(arg):
        arg = arg.replace('file=', '')
        arg = arg.replace('lfn=', '')
        res = file_info(arg, debug)
    elif pat_block.match(arg):
        arg = arg.replace('block=', '')
        res = block_info(arg, debug)
    elif pat_dataset.match(arg):
        arg = arg.replace('dataset=', '')
        try:
            res = dataset_info(arg, debug)
        except IndexError:
            msg = "Given pattern '%s' does not exist on local filesystem or in DBS" % arg
            print_error(msg)
    elif pat_run.match(arg):
        arg = arg.replace('run=', '')
        res = run_info(arg, debug)
    elif pat_release.match(arg):
        arg = arg.replace('release=', '')
        res = release_info(arg, debug)
    elif startswith:
        msg = 'No pattern is allowed for %s look-up' % startswith
        print_error(msg)
    else:
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    if  res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)