跳转到主要内容

一个通过一个密钥调用一系列自定义项目命令的工具。

项目描述

项目密钥

项目密钥是一个框架,允许您使用Python编写自文档化的命令套件来自动化常见的项目任务。

然后您可以通过使用“k”键从项目中的任何文件夹运行这些命令。

例如

$ k help
Usage: k command [args]

Yourproject development environment commands.

                runserver - Run django debug web server on port 8000
                    shell - Run django shell.
                  upgrade - pip upgrade on all packages and freeze to requirements afterwards.
                     smtp - Run development smtp server on port 25025.
  striptrailingwhitespace - strip the trailing whitespace from all files in your mercurial repo.
              inspectfile - Inspect file(s) for pylint violations.

Run 'k help [command]' to get more help on a particular command.

三步快速入门

步骤1:按如下方式安装

$ sudo pip install projectkey

步骤2:在项目的根目录下创建一个名为key.py的文件,如下所示

#!/usr/bin/python
"""Yourproject development environment commands."""
from projectkey import cd, run, run_return, runnable, ignore_ctrlc

def runserver():
    """Run django debug web server on port 8080."""
    print "Running webserver..."
    # Run simple shell commands, assuming you are in the same directory as your key.py file.
    run("./venv/bin/python manage.py runserver_plus 8080 --traceback --settings=yourproject.special_settings")

@ignore_ctrlc       # Projectkey will ignore the user pressing ctrl-C when running this command
def shell():
    """Run django shell."""
    print "Running shell..."
    # ...since you want the python shell to decide what to do with Ctrl-C.
    run("./venv/bin/python manage.py shell --settings=yourproject.special_settings")

def upgrade():
    """pip upgrade on all packages and freeze to requirements afterwards."""
    # Copy and paste in whole bash scripts if you like...
    run("""
        ./venv/bin/pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs ./venv/bin/pip install -U
        ./venv/bin/pip freeze > ./requirements.txt
    """)

def smtp():
    """Run development smtp server on port 25025."""
    print "Running SMTP server..."
    run("python -m smtpd -n -c DebuggingServer localhost:25025")

def striptrailingwhitespace():
    """strip the trailing whitespace from all files in your mercurial repo."""
    # Get the output of shell commands...
    repofiles = run_return("hg locate *.py").split('\n')

    # ...and write simple, short, python scripts to do stuff with it.
    repofiles.remove('')
    for filename in repofiles:
        with open(filename, 'r') as fh:
            new = [line.rstrip() for line in fh]
        with open(filename, 'w') as fh:
            [fh.write('%s\n' % line) for line in new]

def inspectfile(*filenames):
    """Inspect file(s) for pylint violations."""
    # You can also change to the directory that the k command was run from, if you need that.
    cd(CWD)
    run("{0}/venv/bin/pylint --rcfile={0}/pylintrc -r n {1}".format(KEYDIR, ' '.join(filenames)))

# Add this and you can run the file directly (e.g. python key.py smtp) as well as by running "k smtp".
runnable(__name__)

步骤3:在项目的任何文件夹中运行“k”命令

$ k inspectfile onefile.py twofiles.py
[ Runs pylint on those files ]

步骤4:添加更多命令。

功能

  • 自动使用您的文档字符串进行文档。

  • 在任意命令中使用变量KEYDIR或CWD来引用key.py的目录或运行k的目录。

  • 通过命令行传递任何参数给方法(也可以使用可选参数和可变数量的参数)。

  • 自动补全默认工作。

  • 包含快捷命令“run”,可以直接运行shell命令列表,因此您可以直接从现有的shell脚本复制和粘贴。

  • 可以选择性地忽略Ctrl-C(默认情况下它尝试停止并退出)。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分发

projectkey-0.7.1.tar.gz (7.5 kB 查看哈希值)

上传时间

支持