def overwrite(xxnet_version, xxnet_unzip_path):
progress["update_status"] = "Over writing"
try:
for root, subdirs, files in os.walk(xxnet_unzip_path):
relate_path = root[len(xxnet_unzip_path)+1:]
target_relate_path = relate_path
if sys.platform == 'win32':
if target_relate_path.startswith("code\\default"):
target_relate_path = "code\\" + xxnet_version + relate_path[12:]
else:
if target_relate_path.startswith("code/default"):
target_relate_path = "code/" + xxnet_version + relate_path[12:]
for subdir in subdirs:
if relate_path == "code" and subdir == "default":
subdir = xxnet_version
target_path = os.path.join(top_path, target_relate_path, subdir)
if not os.path.isdir(target_path):
xlog.info("mkdir %s", target_path)
os.mkdir(target_path)
for filename in files:
src_file = os.path.join(root, filename)
dst_file = os.path.join(top_path, target_relate_path, filename)
if not os.path.isfile(dst_file) or hash_file_sum(src_file) != hash_file_sum(dst_file):
xlog.info("copy %s => %s", src_file, dst_file)
if sys.platform != 'win32' and os.path.isfile(dst_file):
st = os.stat(dst_file)
shutil.copy(src_file, dst_file)
if st.st_mode & stat.S_IEXEC:
os.chmod(dst_file, st.st_mode)
else:
shutil.copy(src_file, dst_file)
except Exception as e:
xlog.warn("update over write fail:%r", e)
progress["update_status"] = "Over write Fail:%r" % e
raise e
xlog.info("update file finished.")
update_from_github.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录