Aestate
commad.py
Go to the documentation of this file.
1 # -*- utf-8 -*-
2 # encoding:utf-8
3 # @Time: 2021/6/27 20:47
4 # @Author: CACode
5 # 版本有三种状态 正式版从1.0.0往后逐个加 1,对应版本的补丁为'a+补丁次数'
6 __version__ = '1.0.4a4'
7 __description__ = "Aestate framework for Python,You can see:https://gitee.com/cacode_cctvadmin/aestate"
8 __author__ = "CACode"
9 __author_email__ = "cacode@163.com"
10 __url__ = "https://gitee.com/cacode_cctvadmin/aestate"
11 __license__ = 'Apache License 2.0'
12 __project_name__ = 'Aestate'
13 __logo__ = """
14  :: Aestate Framework :: (version:%s)
15  + __ _ _ __ +
16  + / / /\ | | | | \ \ +
17  + / / / \ ___ ___| |_ __ _| |_ ___ \ \ +
18  + | | / /\ \ / _ \/ __| __/ _` | __/ _ \ | | +
19  + \ \ / ____ \ __/\__ \ || (_| | || __/ / / +
20 ========\_\=/_/====\_\___||___/\__\__,_|\__\___|=/_/========
21 """ % __version__
22 
23 __log_logo__ = """
24  :: Aestate Framework :: (version:%s)
25  + __ _ _ __ +
26  + / / /\ | | | | \ \ +
27  + / / / \ ___ ___| |_ __ _| |_ ___ \ \ +
28  + | | / /\ \ / _ \/ __| __/ _` | __/ _ \ | | +
29  + \ \ / ____ \ __/\__ \ || (_| | || __/ / / +
30 ========\_\=/_/====\_\___||___/\__\__,_|\__\___|=/_/========
31 """ % __version__
32 
33 import importlib
34 
35 try:
36  from prettytable import PrettyTable
37 except ModuleNotFoundError as e:
38  print("请先安装 [prettytable] 再执行 [-h] 命令,使用 [pip install prettytable]")
39 
40 
41 class Commands:
42  def __init__(self, *args):
43  """
44  下面的@staticmethod主要是为了不想看见黄线警告,并没有其他意思
45  """
46  self.args = args
47  self.c = {
48  "": (
49  self.start,
50  '显示aestate的logo和版本号,用于检查aestate是否安装成功',
51  "aestate"
52  ),
53  "-v": (
54  self.version,
55  "显示aestate的版本号",
56  "aestate -v"
57  ),
58  "-create": (
59  self.create,
60  "将文件内存在pojo对象的类生成到数据库中称为数据库的表"
61  "数据库格式化类型参考默认的 [mysql] 格式",
62  'aestate -create [文件名] [数据库类型 (可选)]'
63  ),
64  "-m": (
65  self.make,
66  "将数据库中的表同步生成到当前目录下的 [model.py],并默认命名为 [数据库命_表名]",
67  'aestate -m [--n [生成的文件名 (可选) ]] [--nn [生成的类名 (可选)]]'
68  ),
69  "-enc": (
70  self.enc,
71  "加密模型",
72  'aestate -enc [密码]'
73  ),
74  "-dec": (
75  self.dec,
76  "解密模型",
77  'aestate -dec [被加密后的文件] [密码]'
78  ),
79  "-check": (
80  self.check,
81  "检查模型与数据库中的表结构是否一直",
82  'aestate -check [文件名] [数据库名]'
83  ),
84  "-h": (
85  self.help,
86  "帮助文档",
87  'aestate -h'
88  ),
89  "-startproject": (
90  self.startproject,
91  "创建一个web项目",
92  'aestate -startproject 项目名'
93  )
94  }
95 
96  def startproject(self):
97  pass
98 
99  def start(self):
100  print(__logo__)
101 
102  def create(self):
103  print(__logo__)
104  try:
105  file = self.args[2]
106  db_name = self.args[3]
107  except IndexError:
108  raise IndexError("为了保证数据库的sql执行顺利,请填写pojo存在的文件名和数据库名称")
109  import inspect
110  temp_module = importlib.import_module(file)
111 
112  temp_classes = inspect.getmembers(temp_module, inspect.isclass)
113  for name, class_ in temp_classes:
114  c = class_()
115  c.orm.create()
116 
117  def enc(self):
118  pass
119 
120  def dec(self):
121  pass
122 
123  def version(self):
124  print(__version__)
125 
126  def make(self):
127  pass
128 
129  def check(self):
130  print(__logo__)
131  try:
132  file = self.args[2]
133  db_name = self.args[3]
134  except IndexError:
135  raise IndexError("为了保证数据库的sql执行顺利,请填写pojo存在的文件名和数据库名称")
136  import inspect
137  temp_module = importlib.import_module(file)
138 
139  temp_classes = inspect.getmembers(temp_module, inspect.isclass)
140  for name, class_ in temp_classes:
141  c = class_()
142  c.orm.check()
143 
144  def help(self):
145  table = PrettyTable(["命令", "使用方法", "描述"])
146  table.border = True
147  table.junction_char = '-'
148  [table.add_row([k, v[2], v[1]]) for k, v in self.c.items()]
149  print(table)
aestate.work.commad.Commands.check
def check(self)
Definition: commad.py:129
aestate.work.commad.Commands.help
def help(self)
Definition: commad.py:144
aestate.work.commad.Commands.args
args
Definition: commad.py:46
aestate.work.commad.Commands.enc
def enc(self)
Definition: commad.py:117
aestate.work.commad.Commands.c
c
Definition: commad.py:47
aestate.work.commad.Commands.version
def version(self)
Definition: commad.py:123
aestate.work.commad.Commands.__init__
def __init__(self, *args)
Definition: commad.py:42
aestate.work.commad.Commands.start
def start(self)
Definition: commad.py:99
aestate.work.commad.Commands
Definition: commad.py:41
aestate.work.commad.Commands.make
def make(self)
Definition: commad.py:126
aestate.work.commad.Commands.dec
def dec(self)
Definition: commad.py:120
aestate.work.commad.Commands.create
def create(self)
Definition: commad.py:102
aestate.work.commad.Commands.startproject
def startproject(self)
Definition: commad.py:96