當前位置: 首頁>>代碼示例>>Python>>正文


Python DCC.file_download方法代碼示例

本文整理匯總了Python中DCC.file_download方法的典型用法代碼示例。如果您正苦於以下問題:Python DCC.file_download方法的具體用法?Python DCC.file_download怎麽用?Python DCC.file_download使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DCC的用法示例。


在下文中一共展示了DCC.file_download方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: traverse

# 需要導入模塊: import DCC [as 別名]
# 或者: from DCC import file_download [as 別名]
def traverse(s, tr, collkey, dirpath = './', indent = '', **kwargs):
    # traverse follows the collection structure on the DCC and replicates it on the local disk
    pflag = False
    savefiles = kwargs.get('SaveFiles', False)
    exclude = kwargs.get('Exclude', [])        
    maxfilesize = kwargs.get('MaxFileSize', sys.maxsize)
        
    branch = tr[collkey]
    collist = branch['collections']
    doclist = branch['documents']
        
    cinfo = DCC.prop_get(s, collkey, InfoSet = 'CollData')
    print(indent,'Files in ', collkey, ': ', cinfo['title'])
    colname = cinfo['title']
    colname = colname.replace('/',' ')
    dirpath = dirpath + colname + '/' 
    if savefiles:
        try:
            os.stat(dirpath)
        except:
            os.mkdir(dirpath) 
    for doc in doclist:
        finfo = DCC.prop_get(s, doc, InfoSet = 'DocBasic')
        print(indent + '\t',doc)
        print(indent + '\t\tTitle: ',finfo['title'])
        print(indent + '\t\tFileName: ',finfo['filename'],' [',finfo['date'],']' ,' [', finfo['size'],' bytes ]')
        filedirpath = dirpath + finfo.get('title').replace('/',' ') + '/'
        filename = finfo.get('filename')
        if savefiles:
            try:
                os.stat(filedirpath)
            except:
                os.mkdir(filedirpath)
        if not os.path.isfile(filedirpath+filename):
            print(indent + "\t\t\tFile doesn't exist")
            if savefiles:
                if finfo['size'] < maxfilesize:
                    print(indent + "\t\t\tGetting file")
                    DCC.file_download(s, doc, filedirpath, finfo['filename'])
                else:
                    print(indent + "\t\t\tFile size exceeds MaxFileSize of ", maxfilesize, "bytes")
            else:
                print(indent + "\t\t\tSaveFiles is False, so file will not be downloaded")


        elif (datetime.strptime(finfo['date'],'%a, %d %b %Y %H:%M:%S %Z') - datetime(1970,1,1)).total_seconds() > os.path.getctime(filedirpath+filename):
            print(indent + "\t\t\tFile exists, but is out of date:", time.ctime(os.path.getctime(filedirpath+filename)))
            if savefiles:
                if finfo['size'] < maxfilesize:
                    print(indent + "\t\t\tGetting updated file")
                    DCC.file_download(s, doc, filedirpath, finfo['filename'])
                else:
                    print(indent + "\t\t\tFile size exceeds MaxFileSize of ", maxfilesize, "bytes")
            else:
                print(indent + "\t\t\tSaveFiles is False, so file will not be downloaded")
        else:
            print(indent + "\t\t\tFile exists, created:", time.ctime(os.path.getctime(filedirpath+filename)))

    for c in collist:
        if (not c == collkey) and (not c in exclude):
            traverse(s, tr, c, dirpath, indent + '\t', **kwargs)
開發者ID:pbbarnes,項目名稱:Library1,代碼行數:63,代碼來源:FileSys.py


注:本文中的DCC.file_download方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。