diff --git a/.github/workflows/alist-sync.yaml b/.github/workflows/alist-sync.yaml index c61b502..aa777bd 100644 --- a/.github/workflows/alist-sync.yaml +++ b/.github/workflows/alist-sync.yaml @@ -2,18 +2,25 @@ name: Alist Sync env: _ALIST_SYNC_NAME: "action-${{github.actor}}-${{github.run_id}}-${{github.run_number}}" + _ALIST_SYNC_DEBUG: ${{ github.event.inputs.debug }} + _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} on: workflow_dispatch: inputs: reload_storage: - description: | - 是否重新创建存储: true or false - 默认情况下,如果存储已经存在,则不会重新创建 - 如果指定了true,则会删除全部的存储器,并从新载入 + description: 删除现有存储库,并从配置文件或远程配置中重新创建存储器 + type: boolean required: false default: false + + + debug: + description: 开启调试模式 type: boolean + required: false + default: false + jobs: run: @@ -67,13 +74,13 @@ jobs: EOF python3 tools/create_storage.py - - name: RUN - env: - _ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} + - name: RUN Alist Sync run: | cat > config.yaml << EOF ${{ secrets.SYNC_CONFIG }} EOF set -ex + export TERM=dumb + export FORCE_COLOR=true ./bootstrap.sh main test-config ./bootstrap.sh main sync diff --git a/alist_sync/__main__.py b/alist_sync/__main__.py index 0778178..c50c33c 100644 --- a/alist_sync/__main__.py +++ b/alist_sync/__main__.py @@ -41,16 +41,22 @@ def t_ignore(path, match): @app.command("sync") def sync( config_file: str = Option(None, "--config", "-c", help="配置文件路径"), - debug: bool = Option(False, "--debug", help="调试模式, 将以单线程启动"), + debug: bool = Option( + False, + "--debug", + envvar="ALIST_SYNC_DEBUG", + help="调试模式, 将以单线程启动", + ), ): """同步任务""" - from alist_sync.config import create_config + from alist_sync.config import create_config, getenv from alist_sync.d_main import main, main_debug if config_file and Path(config_file).exists(): os.environ["ALIST_SYNC_CONFIG"] = str(Path(config_file).resolve().absolute()) os.environ["_ALIST_SYNC_CONFIG"] = str(Path(config_file).resolve().absolute()) - + if getenv("ALIST_SYNC_DEBUG", "false").lower() == "true": + debug = True create_config() if debug: echo("调试模式启动") diff --git a/alist_sync/config.py b/alist_sync/config.py index 88b7eaf..980d174 100644 --- a/alist_sync/config.py +++ b/alist_sync/config.py @@ -31,6 +31,9 @@ ), ] +TrueValues = {"true", "1", "yes", "on", "y", "t", "1"} +FalseValues = {"false", "0", "no", "off", "n", "f", "0"} + def getenv(name, default=None): """获取环境变量""" @@ -139,15 +142,7 @@ def __hash__(self): timeout: int = Field(10) ua: str = None - daemon: bool = getenv("ALIST_SYNC_DAEMON", "false").lower() in ( - "true", - "1", - "yes", - "on", - "y", - "t", - "1", - ) + daemon: bool = getenv("ALIST_SYNC_DAEMON", "false").lower() in TrueValues name: str = getenv("ALIST_SYNC_NAME", "alist-sync") @@ -161,6 +156,8 @@ def __hash__(self): create_time: datetime = datetime.now() logs: dict = None + debug: bool = getenv("ALIST_SYNC_DEBUG", "false").lower() in TrueValues + def __init__(self, **data: Any): super().__init__(**data) import logging.config diff --git a/alist_sync/d_worker.py b/alist_sync/d_worker.py index f8b0101..2a2f035 100644 --- a/alist_sync/d_worker.py +++ b/alist_sync/d_worker.py @@ -162,9 +162,7 @@ def copy_single_stream(self): "Last-Modified": str( int(self.source_path.stat().modified.timestamp() * 1000) ), - "File-Path": urllib.parse.quote( - str(self.target_path.as_posix()) - ), + "File-Path": urllib.parse.quote(str(self.target_path.as_posix())), }, content=fs, ) @@ -229,9 +227,7 @@ def run(self): try: if self.status in ["done", "failed"]: return - if self.need_backup and self.status in [ - "init", - ]: + if self.need_backup and self.status in ["init"]: self.backup() if self.type == "copy" and self.status in ["init", "back-upped"]: @@ -246,7 +242,7 @@ def run(self): logger.error(f"worker[{self.short_id}] 出现错误: {_e}") self.error_info = str(_e) self.update(status="failed") - if os.getenv("ALIST_SYNC_DEBUG"): + if sync_config.debug: raise _e