本文整理汇总了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)