本文整理汇总了Python中wheel.util.open_for_csv方法的典型用法代码示例。如果您正苦于以下问题:Python util.open_for_csv方法的具体用法?Python util.open_for_csv怎么用?Python util.open_for_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wheel.util
的用法示例。
在下文中一共展示了util.open_for_csv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_record
# 需要导入模块: from wheel import util [as 别名]
# 或者: from wheel.util import open_for_csv [as 别名]
def write_record(self, bdist_dir, distinfo_dir):
from wheel.util import urlsafe_b64encode
record_path = os.path.join(distinfo_dir, "RECORD")
record_relpath = os.path.relpath(record_path, bdist_dir)
def walk():
for dir, dirs, files in os.walk(bdist_dir):
dirs.sort()
for f in sorted(files):
yield os.path.join(dir, f)
def skip(path):
"""Wheel hashes every possible file."""
return path == record_relpath
with open_for_csv(record_path, "w+") as record_file:
writer = csv.writer(record_file)
for path in walk():
relpath = os.path.relpath(path, bdist_dir)
if skip(relpath):
hash = ""
size = ""
else:
with open(path, "rb") as f:
data = f.read()
digest = hashlib.sha256(data).digest()
hash = "sha256=" + native(urlsafe_b64encode(digest))
size = len(data)
record_path = os.path.relpath(path, bdist_dir).replace(os.path.sep, "/")
writer.writerow((record_path, hash, size))
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------