#!/usr/bin/env python
# -*- coding: utf_8 -*-
import os
import shutil
import logging
from logging.handlers import RotatingFileHandler
logPath = os.getcwd() + os.path.sep + "logs"
if not os.path.exists(logPath):
os.makedirs(logPath)
fh = RotatingFileHandler("showcase.log", maxBytes=10 * 1024 * 1024, backupCount=100)
fh.setLevel(logging.DEBUG)
#log write in console
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
#log formatter
formatter = logging.Formatter(
'%(asctime)s %(levelname)8s [%(filename)25s%(funcName)20s%(lineno)06s] %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger = logging.root
logger.setLevel(logging.INFO)
logger.addHandler(fh)
logger.addHandler(ch)
def copydirs(from_file, to_file):
if not os.path.exists(to_file): # 如不存在目标目录则创建
os.makedirs(to_file)
files = os.listdir(from_file) # 获取文件夹中文件和目录列表
for f in files:
if os.path.isdir(from_file + os.sep + f): # 判断是否是文件夹
copydirs(from_file + os.sep + f, to_file + os.sep + f) # 递归调用本函数
else:
shutil.copy(from_file + os.sep + f, to_file + os.sep + f) # 拷贝文件
def rmdirs(dirpath):
if os.path.exists(dirpath):
files = os.listdir(dirpath)
for file in files:
filepath = os.path.join(dirpath, file).replace("\\",'/')
if os.path.isdir(filepath):
rmdirs(filepath)
else:
os.remove(filepath)
os.rmdir(dirpath)
def generateProjects(path):
'''
获取指定path下的所有文件列表
'''
ignore_dir = ['.git']
templateDir = os.sep.join([os.getcwd(), "helloworld"])
files = []
for dirpath, dirnames, filenames in os.walk(path):
for d in ignore_dir:
# print(dirpath)
# print(os.sep.join([os.getcwd(), d]))
# print(dirpath.startswith(os.sep.join([os.getcwd(), d])))
if dirpath.startswith(os.sep.join([os.getcwd(), d])):
continue
# print(dirpath, dirnames, filenames)
if filenames == ['index.css', 'index.hml', 'index.js']:
# componentID = "%s-%s" % os.path.basename(dirpath)
pathkeys = dirpath.split(os.sep)
if 'component' in dirpath:
index = pathkeys.index('component')
projectName = "showcase-%s" % "-".join(pathkeys[index+1:])
else:
index = pathkeys.index('examples')
projectName = pathkeys[index+1]
if projectName == "showcase":
projectName = "showcase-index"
#创建目录
projectDir = os.sep.join([os.getcwd(), projectName])
if os.path.exists(projectDir):
rmdirs(projectDir)
if not os.path.isdir(projectDir):
os.makedirs(projectDir)
logger.info("generate project [%s]-[%s]" % (projectName, projectDir))
copydirs(templateDir , projectDir)
defaultDir = os.sep.join(pathkeys[0:pathkeys.index('default')+1])
projectDir = os.sep.join([projectDir, "entry", "src", "main", "js","default"])
if os.path.exists(defaultDir):
copydirs(defaultDir , projectDir)
rmdirs(os.sep.join([projectDir, "pages"]))
projectPageDir = os.sep.join([projectDir, "pages"])
if os.path.exists(projectPageDir):
rmdirs(projectPageDir)
os.makedirs(projectPageDir)
projectIndexDir = os.sep.join([projectPageDir, "index"])
if os.path.exists(projectIndexDir):
rmdirs(projectIndexDir)
# 拷贝源文件index.hml index.css index.js
# indexDir = os.sep.join([projectDir, "entry", "src", "main", "js","default","pages","index"])
os.makedirs(projectIndexDir)
copydirs(dirpath , projectIndexDir)
indexFile = os.sep.join([projectIndexDir, "index.js"])
with open(indexFile, "r") as f:
content = str(f.read())
isReWrite = False
if "../../../../../common/js/general" in content:
content = content.replace("../../../../../common/js/general", "../../common/js/general")
isReWrite = True
elif "../../../../common/js/general" in content:
content = content.replace("../../../../common/js/general", "../../common/js/general")
isReWrite = True
elif "../../../common/js/general" in content:
content = content.replace("../../../common/js/general", "../../common/js/general")
isReWrite = True
if isReWrite:
with open(indexFile, "w") as f:
f.write(content)
def main():
generateProjects(os.sep.join([os.getcwd(), "examples"]))
if __name__ == '__main__':
main()
没有合适的资源?快使用搜索试试~ 我知道了~
VM超轻量物联网虚拟机团队 针对鸿蒙OS的深度研究.zip
共2000个文件
js:1219个
css:300个
xml:235个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 32 浏览量
2024-02-07
11:58:48
上传
评论
收藏 9.1MB ZIP 举报
温馨提示
华为 鸿蒙系统 开发
资源推荐
资源详情
资源评论
收起资源包目录
VM超轻量物联网虚拟机团队 针对鸿蒙OS的深度研究.zip (2000个子文件)
index.css 3KB
index.css 3KB
style.css 3KB
style.css 2KB
style.css 2KB
style.css 2KB
commonStyle.css 2KB
commonStyle.css 2KB
event.css 2KB
event.css 2KB
style.css 2KB
style.css 2KB
attr.css 2KB
edit_alarm.css 2KB
attr.css 2KB
attr.css 2KB
attr.css 2KB
event.css 2KB
event.css 2KB
attr.css 2KB
event.css 2KB
event.css 2KB
attr.css 2KB
event.css 1KB
event.css 1KB
animation5.css 1KB
index.css 1KB
index.css 1KB
attr.css 1KB
specStyle.css 1KB
specStyle.css 1KB
attr.css 1KB
animation4.css 1KB
animation3.css 1KB
animation7.css 1KB
index.css 1KB
index.css 1KB
animation1.css 1KB
animation6.css 1KB
animation2.css 1KB
index.css 983B
index.css 983B
index.css 981B
index.css 981B
index.css 981B
index.css 981B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
index.css 980B
detail.css 978B
index.css 938B
index.css 938B
history.css 892B
image4.css 875B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
博士僧小星
- 粉丝: 1945
- 资源: 5903
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Servlet和JDBC实现三层架构
- Appium-Inspector-2024.6.1-win
- Screenshot_2024-06-14-21-22-39-202_net.csdn.csdnplus.jpg
- Appium-Server-GUI-windows-1.22.3-4
- 基于C语言+python实现的永磁同步电机矢量控制算法仿真+源码(毕业设计&课程设计&项目开发)
- APKPure_v3.20.05_apkpure.com.apk
- HKJC_AOSBS_PROD_L2.7R2Q_Build8172.apk
- jetson官网下载的官方资料
- 小游戏的java程序开发
- matlab GUI仿真资源.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功