命令和统治你的壳
sultan的Python项目详细描述
命令和规则覆盖您的shell
sultan现在支持python 2.7+和3.0+
注
欢迎输入!请通过创建 issues on Github
安装
pip install --upgrade sultan
苏丹是什么?
sultan是一个python包,用于与命令行实用程序接口,如 yum,apt get或ls,以一种Python的方式。它允许您运行命令行 使用简单函数调用的实用程序。
使用sultan最简单的方法就是调用它:
fromsultan.apiimportSultans=Sultan()s.sudo("yum install -y tree").run()
运行:
sudo yum install -y tree;
建议使用sultan的方法是在上下文管理模式下使用它。 下面是如何将sultan用于上下文管理:
fromsultan.apiimportSultanwithSultan.load(sudo=True)ass:s.yum("install -y tree").run()
运行:
sudo su - root -c 'yum install -y tree;'
如果我们想在远程计算机上安装这个命令呢?你很容易 使用上下文管理实现此目的:
fromsultan.apiimportSultanwithSultan.load(sudo=True,hostname="myserver.com")assultan:sultan.yum("install -y tree").run()
运行:
ssh root@myserver.com 'sudo su - root -c 'yum install -y tree;''
如果输入了错误的命令,sultan将打印出需要调试和 快点找到问题。
在这里,相同的命令在mac上运行:
fromsultan.apiimportSultanwithSultan.load(sudo=True,hostname="myserver.com")assultan:sultan.yum("install -y tree").run()
收益率:
[sultan]: sudo su - root -c 'yum install -y tree;' Password: [sultan]: --{ STDERR }------------------------------------------------------------------------------------------------------- [sultan]: | -sh: yum: command not found [sultan]: -------------------------------------------------------------------------------------------------------------------
想开始吗?只需安装sultan,然后开始编写干净的代码:
pip install --upgrade sultan
如果你有更多的问题,请查看文档!http://sultan.readthedocs.io/en/latest/