forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_project.py
More file actions
52 lines (39 loc) · 1.3 KB
/
create_project.py
File metadata and controls
52 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on 2018-08-28 17:38:43
---------
@summary: 创建项目
---------
@author: Boris
@email: boris_liu@foxmail.com
"""
import getpass
import os
import shutil
import feapder.utils.tools as tools
def deal_file_info(file):
file = file.replace("{DATE}", tools.get_current_date())
file = file.replace("{USER}", getpass.getuser())
return file
class CreateProject:
def copy_callback(self, src, dst, *, follow_symlinks=True):
if src.endswith(".py"):
with open(src, "r", encoding="utf-8") as src_file, open(
dst, "w", encoding="utf8"
) as dst_file:
content = src_file.read()
content = deal_file_info(content)
dst_file.write(content)
else:
shutil.copy2(src, dst, follow_symlinks=follow_symlinks)
def create(self, project_name):
if os.path.exists(project_name):
print("%s 项目已经存在" % project_name)
else:
template_path = os.path.abspath(
os.path.join(__file__, "../../../templates/project_template")
)
shutil.copytree(
template_path, project_name, copy_function=self.copy_callback
)
print("\n%s 项目生成成功" % project_name)