本文整理匯總了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)