core.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:PyChroner 作者: NephyProject 项目源码 文件源码
def __init__(self, prompt: bool=True) -> None:
        pidFile = f"{os.getcwd()}/lock"
        if os.path.isfile(pidFile):
            running = False
            with open(pidFile) as f:
                pid = f.read()
                if pid.isdigit() and psutil.pid_exists(int(pid.strip())):
                    running = True
            if running:
                print("PyChroner is already running.")
                exit(1)
        with open(pidFile, "w") as f:
            f.write(str(os.getpid()))

        self.prompt: bool = prompt
        self.config: Config = Config()
        sys.path.append(self.config.directory.library)

        makeDirs(self.config.directory.dirs)
        self.queue = Queue()
        self.logger: Logger = getLogger(
                name="pychroner", directory=self.config.directory.logs, logLevel=self.config.logging.level,
                slack=self.config.logging.slack,
                queue=self.queue
        )
        self.logger.info(f"Logger started. Current time is {datetime.now()}.")
        self.logger.info(f"Working directory is {os.getcwd()}. Running as {os.getlogin()}, PID {os.getpid()}.")
        self.logger.info(
                f"Operating System is {platform.system()} {platform.release()} "
                f"[version {platform.version()}] ({platform.architecture()[0]}). "
        )
        self.logger.info(
                f"Running Python is version {platform.python_version()} ({platform.python_implementation()}) "
                f"build {platform.python_compiler()} [{ platform.python_build()[1]}]."
        )
        if os.getlogin() in ["root", "Administrator"]:
            self.logger.warning(f"PyChroner is running as root or Administrator. Bot should be running as a normal user.")

        self.UM: UserStreamManager = UserStreamManager(self)
        self.WSM: WebSocketManager = WebSocketManager(self)
        self.TM: ThreadManager = ThreadManager(self)

        self.PM: PluginManager = PluginManager(self)
        self.PM.loadPluginsFromDir()

        self.FS: FileSystemWatcher = FileSystemWatcher(self)
        self.CM = ConsoleManager(self)
        self.WM = WebUIManager(self)
        self.LS = LocalStorage()

        self.logger.info(f"Initialization Complate. Current time is {datetime.now()}.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号