{"id":253841,"date":"2022-10-05T08:06:29","date_gmt":"2022-10-05T00:06:29","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=253841"},"modified":"2022-09-28T11:06:46","modified_gmt":"2022-09-28T03:06:46","slug":"python-conture-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-conture-linux.html","title":{"rendered":"Python\u5b9e\u73b0\u811a\u672c\u8f6c\u6362\u4e3a\u547d\u4ee4\u884c\u7a0b\u5e8f\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4f7f\u7528Python\u4e2d\u7684scaffold\u548cclick\u5e93\uff0c\u4f60\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u7528\u7a0b\u5e8f\u5347\u7ea7\u4e3a\u4e00\u4e2a\u6210\u719f\u7684\u547d\u4ee4\u884c\u754c\u9762\u5de5\u5177\uff0c\u672c\u6587\u5c31\u6765\u5e26\u4f60\u770b\u770b\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\uff0c\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u4e86\u89e3\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728\u6211\u7684\u804c\u4e1a\u751f\u6daf\u4e2d\uff0c\u6211\u5199\u8fc7\u3001\u7528\u8fc7\u548c\u770b\u5230\u8fc7\u5f88\u591a\u968f\u610f\u7684\u811a\u672c\u3002\u4e00\u4e9b\u4eba\u9700\u8981\u534a\u81ea\u52a8\u5316\u5b8c\u6210\u4efb\u52a1\uff0c\u4e8e\u662f\u5b83\u4eec\u8bde\u751f\u4e86\u3002\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u5b83\u4eec\u53d8\u5f97\u8d8a\u6765\u8d8a\u5927\u3002\u5b83\u4eec\u5728\u4e00\u751f\u4e2d\u53ef\u80fd\u8f6c\u624b\u5f88\u591a\u6b21\u3002\u6211\u5e38\u5e38\u5e0c\u671b\u8fd9\u4e9b\u811a\u672c\u63d0\u4f9b\u66f4\u591a\u7684 \u547d\u4ee4\u884c\u5de5\u5177\u5f0f \u7684\u611f\u89c9\u3002\u4f46\u662f\uff0c\u4ece\u4e00\u6b21\u6027\u811a\u672c\u5230\u5408\u9002\u7684\u5de5\u5177\uff0c\u771f\u6b63\u63d0\u9ad8\u8d28\u91cf\u6c34\u5e73\u6709\u591a\u96be\u5462\uff1f\u4e8b\u5b9e\u8bc1\u660e\u8fd9\u5728 Python \u4e2d\u5e76\u4e0d\u96be\u3002<\/p>\n

\u642d\u5efa\u9aa8\u67b6\u811a\u672c<\/strong><\/div>\n

\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u4ece\u4e00\u5c0f\u6bb5 Python \u4ee3\u7801\u5f00\u59cb\u3002\u6211\u5c06\u628a\u5b83\u5e94\u7528\u5230 \u200b \u200bscaffold\u200b \u200b\u200b \u6a21\u5757\u4e2d\uff0c\u5e76\u4f7f\u7528 \u200b \u200bclick\u200b \u200b \u5e93\u6269\u5c55\u5b83\u4ee5\u63a5\u53d7\u547d\u4ee4\u884c\u53c2\u6570\u3002<\/p>\n

#!\/usr\/bin\/python\r\n \r\nfrom glob import glob\r\nfrom os.path import join, basename\r\nfrom shutil import move\r\nfrom datetime import datetime\r\nfrom os import link, unlink\r\n \r\n \r\nLATEST = 'latest.txt'\r\nARCHIVE = '\/Users\/mark\/archive'\r\nINCOMING = '\/Users\/mark\/incoming'\r\nTPATTERN = '%Y-%m-%d'\r\n \r\n \r\ndef transmogrify_filename(fname):\r\n    bname = basename(fname)\r\n    ts = datetime.now().strftime(TPATTERN)\r\n    return '-'.join([ts, bname])\r\n \r\ndef set_current_latest(file):\r\n    latest = join(ARCHIVE, LATEST)\r\n \r\n    try:\r\n        unlink(latest)\r\n    except:\r\n        pass\r\n    link(file, latest)\r\n \r\n \r\ndef rotate_file(source):\r\n \r\n    target = join(ARCHIVE, transmogrify_filename(source))\r\n    move(source, target)\r\n    set_current_latest(target)\r\n \r\n \r\ndef rotoscope():\r\n    file_no = 0\r\n    folder = join(INCOMING, '*.txt')\r\n    print(f'Looking in {INCOMING}')\r\n \r\n    for file in glob(folder):\r\n        rotate_file(file)\r\n        print(f'Rotated: {file}')\r\n        file_no = file_no + 1\r\n    print(f'Total files rotated: {file_no}')\r\n \r\nif __name__ == '__main__':\r\n \r\n    print('This is rotoscope 0.4.1. Bleep, bloop.')\r\n    rotoscope()<\/pre>\n

\u672c\u6587\u6240\u6709\u6ca1\u6709\u5728\u8fd9\u91cc\u63d2\u5165\u663e\u793a\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u4f60\u90fd\u53ef\u4ee5\u5728 \u200b \u200bhttps:\/\/codeberg.org\/ofosos\/rotoscope\u200b \u200b \u4e2d\u627e\u5230\u7279\u5b9a\u7248\u672c\u7684\u4ee3\u7801\u3002\u8be5\u4ed3\u5e93\u4e2d\u7684\u6bcf\u4e2a\u63d0\u4ea4\u90fd\u63cf\u8ff0\u4e86\u672c\u6587\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u4e00\u4e9b\u6709\u610f\u4e49\u7684\u6b65\u9aa4\u3002<\/p>\n

\u8fd9\u4e2a\u7247\u6bb5\u505a\u4e86\u51e0\u4ef6\u4e8b\uff1a<\/p>\n

\u200bINCOMING\u200b\r\n\u200bARCHIVE\u200b\r\n\u200bARCHIVE\/latest.txt\u200b<\/pre>\n

\u4f5c\u4e3a\u4e00\u4e2a\u793a\u4f8b\uff0c\u5b83\u5f88\u7b80\u5355\uff0c\u4f46\u5b83\u4f1a\u8ba9\u4f60\u7406\u89e3\u8fd9\u4e2a\u8fc7\u7a0b\u3002<\/p>\n

\u4f7f\u7528 Pyscaffold \u521b\u5efa\u5e94\u7528\u7a0b\u5e8f<\/strong><\/div>\n

\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5 \u200b \u200bscaffold\u200b \u200b\u200b\u3001\u200b \u200bclick\u200b \u200b\u200b \u548c \u200b \u200btox\u200b \u200b\u200b \u200b \u200bPython \u5e93\u200b \u200b\u3002<\/p>\n

$ python3 -m pip install scaffold click tox<\/pre>\n

\u5b89\u88c5 \u200b \u200bscaffold\u200b \u200b\u200b \u540e\uff0c\u5207\u6362\u5230\u793a\u4f8b\u7684 \u200b \u200brotoscope\u200b \u200b \u9879\u76ee\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

$ putup rotoscope -p rotoscope \\\r\n \r\n    --force --no-skeleton -n rotoscope \\\r\n    -d 'Move some files around.' -l GLWT \\\r\n    -u http:\/\/codeberg.org\/ofosos\/rotoscope \\\r\n    --save-config --pre-commit --markdown<\/pre>\n

Pyscaffold \u4f1a\u91cd\u5199\u6211\u7684 \u200b \u200bREADME.md\u200b \u200b\uff0c\u6240\u4ee5\u4ece Git \u6062\u590d\u5b83\uff1a<\/p>\n

$ git checkout README.md<\/pre>\n

Pyscaffold \u5728\u6587\u6863\u4e2d\u8bf4\u660e\u4e86\u5982\u4f55\u8bbe\u7f6e\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\u9879\u76ee\uff0c\u6211\u4e0d\u4f1a\u5728\u8fd9\u91cc\u4ecb\u7ecd\uff0c\u4f60\u4e4b\u540e\u53ef\u4ee5\u63a2\u7d22\u3002\u9664\u6b64\u4e4b\u5916\uff0cPyscaffold \u8fd8\u53ef\u4ee5\u5728\u9879\u76ee\u4e2d\u4e3a\u4f60\u63d0\u4f9b\u6301\u7eed\u96c6\u6210\uff08CI\uff09\u6a21\u677f\uff1a<\/p>\n

  • \u6253\u5305: \u4f60\u7684\u9879\u76ee\u73b0\u5728\u542f\u7528\u4e86 PyPi\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u5c06\u5176\u4e0a\u4f20\u5230\u4e00\u4e2a\u4ed3\u5e93\u5e76\u4ece\u90a3\u91cc\u5b89\u88c5\u5b83\u3002<\/li>\n
  • \u6587\u6863: \u4f60\u7684\u9879\u76ee\u73b0\u5728\u6709\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6587\u6863\u6587\u4ef6\u5939\u5c42\u6b21\u7ed3\u6784\uff0c\u5b83\u57fa\u4e8e Sphinx\uff0c\u5305\u62ec\u4e00\u4e2a\u200b \u200breadthedocs.org\u200b \u200b \u6784\u5efa\u5668\u3002<\/li>\n
  • \u6d4b\u8bd5: \u4f60\u7684\u9879\u76ee\u73b0\u5728\u53ef\u4ee5\u4e0e tox \u4e00\u8d77\u4f7f\u7528\uff0c\u6d4b\u8bd5\u6587\u4ef6\u5939\u5305\u542b\u8fd0\u884c\u57fa\u4e8e pytest \u7684\u6d4b\u8bd5\u6240\u9700\u7684\u6240\u6709\u6837\u677f\u6587\u4ef6\u3002<\/li>\n
  • \u4f9d\u8d56\u7ba1\u7406: \u6253\u5305\u548c\u6d4b\u8bd5\u57fa\u7840\u7ed3\u6784\u90fd\u9700\u8981\u4e00\u79cd\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb\u7684\u65b9\u6cd5\u3002\u200b \u200bsetup.cfg\u200b \u200b \u6587\u4ef6\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u5b83\u5305\u542b\u6240\u6709\u4f9d\u8d56\u9879\u3002<\/li>\n
  • \u9884\u63d0\u4ea4\u94a9\u5b50: \u5305\u62ec Python \u6e90\u4ee3\u7801\u683c\u5f0f\u5de5\u5177 black \u548c Python \u98ce\u683c\u68c0\u67e5\u5668 flake8\u3002<\/li>\n

    \u67e5\u770b\u6d4b\u8bd5\u6587\u4ef6\u5939\u5e76\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c \u200b \u200btox\u200b \u200b \u547d\u4ee4\uff0c\u5b83\u4f1a\u7acb\u5373\u8f93\u51fa\u4e00\u4e2a\u9519\u8bef\uff1a\u6253\u5305\u57fa\u7840\u8bbe\u65bd\u65e0\u6cd5\u627e\u5230\u76f8\u5173\u5e93\u3002<\/p>\n

    \u73b0\u5728\u521b\u5efa\u4e00\u4e2a \u200b \u200bGit\u200b \u200b\u200b \u6807\u8bb0\uff08\u4f8b\u5982 \u200b \u200bv0.2\u200b \u200b\u200b\uff09\uff0c\u6b64\u5de5\u5177\u4f1a\u5c06\u5176\u8bc6\u522b\u4e3a\u53ef\u5b89\u88c5\u7248\u672c\u3002\u5728\u63d0\u4ea4\u66f4\u6539\u4e4b\u524d\uff0c\u6d4f\u89c8\u4e00\u4e0b\u81ea\u52a8\u751f\u6210\u7684 \u200b \u200bsetup.cfg\u200b \u200b\u200b \u5e76\u6839\u636e\u9700\u8981\u7f16\u8f91\u5b83\u3002\u5bf9\u4e8e\u6b64\u793a\u4f8b\uff0c\u4f60\u53ef\u4ee5\u4fee\u6539 \u200b \u200bLICENSE\u200b \u200b \u548c\u9879\u76ee\u63cf\u8ff0\uff0c\u5c06\u8fd9\u4e9b\u66f4\u6539\u6dfb\u52a0\u5230 Git \u7684\u6682\u5b58\u533a\uff0c\u6211\u5fc5\u987b\u7981\u7528\u9884\u63d0\u4ea4\u94a9\u5b50\uff0c\u7136\u540e\u63d0\u4ea4\u5b83\u4eec\u3002\u5426\u5219\uff0c\u6211\u4f1a\u9047\u5230\u9519\u8bef\uff0c\u56e0\u4e3a Python \u98ce\u683c\u68c0\u67e5\u5668 flake8 \u4f1a\u62b1\u6028\u7cdf\u7cd5\u7684\u683c\u5f0f\u3002<\/p>\n

    $ PRE_COMMIT_ALLOW_NO_CONFIG=1 git commit<\/pre>\n

    \u5982\u679c\u8fd9\u4e2a\u811a\u672c\u6709\u4e00\u4e2a\u5165\u53e3\u70b9\uff0c\u7528\u6237\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u8c03\u7528\uff0c\u90a3\u5c31\u66f4\u597d\u4e86\u3002\u73b0\u5728\uff0c\u4f60\u53ea\u80fd\u901a\u8fc7\u627e \u200b \u200b.py\u200b \u200b\u200b \u6587\u4ef6\u5e76\u624b\u52a8\u6267\u884c\u5b83\u6765\u8fd0\u884c\u3002\u5e78\u8fd0\u7684\u662f\uff0cPython \u7684\u6253\u5305\u57fa\u7840\u8bbe\u65bd\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u201c\u7f50\u88c5\u201d\u65b9\u5f0f\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u914d\u7f6e\u66f4\u6539\u3002\u5c06\u4ee5\u4e0b\u5185\u5bb9\u6dfb\u52a0\u5230 \u200b \u200bsetup.cfg\u200b \u200b\u200b \u7684 \u200b \u200boptions.entry_points\u200b \u200b \u90e8\u5206\uff1a<\/p>\n

    console_scripts =\r\n    roto = rotoscope.rotoscope:rotoscope<\/pre>\n

    \u8fd9\u4e2a\u66f4\u6539\u4f1a\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a \u200b \u200broto\u200b \u200b\u200b \u7684 shell \u547d\u4ee4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u8c03\u7528 rotoscope \u811a\u672c\uff0c\u4f7f\u7528 \u200b \u200bpip\u200b \u200b\u200b \u5b89\u88c5 rotoscope \u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 \u200b \u200broto\u200b \u200b \u547d\u4ee4\u3002<\/p>\n

    \u5c31\u662f\u8fd9\u6837\uff0c\u4f60\u53ef\u4ee5\u4ece Pyscaffold \u514d\u8d39\u83b7\u5f97\u6240\u6709\u6253\u5305\u3001\u6d4b\u8bd5\u548c\u6587\u6863\u8bbe\u7f6e\u3002\u4f60\u8fd8\u83b7\u5f97\u4e86\u4e00\u4e2a\u9884\u63d0\u4ea4\u94a9\u5b50\u6765\u4fdd\u8bc1\uff08\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff09\u4f60\u6309\u7167\u8bbe\u5b9a\u89c4\u5219\u63d0\u4ea4\u3002<\/p>\n

    CLI \u5de5\u5177\u5316<\/strong><\/div>\n

    \u73b0\u5728\uff0c\u4e00\u4e9b\u503c\u4f1a\u786c\u7f16\u7801\u5230\u811a\u672c\u4e2d\uff0c\u5b83\u4eec\u4f5c\u4e3a\u547d\u4ee4 \u200b \u200b\u53c2\u6570\u200b \u200b\u200b \u4f1a\u66f4\u65b9\u4fbf\u3002\u4f8b\u5982\uff0c\u5c06 \u200b \u200bINCOMING\u200b \u200b \u5e38\u91cf\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u4f1a\u66f4\u597d\u3002<\/p>\n

    \u9996\u5148\uff0c\u5bfc\u5165 \u200b \u200bclick\u200b \u200b\u200b \u5e93\uff0c\u4f7f\u7528 Click \u63d0\u4f9b\u7684\u547d\u4ee4\u88c5\u9970\u5668\u5bf9 \u200b \u200brotoscope()\u200b \u200b\u200b \u65b9\u6cd5\u8fdb\u884c\u88c5\u9970\uff0c\u5e76\u6dfb\u52a0\u4e00\u4e2a Click \u4f20\u9012\u7ed9 \u200b \u200brotoscope\u200b \u200b \u51fd\u6570\u7684\u53c2\u6570\u3002Click \u63d0\u4f9b\u4e86\u4e00\u7ec4\u9a8c\u8bc1\u5668\uff0c\u56e0\u6b64\u8981\u5411\u53c2\u6570\u6dfb\u52a0\u4e00\u4e2a\u8def\u5f84\u9a8c\u8bc1\u5668\u3002Click \u8fd8\u65b9\u4fbf\u5730\u4f7f\u7528\u51fd\u6570\u7684\u5185\u5d4c\u5b57\u7b26\u4e32\u4f5c\u4e3a\u547d\u4ee4\u884c\u6587\u6863\u7684\u4e00\u90e8\u5206\u3002\u6240\u4ee5\u4f60\u6700\u7ec8\u4f1a\u5f97\u5230\u4ee5\u4e0b\u65b9\u6cd5\u7b7e\u540d\uff1a<\/p>\n

    @click.command()\r\n@click.argument('incoming', type=click.Path(exists=True))\r\ndef rotoscope(incoming):\r\n \r\n    \"\"\"\r\n \r\n    Rotoscope 0.4 - Bleep, blooop.\r\n \r\n    Simple sample that move files.\r\n \r\n    \"\"\"<\/pre>\n

    \u4e3b\u51fd\u6570\u4f1a\u8c03\u7528 \u200b \u200brotoscope()\u200b \u200b\uff0c\u5b83\u73b0\u5728\u662f\u4e00\u4e2a Click \u547d\u4ee4\uff0c\u4e0d\u9700\u8981\u4f20\u9012\u4efb\u4f55\u53c2\u6570\u3002<\/p>\n

    \u9009\u9879\u4e5f\u53ef\u4ee5\u4f7f\u7528 \u200b \u200b\u73af\u5883\u53d8\u91cf\u200b \u200b\u200b \u81ea\u52a8\u586b\u5145\u3002\u4f8b\u5982\uff0c\u5c06 \u200b \u200bARCHIVE\u200b \u200b \u5e38\u91cf\u6539\u4e3a\u4e00\u4e2a\u9009\u9879\uff1a<\/p>\n

    @click.option('archive', '--archive', default='\/Users\/mark\/archive', envvar='ROTO_ARCHIVE', type=click.Path())<\/pre>\n

    \u4f7f\u7528\u76f8\u540c\u7684\u8def\u5f84\u9a8c\u8bc1\u5668\u3002\u8fd9\u4e00\u6b21\uff0c\u8ba9 Click \u586b\u5145\u73af\u5883\u53d8\u91cf\uff0c\u5982\u679c\u73af\u5883\u53d8\u91cf\u6ca1\u6709\u63d0\u4f9b\u4efb\u4f55\u5185\u5bb9\uff0c\u5219\u9ed8\u8ba4\u4e3a\u65e7\u5e38\u91cf\u7684\u503c\u3002<\/p>\n

    Click \u53ef\u4ee5\u505a\u66f4\u591a\u7684\u4e8b\u60c5\uff0c\u5b83\u6709\u5f69\u8272\u7684\u63a7\u5236\u53f0\u8f93\u51fa\u3001\u63d0\u793a\u548c\u5b50\u547d\u4ee4\uff0c\u53ef\u4ee5\u8ba9\u4f60\u6784\u5efa\u590d\u6742\u7684 CLI \u5de5\u5177\u3002\u6d4f\u89c8 Click \u6587\u6863\u4f1a\u53d1\u73b0\u5b83\u7684\u66f4\u591a\u529f\u80fd\u3002<\/p>\n

    \u73b0\u5728\u6dfb\u52a0\u4e00\u4e9b\u6d4b\u8bd5\u3002<\/p>\n

    \u6d4b\u8bd5<\/strong><\/div>\n

    Click \u5bf9\u4f7f\u7528 CLI \u8fd0\u884c\u5668 \u200b \u200b\u8fd0\u884c\u7aef\u5230\u7aef\u6d4b\u8bd5\u200b \u200b\u200b \u63d0\u4f9b\u4e86\u4e00\u4e9b\u5efa\u8bae\u3002\u4f60\u53ef\u4ee5\u7528\u5b83\u6765\u5b9e\u73b0\u4e00\u4e2a\u5b8c\u6574\u7684\u6d4b\u8bd5\uff08\u5728 \u200b \u200b\u793a\u4f8b\u9879\u76ee\u200b \u200b\u200b \u4e2d\uff0c\u6d4b\u8bd5\u5728 \u200b \u200btests\u200b \u200b \u6587\u4ef6\u5939\u4e2d\u3002\uff09<\/p>\n

    \u6d4b\u8bd5\u4f4d\u4e8e\u6d4b\u8bd5\u7c7b\u7684\u4e00\u4e2a\u65b9\u6cd5\u4e2d\u3002\u5927\u591a\u6570\u7ea6\u5b9a\u4e0e\u6211\u5728\u5176\u4ed6 Python \u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u975e\u5e38\u63a5\u8fd1\uff0c\u4f46\u6709\u4e00\u4e9b\u7ec6\u8282\uff0c\u56e0\u4e3a rotoscope \u4f7f\u7528 \u200b \u200bclick\u200b \u200b\u200b\u3002\u5728 \u200b \u200btest\u200b \u200b\u200b \u65b9\u6cd5\u4e2d\uff0c\u6211\u521b\u5efa\u4e86\u4e00\u4e2a \u200b \u200bCliRunner\u200b \u200b\u200b\u3002\u6d4b\u8bd5\u4f7f\u7528\u5b83\u5728\u4e00\u4e2a\u9694\u79bb\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\u8fd0\u884c\u6b64\u547d\u4ee4\u3002\u7136\u540e\u6d4b\u8bd5\u5728\u9694\u79bb\u7684\u6587\u4ef6\u7cfb\u7edf\u4e2d\u521b\u5efa \u200b \u200bincoming\u200b \u200b\u200b \u548c \u200b \u200barchive\u200b \u200b\u200b \u76ee\u5f55\u548c\u4e00\u4e2a\u865a\u62df\u7684 \u200b \u200bincoming\/test.txt\u200b \u200b\u200b \u6587\u4ef6\uff0c\u7136\u540e\u5b83\u8c03\u7528 CliRunner\uff0c\u5c31\u50cf\u4f60\u8c03\u7528\u547d\u4ee4\u884c\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u3002\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u6d4b\u8bd5\u4f1a\u68c0\u67e5\u9694\u79bb\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5e76\u9a8c\u8bc1 \u200b \u200bincoming\u200b \u200b\u200b \u4e3a\u7a7a\uff0c\u5e76\u4e14 \u200b \u200barchive\u200b \u200b \u5305\u542b\u4e24\u4e2a\u6587\u4ef6\uff08\u6700\u65b0\u94fe\u63a5\u548c\u5b58\u6863\u6587\u4ef6\uff09\u3002<\/p>\n

    from os import listdir, mkdir\r\nfrom click.testing import CliRunner\r\nfrom rotoscope.rotoscope import rotoscope\r\n \r\nclass TestRotoscope:\r\n    def test_roto_good(self, tmp_path):\r\n        runner = CliRunner()\r\n \r\n        with runner.isolated_filesystem(temp_dir=tmp_path) as td:\r\n            mkdir(\"incoming\")\r\n            mkdir(\"archive\")\r\n            with open(\"incoming\/test.txt\", \"w\") as f:\r\n                f.write(\"hello\")\r\n \r\n            result = runner.invoke(rotoscope, [\"incoming\", \"--archive\", \"archive\"])\r\n            assert result.exit_code == 0\r\n \r\n            print(td)\r\n            incoming_f = listdir(\"incoming\")\r\n            archive_f = listdir(\"archive\")\r\n            assert len(incoming_f) == 0\r\n            assert len(archive_f) == 2<\/pre>\n

    \u8981\u5728\u63a7\u5236\u53f0\u4e0a\u6267\u884c\u8fd9\u4e9b\u6d4b\u8bd5\uff0c\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\u8fd0\u884c \u200b \u200btox\u200b \u200b\u3002<\/p>\n

    \u5728\u6267\u884c\u6d4b\u8bd5\u671f\u95f4\uff0c\u6211\u5728\u4ee3\u7801\u4e2d\u53d1\u73b0\u4e86\u4e00\u4e2a\u9519\u8bef\u3002\u5f53\u6211\u8fdb\u884c Click \u8f6c\u6362\u65f6\uff0c\u200b \u200brotoscope\u200b \u200b \u53ea\u662f\u53d6\u6d88\u4e86\u6700\u65b0\u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u65e0\u8bba\u5b83\u662f\u5426\u5b58\u5728\u3002\u6d4b\u8bd5\u4ece\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u7cfb\u7edf\uff08\u4e0d\u662f\u6211\u7684\u4e3b\u6587\u4ef6\u5939\uff09\u5f00\u59cb\uff0c\u5f88\u5feb\u5c31\u5931\u8d25\u4e86\u3002\u6211\u53ef\u4ee5\u901a\u8fc7\u5728\u4e00\u4e2a\u5f88\u597d\u7684\u9694\u79bb\u548c\u81ea\u52a8\u5316\u6d4b\u8bd5\u73af\u5883\u4e2d\u8fd0\u884c\u6765\u9632\u6b62\u8fd9\u79cd\u9519\u8bef\u3002\u8fd9\u5c06\u907f\u514d\u5f88\u591a\u201c\u5b83\u5728\u6211\u7684\u673a\u5668\u4e0a\u6b63\u5e38\u5de5\u4f5c\u201d\u7684\u95ee\u9898\u3002<\/p>\n

    \u642d\u5efa\u9aa8\u67b6\u811a\u672c\u548c\u6a21\u5757<\/strong><\/div>\n

    \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 \u200b \u200bscaffold\u200b \u200b\u200b \u548c \u200b \u200bclick\u200b \u200b \u5b8c\u6210\u4e00\u4e9b\u9ad8\u7ea7\u64cd\u4f5c\u3002\u6709\u5f88\u591a\u65b9\u6cd5\u53ef\u4ee5\u5347\u7ea7\u4e00\u4e2a\u666e\u901a\u7684 Python \u811a\u672c\uff0c\u751a\u81f3\u53ef\u4ee5\u5c06\u4f60\u7684\u7b80\u5355\u5b9e\u7528\u7a0b\u5e8f\u53d8\u6210\u6210\u719f\u7684 CLI \u5de5\u5177\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5728\u6211\u7684\u804c\u4e1a\u751f\u6daf\u4e2d\uff0c\u6211\u5199\u8fc7\u3001\u7528\u8fc7\u548c\u770b\u5230\u8fc7\u5f88\u591a\u968f\u610f\u7684\u811a\u672c\u3002\u4e00\u4e9b\u4eba\u9700\u8981\u534a\u81ea\u52a8\u5316\u5b8c\u6210\u4efb\u52a1\uff0c\u4e8e\u662f\u5b83\u4eec\u8bde\u751f\u4e86\u3002\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c […]<\/p>\n","protected":false},"author":668,"featured_media":222378,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-253841","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/253841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=253841"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/253841\/revisions"}],"predecessor-version":[{"id":253844,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/253841\/revisions\/253844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/222378"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=253841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=253841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=253841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}