120 Star 519 Fork 285

GVPOneOS/OneOS

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
generate.py 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
likefei 提交于 2022-11-18 19:51 +08:00 . first merge yaml
import os
import sys
import shutil
import importlib
import importlib.util
import time
import re
from print_helper import print_debug, print_info, print_warn, print_error
def find_soc(src, soc):
soc_dir = [os.path.basename(src)]
#soc_dir = ['hk32-common', 'replace', 'HK32F030', 'replace', 'TEMP_HK32F030CBT6']
names = os.listdir(src)
for name in names:
if name == soc:
soc_dir.append(name)
#tools.print_debug(soc_dir)
return soc_dir
srcname = os.path.join(src, name)
if not os.path.isdir(srcname):
continue
sub_soc_dir = find_soc(srcname, soc)
if len(sub_soc_dir) > 1:
soc_dir.extend(sub_soc_dir)
#tools.print_debug(soc_dir)
return soc_dir
#tools.print_debug(soc_dir)
return soc_dir
def copytree(src, dst, ignore, symlinks=False):
names = os.listdir(src)
if not os.path.isdir(dst):
os.makedirs(dst)
errors = []
for name in names:
if isinstance(ignore, list):
if name in ignore:
continue
elif isinstance(ignore, str):
if name == ignore:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, ignore, symlinks)
else:
if os.path.isdir(dstname):
os.rmdir(dstname)
elif os.path.isfile(dstname):
os.remove(dstname)
shutil.copy2(srcname, dstname)
except (IOError, os.error) as why:
errors.append((srcname, dstname, str(why)))
except OSError as err:
errors.extend(err.args[0])
def template(source_path, g):
target_path = os.path.join(source_path, 'target')
for item in g:
if 'TEMP_' in item:
soc = item
print_info(source_path)
print_info(target_path)
print_info(soc)
if os.path.exists(target_path):
shutil.rmtree(target_path)
# find soc dir
soc_dir = find_soc(source_path, soc)
print_info("soc_dir")
print(soc_dir)
#soc_dir = ['hk32-common', 'replace', 'HK32F030', 'replace', 'TEMP_HK32F030CBT6']
if len(soc_dir) < 2:
print_warn("invalid soc_dir %s" % soc_dir)
return None
# copy replace files
replace_path = source_path
copytree(replace_path, target_path, ['replace', 'generate.py'])
for i in range(1, len(soc_dir)):
if i % 2 == 1 and soc_dir[i] != 'replace':
print_warn("invalid soc_dir %s\n"
"soc_dir[%d] is %s, expect 'replace'"
% (soc_dir, i, soc_dir[i]))
return None
replace_path = os.path.join(replace_path, soc_dir[i])
if soc_dir[i] == 'replace':
continue
copytree(replace_path, target_path, ['replace', 'generate.py'])
return target_path
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/cmcc-oneos/OneOS.git
git@gitee.com:cmcc-oneos/OneOS.git
cmcc-oneos
OneOS
OneOS
dev

搜索帮助