Exemplo n.º 1
0
def cms_rm(arg):
    """
    CMS rm command works with local files/dirs and CMS storate elements.
    Examples:
        cmssh> rm local_file
        cmssh> rm -rf local_dir
        cmssh> rm T3_US_Cornell:/xrootdfs/cms/store/user/user_name/file.root
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if not arg:
        print_error("Usage: rm <options> source_file")
    dst = arg.split()[-1]
    if os.path.exists(dst) or len(glob.glob(dst)):
        cmd = "rm %s" % arg
        run(cmd)
    else:
        if pat_lfn.match(arg.split(':')[-1]):
            status = rm_lfn(arg, verbose=debug)
            print_status(status)
        else:
            if not os.path.exists(dst):
                print_error('File %s does not exists' % dst)
            else:
                raise Exception('Not implemented yet')
Exemplo n.º 2
0
def cms_rm(arg):
    """
    CMS rm command works with local files/dirs and CMS storate elements.
    Examples:
        cmssh> rm local_file
        cmssh> rm -rf local_dir
        cmssh> rm T3_US_Cornell:/xrootdfs/cms/store/user/user_name/file.root
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if  not arg:
        print_error("Usage: rm <options> source_file")
    dst = arg.split()[-1]
    if  os.path.exists(dst) or len(glob.glob(dst)):
        cmd = "rm %s" % arg
        run(cmd)
    else:
        if  pat_lfn.match(arg.split(':')[-1]):
            status = rm_lfn(arg, verbose=debug)
            print_status(status)
        else:
            if  not os.path.exists(dst):
                print_error('File %s does not exists' % dst)
            else:
                raise Exception('Not implemented yet')
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def cms_cp(arg):
    """
    cmssh cp command copies local files/dirs to/from local files/dirs or CMS storate elements.
    Examples:
        cmssh> cp file1 file2
        cmssh> cp file.root T3_US_Cornell:/store/user/name
        cmssh> cp /store/mc/file.root T3_US_Cornell:/store/user/name
        cmssh> cp T3_US_Cornell:/store/user/name/file.root T3_US_Omaha
    """
    check_voms_proxy()
    background = False
    orig_arg = arg
    arg = arg.strip()
    try:
        last_arg = arg.split(' ')[-1].strip()
        if last_arg == '&':
            background = True
            arg = arg.replace('&', '').strip()
        src, dst = arg.rsplit(' ', 1)
        if dst.find('&') != -1:
            background = True
            dst = dst.replace('&', '').strip()
        if dst == '.':
            dst = os.getcwd()
        # check if src still has options and user asked for -f
        options = src.split(' ')
        if len(options) > 1 and options[0] == '-f':
            overwrite = True
        else:
            overwrite = False
    except:
        traceback.print_exc()
        return
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if not arg:
        print_error("Usage: cp <options> source_file target_{file,directory}")
    pat = pat_se
    orig = src.split(' ')[-1]
    if os.path.exists(orig) and not pat.match(dst):
        if background:
            cmd = 'cp %s' % orig_arg
            subprocess.call(cmd, shell=True)
        else:
            run("cp %s %s" % (src, dst))
    else:
        try:
            status = copy_lfn(orig, dst, debug, background, overwrite)
            print_status(status)
        except:
            traceback.print_exc()
Exemplo n.º 6
0
def cms_cp(arg):
    """
    cmssh cp command copies local files/dirs to/from local files/dirs or CMS storate elements.
    Examples:
        cmssh> cp file1 file2
        cmssh> cp file.root T3_US_Cornell:/store/user/name
        cmssh> cp /store/mc/file.root T3_US_Cornell:/store/user/name
        cmssh> cp T3_US_Cornell:/store/user/name/file.root T3_US_Omaha
    """
    check_voms_proxy()
    background = False
    orig_arg = arg
    arg = arg.strip()
    try:
        last_arg = arg.split(' ')[-1].strip()
        if  last_arg == '&':
            background = True
            arg = arg.replace('&', '').strip()
        src, dst = arg.rsplit(' ', 1)
        if  dst.find('&') != -1:
            background = True
            dst = dst.replace('&', '').strip()
        if  dst == '.':
            dst = os.getcwd()
        # check if src still has options and user asked for -f
        options = src.split(' ')
        if  len(options) > 1 and options[0] == '-f':
            overwrite = True
        else:
            overwrite = False
    except:
        traceback.print_exc()
        return
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if  not arg:
        print_error("Usage: cp <options> source_file target_{file,directory}")
    pat  = pat_se
    orig = src.split(' ')[-1]
    if  os.path.exists(orig) and not pat.match(dst):
        if  background:
            cmd = 'cp %s' % orig_arg
            subprocess.call(cmd, shell=True)
        else:
            run("cp %s %s" % (src, dst))
    else:
        try:
            status = copy_lfn(orig, dst, debug, background, overwrite)
            print_status(status)
        except:
            traceback.print_exc()
Exemplo n.º 7
0
def cms_mkdir(arg):
    """
    cmssh mkdir command creates directory on local filesystem or remote CMS storage element.
    Examples:
        cmssh> mkdir foo
        cmssh> mkdir T3_US_Cornell:/store/user/user_name/foo
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if not arg:
        print_error("Usage: mkdir <options> dir")
    if arg.find(':') == -1:  # not a SE:dir pattern
        run("mkdir %s" % arg)
    else:
        try:
            status = mkdir(arg, verbose=debug)
            print_status(status)
        except:
            traceback.print_exc()
Exemplo n.º 8
0
def cms_rmdir(arg):
    """
    cmssh rmdir command removes directory from local file system or CMS storage element.
    Examples:
        cmssh> rmdir foo
        cmssh> rmdir T3_US_Cornell:/store/user/user_name/foo
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if not arg:
        print_error("Usage: rmdir <options> dir")
    if os.path.exists(arg):
        run("rmdir %s" % arg)
    else:
        try:
            status = rmdir(arg, verbose=debug)
            print_status(status)
        except:
            traceback.print_exc()
Exemplo n.º 9
0
def cms_mkdir(arg):
    """
    cmssh mkdir command creates directory on local filesystem or remote CMS storage element.
    Examples:
        cmssh> mkdir foo
        cmssh> mkdir T3_US_Cornell:/store/user/user_name/foo
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if  not arg:
        print_error("Usage: mkdir <options> dir")
    if  arg.find(':') == -1: # not a SE:dir pattern
        run("mkdir %s" % arg)
    else:
        try:
            status = mkdir(arg, verbose=debug)
            print_status(status)
        except:
            traceback.print_exc()
Exemplo n.º 10
0
def cms_rmdir(arg):
    """
    cmssh rmdir command removes directory from local file system or CMS storage element.
    Examples:
        cmssh> rmdir foo
        cmssh> rmdir T3_US_Cornell:/store/user/user_name/foo
    """
    arg = arg.strip()
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    if  not arg:
        print_error("Usage: rmdir <options> dir")
    if  os.path.exists(arg):
        run("rmdir %s" % arg)
    else:
        try:
            status = rmdir(arg, verbose=debug)
            print_status(status)
        except:
            traceback.print_exc()