From cf3fe5cc667d86d0e53b4403e8fa058a30d43854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=BB=A3=E7=A0=812016?= Date: Fri, 3 Feb 2023 04:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E=E4=B8=8E?= =?UTF-8?q?=E5=A4=9A=E7=9B=AE=E5=BD=95=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +- base_action.py => bak/base_action.py | 0 build_handler.py => bak/build_handler.py | 0 bak/cm.py | 146 ++++++++++++++++ cm_config.py => bak/cm_config.py | 0 cm_decorator.py => bak/cm_decorator.py | 0 init_action.py => bak/init_action.py | 0 init_handler.py => bak/init_handler.py | 0 .../template_c_module_app/CMakeLists.txt | 0 .../include/sample/sample.h | 0 .../template_c_module_app/src/CMakeLists.txt | 0 .../src/main/CMakeLists.txt | 0 .../template_c_module_app/src/main/main.c | 0 .../src/sample/CMakeLists.txt | 0 .../template_c_module_app/src/sample/sample.c | 0 .../template_c_simple/CMakeLists.txt | 17 ++ bak/resources/template_c_simple/main.c | 6 + .../template_c_simple_app/CMakeLists.txt | 0 .../template_c_simple_app/include/sample.h | 0 .../template_c_simple_app/src/CMakeLists.txt | 0 .../template_c_simple_app/src/main.c | 0 .../template_c_simple_app/src/sample.c | 0 .../template_cpp_module_app/CMakeLists.txt | 0 .../include/sample/sample.h | 0 .../src/CMakeLists.txt | 0 .../src/main/CMakeLists.txt | 0 .../template_cpp_module_app/src/main/main.cpp | 0 .../src/sample/CMakeLists.txt | 0 .../src/sample/sample.cpp | 0 .../template_cpp_simple/CMakeLists.txt | 0 .../resources}/template_cpp_simple/main.cpp | 0 .../template_cpp_simple_app/CMakeLists.txt | 0 .../template_cpp_simple_app/include/sample.h | 0 .../src/CMakeLists.txt | 0 .../template_cpp_simple_app/src/main.cpp | 0 .../template_cpp_simple_app/src/sample.cpp | 0 util.py => bak/util.py | 0 cm.py | 161 +++--------------- requirements.txt | 8 + resources/template_c_simple/CMakeLists.txt | 18 +- util/__init__.py | 0 util/util.py | 10 ++ 42 files changed, 217 insertions(+), 160 deletions(-) rename base_action.py => bak/base_action.py (100%) rename build_handler.py => bak/build_handler.py (100%) create mode 100644 bak/cm.py rename cm_config.py => bak/cm_config.py (100%) rename cm_decorator.py => bak/cm_decorator.py (100%) rename init_action.py => bak/init_action.py (100%) rename init_handler.py => bak/init_handler.py (100%) rename {resources => bak/resources}/template_c_module_app/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_module_app/include/sample/sample.h (100%) rename {resources => bak/resources}/template_c_module_app/src/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_module_app/src/main/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_module_app/src/main/main.c (100%) rename {resources => bak/resources}/template_c_module_app/src/sample/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_module_app/src/sample/sample.c (100%) create mode 100644 bak/resources/template_c_simple/CMakeLists.txt create mode 100644 bak/resources/template_c_simple/main.c rename {resources => bak/resources}/template_c_simple_app/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_simple_app/include/sample.h (100%) rename {resources => bak/resources}/template_c_simple_app/src/CMakeLists.txt (100%) rename {resources => bak/resources}/template_c_simple_app/src/main.c (100%) rename {resources => bak/resources}/template_c_simple_app/src/sample.c (100%) rename {resources => bak/resources}/template_cpp_module_app/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_module_app/include/sample/sample.h (100%) rename {resources => bak/resources}/template_cpp_module_app/src/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_module_app/src/main/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_module_app/src/main/main.cpp (100%) rename {resources => bak/resources}/template_cpp_module_app/src/sample/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_module_app/src/sample/sample.cpp (100%) rename {resources => bak/resources}/template_cpp_simple/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_simple/main.cpp (100%) rename {resources => bak/resources}/template_cpp_simple_app/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_simple_app/include/sample.h (100%) rename {resources => bak/resources}/template_cpp_simple_app/src/CMakeLists.txt (100%) rename {resources => bak/resources}/template_cpp_simple_app/src/main.cpp (100%) rename {resources => bak/resources}/template_cpp_simple_app/src/sample.cpp (100%) rename util.py => bak/util.py (100%) create mode 100644 requirements.txt create mode 100644 util/__init__.py create mode 100644 util/util.py diff --git a/README.md b/README.md index 3fb492f..e94c310 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # cm_cli -使用 python 管理 cmake 工程 \ No newline at end of file +使用 python 管理 cmake 工程 + +``` +pip freeze > requirements.txt +pip install - r requirements.txt +``` + +``` +pyinstaller cm.py -p util +``` \ No newline at end of file diff --git a/base_action.py b/bak/base_action.py similarity index 100% rename from base_action.py rename to bak/base_action.py diff --git a/build_handler.py b/bak/build_handler.py similarity index 100% rename from build_handler.py rename to bak/build_handler.py diff --git a/bak/cm.py b/bak/cm.py new file mode 100644 index 0000000..8126c5a --- /dev/null +++ b/bak/cm.py @@ -0,0 +1,146 @@ +# -*- coding: utf-8 -*- +import argparse +import json +import os.path +import sys + +import init_action +from build_handler import BuildHandler +from cm_config import CmConfig +from init_handler import InitHandler +from util import collection_init_args, is_windows + +parser = argparse.ArgumentParser() +subparsers = parser.add_subparsers() + +KEY_CM_ACTION = 'cm_action' +ARG_PREFIX = '--' + +SUB_COMMAND_INIT = 'init' +ARG_INIT_NAME = 'name' +ARG_INIT_LANGUAGE = 'language' +ARG_INIT_STANDARD = 'standard' +ARG_INIT_PROJ_TYPE = 'proj-type' +ARG_INIT_BUILD_DIR = 'build-dir' +ARG_INIT_OUTPUT_DIR = 'output-dir' + +SUB_COMMAND_BUILD = 'build' +ARG_BUILD_RE = 're' + +SUB_COMMAND_RUN = 'run' + + +def register_init_args(): + """ + init 子命令 + """ + init_parsers = subparsers.add_parser(SUB_COMMAND_INIT, help='初始化') + init_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_INIT) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_NAME, help='项目名称', action=init_action.NameAction) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_LANGUAGE, help='语言', choices=['c', 'cpp'], + action=init_action.LanguageAction) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_STANDARD, + help='语言标准. c:89,90,99,11,18 . cpp: 98,11,14,17,20,23 . c 默认为 11 , cpp 默认为 14', + action=init_action.LanguageStandardAction) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_PROJ_TYPE, + help='项目类型. simple, simple_app, module_app . 默认为 simple_app', + default='simple_app', + action=init_action.ProjTypeAction) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_BUILD_DIR, help='构建目录. 默认为 build', + default='build', + action=init_action.BuildDirAction) + init_parsers.add_argument(ARG_PREFIX + ARG_INIT_OUTPUT_DIR, help='二进制或库文件输出目录. 默认为 bin', + default='bin', + action=init_action.OutputDirAction) + + +def register_build_args(): + """ + build 子命令 + """ + build_parsers = subparsers.add_parser(SUB_COMMAND_BUILD, help='构建') + build_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_BUILD) + build_parsers.add_argument(ARG_PREFIX + ARG_BUILD_RE, help='重新构建', action='store_const', const=1) + + +def register_run_args(): + """ + run 子命令 + """ + run_parsers = subparsers.add_parser(SUB_COMMAND_RUN, help='运行') + run_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_RUN) + + +def print_config(): + config = CmConfig() + print('proj_name:' + config.proj_name) + print('language:' + config.language) + print('standard:' + config.standard) + print('type:' + config.proj_type) + print('build_dir:' + config.build_dir) + print('output_dir:' + config.output_dir) + + +def init_cm_config(): + """ + 初始化全局配置 + :return: + """ + config = CmConfig() + + # 程序所在目录 + if hasattr(sys, 'frozen'): + config._application_dir = os.path.dirname(sys.executable) + elif __file__: + config._application_dir = os.path.dirname(os.path.abspath(__file__)) + + # 工作目录 + config._work_dir = os.getcwd() + + # 如果工作目录存在 cm.json , 则根据 cm.json 更新 CmConfig + cm_file = config.work_dir + os.path.sep + 'cm.json' + if os.path.exists(cm_file): + with open(cm_file, 'r', encoding='UTF-8') as file: + data = json.load(file) + config.proj_name = data.get('proj_name') + config.language = data.get('language') + config.standard = data.get('standard') + config.proj_type = data.get('proj_type') + config.build_dir = data.get('build_dir') + config.output_dir = data.get('output_dir') + + +# ['cm.py','base_action.py','build_handler.py','cm_config.py','cm_decorator.py','init_action.py','init_handler.py','util.py'], +if __name__ == '__main__': + # 初始化全局配置 + init_cm_config() + config = CmConfig() + + # 注册命令 + register_init_args() + register_build_args() + register_run_args() + + args = parser.parse_args() + if SUB_COMMAND_INIT == args.__dict__[KEY_CM_ACTION]: + if os.path.exists('cm.json'): + print('已完成初始化') + else: + collection_init_args() + print('执行初始化...') + init_handler = InitHandler() + init_handler.handle() + print('初始化完成. 使用 cm build 编译 , cm run 运行') + elif SUB_COMMAND_BUILD == args.__dict__[KEY_CM_ACTION]: + print('开始构建...') + build_handler = BuildHandler() + build_handler.build(re=args.__dict__[ARG_BUILD_RE]) + print('构建完成. 使用 cm run 运行') + elif SUB_COMMAND_RUN == args.__dict__[KEY_CM_ACTION]: + print('开始运行...\n') + + command = '.' + os.path.sep + config.output_dir + os.path.sep + config.proj_name + if is_windows(): + command = command + '.exe' + os.system(command) + print('\n运行完毕') diff --git a/cm_config.py b/bak/cm_config.py similarity index 100% rename from cm_config.py rename to bak/cm_config.py diff --git a/cm_decorator.py b/bak/cm_decorator.py similarity index 100% rename from cm_decorator.py rename to bak/cm_decorator.py diff --git a/init_action.py b/bak/init_action.py similarity index 100% rename from init_action.py rename to bak/init_action.py diff --git a/init_handler.py b/bak/init_handler.py similarity index 100% rename from init_handler.py rename to bak/init_handler.py diff --git a/resources/template_c_module_app/CMakeLists.txt b/bak/resources/template_c_module_app/CMakeLists.txt similarity index 100% rename from resources/template_c_module_app/CMakeLists.txt rename to bak/resources/template_c_module_app/CMakeLists.txt diff --git a/resources/template_c_module_app/include/sample/sample.h b/bak/resources/template_c_module_app/include/sample/sample.h similarity index 100% rename from resources/template_c_module_app/include/sample/sample.h rename to bak/resources/template_c_module_app/include/sample/sample.h diff --git a/resources/template_c_module_app/src/CMakeLists.txt b/bak/resources/template_c_module_app/src/CMakeLists.txt similarity index 100% rename from resources/template_c_module_app/src/CMakeLists.txt rename to bak/resources/template_c_module_app/src/CMakeLists.txt diff --git a/resources/template_c_module_app/src/main/CMakeLists.txt b/bak/resources/template_c_module_app/src/main/CMakeLists.txt similarity index 100% rename from resources/template_c_module_app/src/main/CMakeLists.txt rename to bak/resources/template_c_module_app/src/main/CMakeLists.txt diff --git a/resources/template_c_module_app/src/main/main.c b/bak/resources/template_c_module_app/src/main/main.c similarity index 100% rename from resources/template_c_module_app/src/main/main.c rename to bak/resources/template_c_module_app/src/main/main.c diff --git a/resources/template_c_module_app/src/sample/CMakeLists.txt b/bak/resources/template_c_module_app/src/sample/CMakeLists.txt similarity index 100% rename from resources/template_c_module_app/src/sample/CMakeLists.txt rename to bak/resources/template_c_module_app/src/sample/CMakeLists.txt diff --git a/resources/template_c_module_app/src/sample/sample.c b/bak/resources/template_c_module_app/src/sample/sample.c similarity index 100% rename from resources/template_c_module_app/src/sample/sample.c rename to bak/resources/template_c_module_app/src/sample/sample.c diff --git a/bak/resources/template_c_simple/CMakeLists.txt b/bak/resources/template_c_simple/CMakeLists.txt new file mode 100644 index 0000000..f38d47b --- /dev/null +++ b/bak/resources/template_c_simple/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.0) + +# 设置项目名称和语言 +project($%{proj_name} C) + +# 指定语言标准 +set(CMAKE_C_STANDARD $%{standard}) +set(CMAKE_C_STANDARD_REQUIRED True) + +# 参与编译的源文件列表 +aux_source_directory(. MAIN_SRCS) + +# 可执行文件所在目录 +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/$%{output_dir}) + + +add_executable(${PROJECT_NAME} ${MAIN_SRCS}) diff --git a/bak/resources/template_c_simple/main.c b/bak/resources/template_c_simple/main.c new file mode 100644 index 0000000..8438c2c --- /dev/null +++ b/bak/resources/template_c_simple/main.c @@ -0,0 +1,6 @@ +#include +int main() +{ + printf("Hello World\n"); + return 0; +} \ No newline at end of file diff --git a/resources/template_c_simple_app/CMakeLists.txt b/bak/resources/template_c_simple_app/CMakeLists.txt similarity index 100% rename from resources/template_c_simple_app/CMakeLists.txt rename to bak/resources/template_c_simple_app/CMakeLists.txt diff --git a/resources/template_c_simple_app/include/sample.h b/bak/resources/template_c_simple_app/include/sample.h similarity index 100% rename from resources/template_c_simple_app/include/sample.h rename to bak/resources/template_c_simple_app/include/sample.h diff --git a/resources/template_c_simple_app/src/CMakeLists.txt b/bak/resources/template_c_simple_app/src/CMakeLists.txt similarity index 100% rename from resources/template_c_simple_app/src/CMakeLists.txt rename to bak/resources/template_c_simple_app/src/CMakeLists.txt diff --git a/resources/template_c_simple_app/src/main.c b/bak/resources/template_c_simple_app/src/main.c similarity index 100% rename from resources/template_c_simple_app/src/main.c rename to bak/resources/template_c_simple_app/src/main.c diff --git a/resources/template_c_simple_app/src/sample.c b/bak/resources/template_c_simple_app/src/sample.c similarity index 100% rename from resources/template_c_simple_app/src/sample.c rename to bak/resources/template_c_simple_app/src/sample.c diff --git a/resources/template_cpp_module_app/CMakeLists.txt b/bak/resources/template_cpp_module_app/CMakeLists.txt similarity index 100% rename from resources/template_cpp_module_app/CMakeLists.txt rename to bak/resources/template_cpp_module_app/CMakeLists.txt diff --git a/resources/template_cpp_module_app/include/sample/sample.h b/bak/resources/template_cpp_module_app/include/sample/sample.h similarity index 100% rename from resources/template_cpp_module_app/include/sample/sample.h rename to bak/resources/template_cpp_module_app/include/sample/sample.h diff --git a/resources/template_cpp_module_app/src/CMakeLists.txt b/bak/resources/template_cpp_module_app/src/CMakeLists.txt similarity index 100% rename from resources/template_cpp_module_app/src/CMakeLists.txt rename to bak/resources/template_cpp_module_app/src/CMakeLists.txt diff --git a/resources/template_cpp_module_app/src/main/CMakeLists.txt b/bak/resources/template_cpp_module_app/src/main/CMakeLists.txt similarity index 100% rename from resources/template_cpp_module_app/src/main/CMakeLists.txt rename to bak/resources/template_cpp_module_app/src/main/CMakeLists.txt diff --git a/resources/template_cpp_module_app/src/main/main.cpp b/bak/resources/template_cpp_module_app/src/main/main.cpp similarity index 100% rename from resources/template_cpp_module_app/src/main/main.cpp rename to bak/resources/template_cpp_module_app/src/main/main.cpp diff --git a/resources/template_cpp_module_app/src/sample/CMakeLists.txt b/bak/resources/template_cpp_module_app/src/sample/CMakeLists.txt similarity index 100% rename from resources/template_cpp_module_app/src/sample/CMakeLists.txt rename to bak/resources/template_cpp_module_app/src/sample/CMakeLists.txt diff --git a/resources/template_cpp_module_app/src/sample/sample.cpp b/bak/resources/template_cpp_module_app/src/sample/sample.cpp similarity index 100% rename from resources/template_cpp_module_app/src/sample/sample.cpp rename to bak/resources/template_cpp_module_app/src/sample/sample.cpp diff --git a/resources/template_cpp_simple/CMakeLists.txt b/bak/resources/template_cpp_simple/CMakeLists.txt similarity index 100% rename from resources/template_cpp_simple/CMakeLists.txt rename to bak/resources/template_cpp_simple/CMakeLists.txt diff --git a/resources/template_cpp_simple/main.cpp b/bak/resources/template_cpp_simple/main.cpp similarity index 100% rename from resources/template_cpp_simple/main.cpp rename to bak/resources/template_cpp_simple/main.cpp diff --git a/resources/template_cpp_simple_app/CMakeLists.txt b/bak/resources/template_cpp_simple_app/CMakeLists.txt similarity index 100% rename from resources/template_cpp_simple_app/CMakeLists.txt rename to bak/resources/template_cpp_simple_app/CMakeLists.txt diff --git a/resources/template_cpp_simple_app/include/sample.h b/bak/resources/template_cpp_simple_app/include/sample.h similarity index 100% rename from resources/template_cpp_simple_app/include/sample.h rename to bak/resources/template_cpp_simple_app/include/sample.h diff --git a/resources/template_cpp_simple_app/src/CMakeLists.txt b/bak/resources/template_cpp_simple_app/src/CMakeLists.txt similarity index 100% rename from resources/template_cpp_simple_app/src/CMakeLists.txt rename to bak/resources/template_cpp_simple_app/src/CMakeLists.txt diff --git a/resources/template_cpp_simple_app/src/main.cpp b/bak/resources/template_cpp_simple_app/src/main.cpp similarity index 100% rename from resources/template_cpp_simple_app/src/main.cpp rename to bak/resources/template_cpp_simple_app/src/main.cpp diff --git a/resources/template_cpp_simple_app/src/sample.cpp b/bak/resources/template_cpp_simple_app/src/sample.cpp similarity index 100% rename from resources/template_cpp_simple_app/src/sample.cpp rename to bak/resources/template_cpp_simple_app/src/sample.cpp diff --git a/util.py b/bak/util.py similarity index 100% rename from util.py rename to bak/util.py diff --git a/cm.py b/cm.py index 8126c5a..6465990 100644 --- a/cm.py +++ b/cm.py @@ -1,146 +1,23 @@ # -*- coding: utf-8 -*- -import argparse -import json -import os.path -import sys +from jinja2 import Template -import init_action -from build_handler import BuildHandler -from cm_config import CmConfig -from init_handler import InitHandler -from util import collection_init_args, is_windows +from util import util -parser = argparse.ArgumentParser() -subparsers = parser.add_subparsers() - -KEY_CM_ACTION = 'cm_action' -ARG_PREFIX = '--' - -SUB_COMMAND_INIT = 'init' -ARG_INIT_NAME = 'name' -ARG_INIT_LANGUAGE = 'language' -ARG_INIT_STANDARD = 'standard' -ARG_INIT_PROJ_TYPE = 'proj-type' -ARG_INIT_BUILD_DIR = 'build-dir' -ARG_INIT_OUTPUT_DIR = 'output-dir' - -SUB_COMMAND_BUILD = 'build' -ARG_BUILD_RE = 're' - -SUB_COMMAND_RUN = 'run' - - -def register_init_args(): - """ - init 子命令 - """ - init_parsers = subparsers.add_parser(SUB_COMMAND_INIT, help='初始化') - init_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_INIT) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_NAME, help='项目名称', action=init_action.NameAction) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_LANGUAGE, help='语言', choices=['c', 'cpp'], - action=init_action.LanguageAction) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_STANDARD, - help='语言标准. c:89,90,99,11,18 . cpp: 98,11,14,17,20,23 . c 默认为 11 , cpp 默认为 14', - action=init_action.LanguageStandardAction) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_PROJ_TYPE, - help='项目类型. simple, simple_app, module_app . 默认为 simple_app', - default='simple_app', - action=init_action.ProjTypeAction) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_BUILD_DIR, help='构建目录. 默认为 build', - default='build', - action=init_action.BuildDirAction) - init_parsers.add_argument(ARG_PREFIX + ARG_INIT_OUTPUT_DIR, help='二进制或库文件输出目录. 默认为 bin', - default='bin', - action=init_action.OutputDirAction) - - -def register_build_args(): - """ - build 子命令 - """ - build_parsers = subparsers.add_parser(SUB_COMMAND_BUILD, help='构建') - build_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_BUILD) - build_parsers.add_argument(ARG_PREFIX + ARG_BUILD_RE, help='重新构建', action='store_const', const=1) - - -def register_run_args(): - """ - run 子命令 - """ - run_parsers = subparsers.add_parser(SUB_COMMAND_RUN, help='运行') - run_parsers.add_argument(ARG_PREFIX + KEY_CM_ACTION, help='动作类型', default=SUB_COMMAND_RUN) - - -def print_config(): - config = CmConfig() - print('proj_name:' + config.proj_name) - print('language:' + config.language) - print('standard:' + config.standard) - print('type:' + config.proj_type) - print('build_dir:' + config.build_dir) - print('output_dir:' + config.output_dir) - - -def init_cm_config(): - """ - 初始化全局配置 - :return: - """ - config = CmConfig() - - # 程序所在目录 - if hasattr(sys, 'frozen'): - config._application_dir = os.path.dirname(sys.executable) - elif __file__: - config._application_dir = os.path.dirname(os.path.abspath(__file__)) - - # 工作目录 - config._work_dir = os.getcwd() - - # 如果工作目录存在 cm.json , 则根据 cm.json 更新 CmConfig - cm_file = config.work_dir + os.path.sep + 'cm.json' - if os.path.exists(cm_file): - with open(cm_file, 'r', encoding='UTF-8') as file: - data = json.load(file) - config.proj_name = data.get('proj_name') - config.language = data.get('language') - config.standard = data.get('standard') - config.proj_type = data.get('proj_type') - config.build_dir = data.get('build_dir') - config.output_dir = data.get('output_dir') - - -# ['cm.py','base_action.py','build_handler.py','cm_config.py','cm_decorator.py','init_action.py','init_handler.py','util.py'], if __name__ == '__main__': - # 初始化全局配置 - init_cm_config() - config = CmConfig() - - # 注册命令 - register_init_args() - register_build_args() - register_run_args() - - args = parser.parse_args() - if SUB_COMMAND_INIT == args.__dict__[KEY_CM_ACTION]: - if os.path.exists('cm.json'): - print('已完成初始化') - else: - collection_init_args() - print('执行初始化...') - init_handler = InitHandler() - init_handler.handle() - print('初始化完成. 使用 cm build 编译 , cm run 运行') - elif SUB_COMMAND_BUILD == args.__dict__[KEY_CM_ACTION]: - print('开始构建...') - build_handler = BuildHandler() - build_handler.build(re=args.__dict__[ARG_BUILD_RE]) - print('构建完成. 使用 cm run 运行') - elif SUB_COMMAND_RUN == args.__dict__[KEY_CM_ACTION]: - print('开始运行...\n') - - command = '.' + os.path.sep + config.output_dir + os.path.sep + config.proj_name - if is_windows(): - command = command + '.exe' - os.system(command) - print('\n运行完毕') + if util.is_windows(): + print('running in windows') + elif util.is_linux(): + print('running in linux') + print('hello world') + + template = Template('Hello {{name}}') + s = template.render(name='老狼') + print(s) + + with open('F:/2023/blog_code/cm_cli/resources/template_c_simple/CMakeLists.txt', encoding='UTF-8') as file: + data = file.read() + template = Template(data) + s = template.render({ + 'proj_name': 'helloc' + }) + print(s) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..49c8d91 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +altgraph==0.17.3 +future==0.18.3 +Jinja2==3.1.2 +MarkupSafe==2.1.2 +pefile==2022.5.30 +pyinstaller==5.7.0 +pyinstaller-hooks-contrib==2022.15 +pywin32-ctypes==0.2.0 diff --git a/resources/template_c_simple/CMakeLists.txt b/resources/template_c_simple/CMakeLists.txt index f38d47b..b7737f2 100644 --- a/resources/template_c_simple/CMakeLists.txt +++ b/resources/template_c_simple/CMakeLists.txt @@ -1,17 +1 @@ -cmake_minimum_required(VERSION 3.0) - -# 设置项目名称和语言 -project($%{proj_name} C) - -# 指定语言标准 -set(CMAKE_C_STANDARD $%{standard}) -set(CMAKE_C_STANDARD_REQUIRED True) - -# 参与编译的源文件列表 -aux_source_directory(. MAIN_SRCS) - -# 可执行文件所在目录 -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/$%{output_dir}) - - -add_executable(${PROJECT_NAME} ${MAIN_SRCS}) +project name: {{proj_name}} \ No newline at end of file diff --git a/util/__init__.py b/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/util/util.py b/util/util.py new file mode 100644 index 0000000..19196e7 --- /dev/null +++ b/util/util.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +import platform + + +def is_windows(): + return 'Windows' == platform.system() + + +def is_linux(): + return 'Linux' == platform.system() -- GitLab