本文整理汇总了Python中fsgs.FSGSDirectories.FSGSDirectories.images_dir_for_sha1方法的典型用法代码示例。如果您正苦于以下问题:Python FSGSDirectories.images_dir_for_sha1方法的具体用法?Python FSGSDirectories.images_dir_for_sha1怎么用?Python FSGSDirectories.images_dir_for_sha1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fsgs.FSGSDirectories.FSGSDirectories
的用法示例。
在下文中一共展示了FSGSDirectories.images_dir_for_sha1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_file_for_sha1_cached
# 需要导入模块: from fsgs.FSGSDirectories import FSGSDirectories [as 别名]
# 或者: from fsgs.FSGSDirectories.FSGSDirectories import images_dir_for_sha1 [as 别名]
def get_file_for_sha1_cached(sha1, size_arg, cache_ext):
cache_zip = get_cache_zip_for_sha1(sha1)
if cache_zip is not None:
try:
return cache_zip.open("{}/{}{}".format(
sha1[:2], sha1, cache_ext))
except KeyError:
pass
cache_dir = FSGSDirectories.images_dir_for_sha1(sha1)
cache_file = os.path.join(cache_dir, sha1 + cache_ext)
if os.path.exists(cache_file):
# An old bug made it possible for 0-byte files to exist, so
# we check for that here...
if os.path.getsize(cache_file) > 0:
return cache_file
url = "{}/image/{}{}".format(openretro_url_prefix(), sha1, size_arg)
print("[IMAGES]", url)
r = urlopen(url)
data = r.read()
cache_file_partial = "{}.{}.partial".format(
cache_file, str(uuid4())[:8])
if not os.path.exists(os.path.dirname(cache_file_partial)):
os.makedirs(os.path.dirname(cache_file_partial))
with open(cache_file_partial, "wb") as f:
f.write(data)
os.rename(cache_file_partial, cache_file)
return cache_file