123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- # -*- coding: utf-8 -*-
- # @Time : 2021/05/17/
- # @Author : ricky
- # @File : base.py
- # @Software: vscode
- """
- 关键字修改类基类
- """
- import os
- from shutil import move
- from loguru import logger
- class BaseCore:
- """
- 初始化参数:
- context (object): 上下文对象
- targetdir (str): 目标路径
- sitename (str): 新站点名称,
- projectdirname (str): 新目录名称
- packagename (str): 新包名
- projectname (str): 新项目名
- artifactid (str): 新artifactId
- groupid (str): 新groupId
- configdict (dict): 配置字典
- callback (function): 回调方法
- """
- def __init__(self, context, targetdir, sitename, projectdirname,
- packagename, projectname, artifactid, groupid, configdict,
- callback):
- self.context = context
- self.targetdir = targetdir
- self.sitename = sitename
- self.packagename = packagename
- self.projectdirname = projectdirname
- self.projectname = projectname
- self.artifactid = artifactid
- self.groupid = groupid
- self.configdict = configdict
- self.callback = callback
- self.exceptions = []
- def start(self):
- """开始方法"""
- pass
- def messagehandle(self, message):
- """
- 消息处理
- 参数:
- message (str): 消息
- """
- if hasattr(self.callback, '__call__'):
- self.callback(self.context, message)
- def exceptionhandle(self, message):
- """
- 异常处理
- 参数:
- message (str): 消息
- """
- self.exceptions.append(str(len(self.exceptions) + 1) + "." + message)
- logger.error(message)
- def move_dir(self, old_dir, new_dir):
- """
- 移动目录
-
- 参数:
- old_dir (str): 旧目录
- new_dir (str): 新目录
- """
- for temp_path in os.listdir(old_dir):
- filepath = new_dir + os.path.sep + temp_path
- oldpath = old_dir + os.path.sep + temp_path
- if os.path.isdir(oldpath):
- os.mkdir(filepath)
- self.move_dir(oldpath, filepath)
- if os.path.isfile(oldpath):
- move(oldpath, filepath)
|