Exemple #1
0
def file_info(lfn, verbose=None):
    query = 'find file.name, file.numevents, file.size, file.createdate, file.createby, file.moddate, file.modby where file=%s' % lfn
    params = {"api": "executeQuery", "apiversion": "DBS_2_0_9", "query": query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        os.environ['DBS_INSTANCE'] = inst
        data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'file')][0]
        except:
            continue
        rec['logical_file_name'] = rec['file']['file.name']
        rec['size'] = rec['file']['file.size']
        rec['nevents'] = rec['file']['file.numevents']
        rec['created'] = time.strftime(
            "%Y-%m-%d %H:%M:%S GMT",
            time.gmtime(rec['file']['file.createdate']))
        rec['createdby'] = rec['file']['file.createby']
        rec['modified'] = time.strftime(
            "%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.moddate']))
        rec['modifiedby'] = rec['file']['file.modby']
        del rec['file']
        lfnobj = File(rec)
        try:
            pfnlist, selist = get_pfns(lfn, verbose)
            if not selist:
                query = 'find site where file=%s' % lfn
                params.update({"query": query})
                data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
                try:
                    rec = [f for f in qlxml_parser(data, 'site')][0]
                    sename = rec['site']['site']
                    selist = [sename]
                    pfnlist = lfn2pfn(lfn, sename)
                except:
                    pass
            lfnobj.assign('pfn', pfnlist)
            lfnobj.assign('se', selist)
        except:
            traceback.print_exc()
            lfnobj.assign('pfn', [])
            lfnobj.assign('se', [])
        os.environ['DBS_INSTANCE'] = default_instance
        lfnobj.assign('dbs_instance', inst)
        return lfnobj
    os.environ['DBS_INSTANCE'] = default_instance
    msg = 'Fail to look-up LFN in %s DBS instances' % dbs_instances()
    print_error(msg)
Exemple #2
0
def file_info(lfn, verbose=None):
    query  = 'find file.name, file.numevents, file.size, file.createdate, file.createby, file.moddate, file.modby where file=%s' % lfn
    params = {"api":"executeQuery", "apiversion": "DBS_2_0_9", "query":query}
    default_instance = os.environ.get('DBS_INSTANCE')
    for inst in dbs_instances():
        os.environ['DBS_INSTANCE'] = inst
        data   = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
        try:
            rec = [f for f in qlxml_parser(data, 'file')][0]
        except:
            continue
        rec['logical_file_name'] = rec['file']['file.name']
        rec['size'] = rec['file']['file.size']
        rec['nevents'] = rec['file']['file.numevents']
        rec['created'] = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.createdate']))
        rec['createdby'] = rec['file']['file.createby']
        rec['modified'] = time.strftime("%Y-%m-%d %H:%M:%S GMT", time.gmtime(rec['file']['file.moddate']))
        rec['modifiedby'] = rec['file']['file.modby']
        del rec['file']
        lfnobj = File(rec)
        try:
            pfnlist, selist = get_pfns(lfn, verbose)
            if  not selist:
                query = 'find site where file=%s' % lfn
                params.update({"query":query})
                data  = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
                try:
                    rec = [f for f in qlxml_parser(data, 'site')][0]
                    sename = rec['site']['site']
                    selist = [sename]
                    pfnlist = lfn2pfn(lfn, sename)
                except:
                    pass
            lfnobj.assign('pfn', pfnlist)
            lfnobj.assign('se', selist)
        except:
            traceback.print_exc()
            lfnobj.assign('pfn', [])
            lfnobj.assign('se', [])
        os.environ['DBS_INSTANCE'] = default_instance
        lfnobj.assign('dbs_instance', inst)
        return lfnobj
    os.environ['DBS_INSTANCE'] = default_instance
    msg = 'Fail to look-up LFN in %s DBS instances' % dbs_instances()
    print_error(msg)
Exemple #3
0
def file_info(lfn, verbose=None):
    """Return file info"""
    url = dbs_url()
    if url.find("cmsdbsprod") != -1:  # DBS2
        return dbs2.file_info(lfn, verbose)
    params = {"logical_file_name": lfn, "detail": "True"}
    result = get_data(dbs_url("files"), params, verbose)
    res = [File(r) for r in result]
    if len(res) != 1:
        msg = "The %s LFN yield %s results" % (lfn, len(res))
        raise Exception(msg)
    lfnobj = res[0]
    try:
        pfnlist, selist = get_pfns(lfn, verbose)
        lfnobj.assign("pfn", pfnlist)
        lfnobj.assign("se", selist)
    except:
        lfnobj.assign("pfn", [])
        lfnobj.assign("se", [])
    return lfnobj
Exemple #4
0
def file_info(lfn, verbose=None):
    """Return file info"""
    url = dbs_url()
    if url.find('cmsdbsprod') != -1:  # DBS2
        return dbs2.file_info(lfn, verbose)
    params = {'logical_file_name': lfn, 'detail': 'True'}
    result = get_data(dbs_url('files'), params, verbose)
    res = [File(r) for r in result]
    if len(res) != 1:
        msg = 'The %s LFN yield %s results' % (lfn, len(res))
        raise Exception(msg)
    lfnobj = res[0]
    try:
        pfnlist, selist = get_pfns(lfn, verbose)
        lfnobj.assign('pfn', pfnlist)
        lfnobj.assign('se', selist)
    except:
        lfnobj.assign('pfn', [])
        lfnobj.assign('se', [])
    return lfnobj
Exemple #5
0
def file_info(lfn, verbose=None):
    """Return file info"""
    url = dbs_url()
    if  url.find('cmsdbsprod') != -1: # DBS2
        return dbs2.file_info(lfn, verbose)
    params = {'logical_file_name': lfn, 'detail':'True'}
    result = get_data(dbs_url('files'), params, verbose)
    res = [File(r) for r in result]
    if  len(res) != 1:
        msg  = 'The %s LFN yield %s results' % (lfn, len(res))
        raise Exception(msg)
    lfnobj = res[0]
    try:
        pfnlist, selist = get_pfns(lfn, verbose)
        lfnobj.assign('pfn', pfnlist)
        lfnobj.assign('se', selist)
    except:
        lfnobj.assign('pfn', [])
        lfnobj.assign('se', [])
    return lfnobj