用于运行通过一个键调用的自定义项目命令套件的工具。
projectke的Python项目详细描述
项目键
projectkey是一个框架,它允许您在 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."""fromprojectkeyimportcd,run,run_return,runnable,ignore_ctrlcdefrunserver():"""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 commanddefshell():"""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")defupgrade():"""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 """)defsmtp():"""Run development smtp server on port 25025."""print"Running SMTP server..."run("python -m smtpd -n -c DebuggingServer localhost:25025")defstriptrailingwhitespace():"""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('')forfilenameinrepofiles:withopen(filename,'r')asfh:new=[line.rstrip()forlineinfh]withopen(filename,'w')asfh:[fh.write('%s\n'%line)forlineinnew]definspectfile(*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:添加更多命令。
功能
- 使用docstrings自动生成文档。
- 在任何命令中使用变量keydir或cwd来引用key.py的目录或运行k的目录。
- 通过命令行将任何参数传递给方法(也可以使用可选参数和可变参数数)。
- “自动完成”是现成的。
- 使用快捷命令“Run”直接运行shell命令列表,这样您就可以直接从现有shell脚本复制粘贴。