python中apt简单使用工具,pythonapt工具,python中apt简单
python中apt简单使用工具,pythonapt工具,python中apt简单
python中apt简单使用工具,这是将apt-get、apt-cache合并在一起使用的方法。
apt-tool -s xxxx :显示查找内容并进行安装交互
apt-tool -i xxxx :安装所选项
apt-tool -s -q xxxx :只显示查找内容
#!/usr/bin/env python#-*-: coding: utf-8 -*-import optparseimport subprocessimport sysimport localeimport osclass Apt(object):def __init__(self, opts):self.options = optsdef apt_install(self, opts, listone=""):soft = opts.install if listone == "" else listoneos.system("apt-get install %s" % soft)def apt_search(self, opts):list_buf = []cout = 0ret = subprocess.Popen("apt-cache search %s | awk -F' ' '{print $1}'" % opts.search, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)if ret == 0:print "commad error !"sys.exit(125)output = ret.stdout.readlines()print '-'*31for out in output:print "%d\t%s" % (cout, out.strip())list_buf.append(out.strip())cout += 1print '-'*10 + "DONE!" + '-'*10if opts.quiet:sys.exit(0)else:try:num = input("Intput software number : ")except KeyboardInterrupt:print "\tUser press Ctrl+C ,Exit\n"sys.exit(125)if num > len(list_buf) and num < 0:print "number is not right !"sys.exit(125)else:self.apt_install(opts, listone=list_buf[num])def run(self):if self.options.install:self.apt_install(self.options)elif self.options.search:self.apt_search(self.options)def parse_cmdline():#www.iplaypy.comp = optparse.OptionParser(description="easy apt tool", prog="apt-tool", version="1.0", usage="%prog [options] dest")p.add_option("-i", "--install", action="store", dest="install", help="software name", type="string")p.add_option("-s", "--search", action="store", dest="search", help="search software", type="string")p.add_option("-q", "--quiet", action="store_true", dest="quiet", help="don't install")(opts, args) = p.parse_args()if not opts.install and not opts.search:print sys.argv[0] + "[-i|-s]" + "software name"return opts, argsdef main():locale.setlocale(locale.LC_ALL, '')opts, args = parse_cmdline()apt = Apt(opts)apt.run()if __name__ == '__main__':main()
编橙之家文章,
相关内容
- django实现简单的数据库内容显示,django实现数据库,dj
- 动态filter查询数据Django实现方法,filterdjango,这是我在学
- Python jpg图片裁剪处理源码,,这个Python jpg
- Python实用又常用函数工具方法分享,python函数,这是我自
- Python shelve方法完成信息录入小工具源码,pythonshelve,此
- Python cookbook守护进程代码示例,pythoncookbook,关于python守
- python自动完成扫描端口使用情况示例,python自动完成
- 如何用python方法检测UDP端口,python检测udp端口,如何用
- Python调用MySQL存储过程,获得返回值示例,pythonmysql,编橙
- Python特定文件备份方法源码示例,,Python备份文件的方
评论关闭