本文整理汇总了Python中index.Index.md5_to_archive[md5]方法的典型用法代码示例。如果您正苦于以下问题:Python Index.md5_to_archive[md5]方法的具体用法?Python Index.md5_to_archive[md5]怎么用?Python Index.md5_to_archive[md5]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类index.Index
的用法示例。
在下文中一共展示了Index.md5_to_archive[md5]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: from index import Index [as 别名]
# 或者: from index.Index import md5_to_archive[md5] [as 别名]
staging_dir = os.path.join(temp_dir, 'staging')
os.makedirs(staging_dir)
# Filenames
now_string = datetime.datetime.today().strftime('%Y%m%d_%H%M')
tar_name = '%s.tar.bz2' % now_string
archive_name = '%s.enc' % tar_name
# Copy needed files
file_count = 0
for file, md5 in index.path_to_md5.items():
if md5 not in index.md5_to_archive:
file_count = file_count + 1
# Record that this hash is in this archive
index.md5_to_archive[md5] = archive_name
# Copy the file
dir = os.path.join(staging_dir, md5[0:2], md5[2:4])
if not os.path.isdir(dir):
os.makedirs(dir)
shutil.copyfile(os.path.join(source_dir, file), os.path.join(dir, md5))
index.write(os.path.join(staging_dir, '%s.backrypt' % now_string))
if file_count == 0:
shutil.rmtree(temp_dir)
print('No new or modified files to backup since last backup')
sys.exit(0)
# Tar up staging_dir to os.path.join(temp_dir, tgz_name)
tar_path = os.path.join(temp_dir, tar_name)