代码拉取完成,页面将自动刷新
同步操作将从 ShiboJiang/toto 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# Function : This scrip is used to creat sl_customization.m with all .m files
# Enviroment : python 3
# Author : Shibo Jiang
# Time : 2018.3.23
# Version : 0.1
# Notes : None
#------------------------------------------------------------------------------
import os
# Start of find_files function-------------------------------------------------
def find_files(path, search, default_result, exclude = None):
for x_path in os.listdir(path):
if x_path != exclude:
x_path = os.path.join(path, x_path)
if os.path.isdir(x_path):
find_files(x_path, search, default_result, exclude = None)
elif (os.path.splitext(x_path)[1]).lower() == search:
default_result.append(x_path)
# End of find_files function---------------------------------------------------
# Start of main function-------------------------------------------------------
def main():
# Config constant value
MAIN_FILE = 'sl_customization.m'
TARGET_FILE = 'sl_customization_all.m'
PWD_PATH = os.path.abspath('.')
# Delete exit target files
if TARGET_FILE in os.listdir(PWD_PATH):
delete_file = os.path.join(PWD_PATH,TARGET_FILE)
os.remove(delete_file)
# Parameters
m_files = [os.path.join(PWD_PATH, MAIN_FILE)]
find_files(PWD_PATH, '.m', m_files)
# Copy files content
done_file = []
repeat_file = []
with open(TARGET_FILE, 'w', encoding='gbk') as tar_file:
for x_file in m_files:
# Judge whether file is repeat
if not x_file in done_file:
# Read file's content
with open(x_file, 'r', encoding='gbk') as src_file:
while True:
content = src_file.readline()
# Write content to target file
tar_file.write(content)
if not content:
tar_file.write('\n'+'\n')
break
# Add file's name to done_file which already copied
done_file.append(x_file)
print(str(os.path.split(x_file)[1]) + ' --already copied!')
else:
if str(os.path.split(x_file)[1]) != MAIN_FILE:
repeat_file.append(x_file)
# Report repeat files
print('These files are repeated:' + str(repeat_file))
# End of main function---------------------------------------------------------
# Run script
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。