pycommands帮助您构建系统远程调用命令

pycommands的Python项目详细描述


pycommands

CircleCICodecov

处理应易于执行且支持撤消的命令列表。

如何使用

安装

pypi上提供pycommands

pip install pycommands

基本用法

命令的定义
fromcommands.baseimportBaseCommandfromcommands.exceptionsimportCommandExceptionfromcommands.invokerimportInvokerclassCommand1(BaseCommand):defbuild(self):return"touch content.txt"defbuild_undo(self):return"rm content.txt"classCommand2(BaseCommand):defbuild(self):return"mv content.txt content-replaced.txt"defbuild_undo(self):return"mv content-replaced.txt content.txt"classInvalidCommand(BaseCommand):defbuild(self):raiseCommandException()

使用success命令进行简单的默认执行

fromcommands.invokerimportInvokerinvoker=Invoker()invoker.execute([Command1(),Command2(),],run_undo=False)# outputrunningcommand:touchcontent.txtrunningcommand:mvcontent.txtcontent-replaced.txt# If a invoker.undo() is called then all commands undo operation will be done in the LIFO order.invoker.undo()# outputrunningundocommand:mvcontent-replaced.txtcontent.txtrunningundocommand:rmcontent.txt# If a invoker.execute() is called with run_undo as True, then the undo operation will be done always# that a command raise CommandExceptioninvoker=Invoker()invoker.execute([Command1(),Command2(),InvalidCommand(),],run_undo=True)# outputrunningcommand:touchcontent.txtrunningcommand:mvcontent.txtcontent-replaced.txtrunningcommand:touchcontent.txtrunningcommand:mvcontent.txtcontent-replaced.txtrunningundocommand:mvcontent-replaced.txtcontent.txtrunningundocommand:rmcontent.txt

如何贡献

我们欢迎多种形式的投稿,例如:

  • 代码(通过提交请求)
  • 文档改进
  • 错误报告和功能请求

为当地发展而设立

我们使用pipenv来管理依赖项,因此请确保您已经安装了它。

创建环境

/<project-path>/pipenv install --python=3

活动环境

/<project-path>/pipenv shell

安装预提交挂钩:

pre-commit install

通过调用pytest运行测试:

pytest

就这样!您已经准备好进行开发了

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何修复使用高停止条件时的StackOverflowerError   java两个非常好的int被除掉,仍然返回0   java将SpringWeb应用程序(Web.xml)迁移到Springboot 1.5.10   java使用CQL查询的结果集检索整行   java Solr 7:当某些请求命中Solr时,QueuedThreadPool线程数很高   在ActionListener中访问另一个类时发生java NullPointerException   异常处理Java重构类似方法的代码   java Hi我需要帮助在我的JSP页面中传输图像   Android中的java工作线程   覆盖字段值的JavaDB模型策略   带有resteasy的java Spring引导“找不到名为requestMappingHandlerMapping的bean的类型”错误   java如何插入(int)和(date)类型?   Java Swing计时器和ActionEvent   java运行一个没有jUnit作为运行选项的类   java通过解析异常来获取方法名及其包含的参数   与枚举匹配的java Get-from列表元素   我的程序中出现java内存不足错误   java在C中创建jobject不起作用   如何在java中测试这个void方法?