开发团队的领导笨鸟提个建议你一定要来看


L123
Xx 2022-10-08 11:38:55 53082
分类专栏: 资讯
本帖最后由 笨鸟弟弟 于 2014-1-2 22:26 编辑

首先说明我这不是胡说,请不要认为我吐槽,这个字眼很难听的我不喜欢,,我认为我在帮助你,,你认为呢???这下面是优客助手的脚本,在250行---258行你是不是忘记敲击几下键盘了,,ubuntukylin的源你添加在主列表里面,那么密匙他会自己飞回来吗??ubuntukylin添加源是一个特出的情况,这我能理解,密匙好像这里没有给他指令啊???
  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3. BEGIN LICENSE

  4. Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd
  5. This program is free software: you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License version 3, as published
  7. by the Free Software Foundation.

  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranties of
  10. MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
  11. PURPOSE.  See the GNU General Public License for more details.

  12. You should have received a copy of the GNU General Public License along
  13. with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. END LICENSE

  15. import apt
  16. import aptsources.sourceslist
  17. import apt.progress.base as apb
  18. import threading

  19. class FetchProcess(apb.AcquireProgress):
  20.     '''Fetch Process'''
  21.     def __init__(self, sudoDaemon):
  22.         apb.AcquireProgress.__init__(self)
  23.         self.sudoDaemon = sudoDaemon

  24.     def done(self, item):
  25.         print 'all items download finished'
  26.         self.sudoDaemon.software_fetch_signal("down_done", "")

  27.     def fail(self, item):
  28.         print 'download failed'
  29.         self.sudoDaemon.software_fetch_signal("down_fail", "")

  30.     def fetch(self, item):
  31.         print 'one item download finished'
  32.         self.sudoDaemon.software_fetch_signal("down_fetch", "")

  33.     def ims_hit(self, item):
  34.         print 'ims_hit'

  35.     def media_change(self, media, drive):
  36.         print 'media_change'

  37.     def pulse(self, owner):
  38.                  print 'owner: ', owner
  39.                  print 'bytes : ', self.current_bytes
  40.                  print '@@@@@@@@@@@@total : ', self.total_bytes
  41.                  print '%%%%%%%%%%%%item : ', self.current_items
  42.                  print '$$$$$$items : ', self.total_items
  43.                  print 'current_cps: ', self.current_cps
  44.                  print 'elapsed_time: ', self.elapsed_time
  45.                  print 'fetched_bytes: ', self.fetched_bytes
  46.                  print 'last_bytes: ', self.last_bytes
  47.         self.sudoDaemon.software_fetch_signal("down_pulse","download_bytes:" + str(self.current_bytes) + ",total_bytes:" + str(self.total_bytes) + ",download_items:" + str(self.current_items) + ",total_items:" + str(self.total_items))

  48.     def start(self):
  49.          Reset all our values.
  50.         self.current_bytes = 0.0
  51.         self.current_cps = 0.0
  52.         self.current_items = 0
  53.         self.elapsed_time = 0
  54.         self.fetched_bytes = 0.0
  55.         self.last_bytes = 0.0
  56.         self.total_bytes = 0.0
  57.         self.total_items = 0
  58.         print 'fetch progress start ...'
  59.         self.sudoDaemon.software_fetch_signal("down_start", "")

  60.     def stop(self):
  61.         print 'fetch progress stop ...'
  62.         self.sudoDaemon.software_fetch_signal("down_stop", "")


  63. class AptProcess(apb.InstallProgress):
  64.     '''Apt progress'''
  65.     def __init__(self, sudoDaemon):
  66.         apb.InstallProgress.__init__(self)
  67.         self.sudoDaemon = sudoDaemon

  68.     def conffile(self, current, new):
  69.         print 'there is a conffile question'

  70.     def error(self, pkg, errormsg):
  71.         self.sudoDaemon.software_apt_signal("apt_error", "")

  72.     def start_update(self):
  73.         print 'apt process start work'
  74.         self.sudoDaemon.software_apt_signal("apt_start", "")

  75.     def finish_update(self):
  76.         print 'apt process finished'
  77.         self.sudoDaemon.software_apt_signal("apt_stop", "")

  78.     def status_change(self, pkg, percent, status):
  79.         print str(int(percent)) + "%  status : " + status
  80.         self.sudoDaemon.software_apt_signal("apt_pulse", "percent:" + str(int(percent)) + ",status:" + status)

  81. class AptDaemon(threading.Thread):
  82. class AptDaemon():
  83.     def __init__(self, sudoDaemon):
  84.         threading.Thread.__init__(self)
  85.         self.sudoDaemon = sudoDaemon
  86.         self.ca = apt.Cache()
  87.         self.ca.open()
  88.                  self.pkgNameList = []
  89.                  for pkg in self.ca:
  90.                          self.pkgNameList.append(pkg.name)

  91.     apt-get update
  92.     def apt_get_update(self):
  93.         self.ca.update(fetch_progress=FetchProcess(self.sudoDaemon))

  94.     apt-get update
  95.     def apt_get_update(self):
  96.         threading.Thread(target=self.apt_get_update_thread, name='AptUpdate').start()

  97.     get package by pkgName
  98.     def get_pkg_by_name(self, pkgName):
  99.         try:
  100.             return self.ca[pkgName]
  101.         except Exception, e:
  102.             print e
  103.             return "ERROR"

  104.     install package
  105.     def install_pkg(self, pkgName):
  106.         self.ca.open()
  107.         pkg = self.get_pkg_by_name(pkgName)
  108.         pkg.mark_install()

  109.         try:
  110.             self.ca.commit(FetchProcess(self.sudoDaemon), AptProcess(self.sudoDaemon))
  111.         except Exception, e:
  112.             print e
  113.             print "install err"

  114.     install package
  115.     def install_pkg(self, pkgName):
  116.         threading.Thread(target=self.install_pkg_thread, args=(pkgName,), name='PkgInstall').start()

  117.     uninstall package
  118.     def uninstall_pkg(self, pkgName):
  119.         self.ca.open()
  120.         pkg = self.get_pkg_by_name(pkgName)
  121.         pkg.mark_delete()

  122.         try:
  123.             self.ca.commit(None, AptProcess(self.sudoDaemon))
  124.         except Exception, e:
  125.             print e
  126.             print "uninstall err"

  127.     uninstall package
  128.     def uninstall_pkg(self, pkgName):
  129.         threading.Thread(target=self.uninstall_pkg_thread, args=(pkgName,), name='PkgUninstall').start()

  130.     update package
  131.     def update_pkg(self, pkgName):
  132.         self.ca.open()
  133.         pkg = self.get_pkg_by_name(pkgName)
  134.         pkg.mark_upgrade()

  135.         try:
  136.             self.ca.commit(FetchProcess(self.sudoDaemon), AptProcess(self.sudoDaemon))
  137.         except Exception, e:
  138.             print e
  139.             print "update err"

  140.     update package
  141.     def update_pkg(self, pkgName):
  142.         threading.Thread(target=self.update_pkg_thread, args=(pkgName,), name='PkgUpgrade').start()

  143.     check package status by pkgName, i = installed u = can update n = notinstall
  144.     def check_pkg_status(self, pkgName):
  145.         self.ca.open()
  146.         pkg = self.get_pkg_by_name(pkgName)
  147.         if(pkg == "ERROR"):
  148.             return "ERROR"
  149.         if(pkg.is_installed):
  150.             if(pkg.is_upgradable):
  151.                 return "u"
  152.             else:
  153.                 return "i"
  154.         else:
  155.             return "n"

  156.     check packages status by pkgNameList, i = installed u = can update n = notinstall
  157.     def check_pkgs_status(self, pkgNameList):
  158.         self.ca.open()
  159.         pkgStatusDict = {}
  160.         for pkgName in pkgNameList:
  161.             pkg = self.get_pkg_by_name(pkgName)
  162.             if(pkg == "ERROR"):
  163.                 continue
  164.             if(pkg.is_installed):
  165.                 if(pkg.is_upgradable):
  166.                     pkgStatusDict[pkgName] = "u"
  167.                 else:
  168.                     pkgStatusDict[pkgName] = "i"
  169.             else:
  170.                 pkgStatusDict[pkgName] = "n"

  171.         return pkgStatusDict

  172.     check packages status by pkgNameList, i = installed u = can update n = notinstall
  173.     def check_pkgs_status_rtn_list(self, pkgNameList):
  174.         self.ca.open()
  175.         pkgStatusList = []
  176.         for pkgName in pkgNameList:
  177.             pkg = self.get_pkg_by_name(pkgName)
  178.             if(pkg == "ERROR"):
  179.                     continue
  180.             if(pkg.is_installed):
  181.                 if(pkg.is_upgradable):
  182.                     pkgStatusList.append(pkgName + ":u")
  183.                 else:
  184.                     pkgStatusList.append(pkgName + ":i")
  185.             else:
  186.                 pkgStatusList.append(pkgName + ":n")

  187.         self.sudoDaemon.software_check_status_signal(pkgStatusList)
  188.         return pkgStatusList

  189.     check packages status by pkgNameList, i = installed u = can update n = notinstall
  190.     def check_pkgs_status_rtn_list(self, pkgNameList):
  191.         threading.Thread(target=self.check_pkgs_status_rtn_list_thread, args=(pkgNameList,), name='PkgStatusList').start()

  192.          def get_pkgs_name_list(self):
  193.                  return self.pkgNameList

  194.          def search_pkgs_name(self, pkgName):
  195.                  if pkgName in self.pkgNameList:
  196.                          return pkgName
  197.                  else:
  198.                          rtns = []
  199.                          for name in self.pkgNameList:
  200.                                  if name.find(pkgName) >= 0:
  201.                                          rtns.append(name)
  202.                          return rtns

  203.     get all source item in /etc/apt/sources.list
  204.     def get_sources(self):
  205.         source = aptsources.sourceslist.SourcesList()
  206.         return source.list

  207.     add ubuntukylin source in /etc/apt/sources.list
  208.     def add_source_ubuntukylin(self):
  209.         source = aptsources.sourceslist.SourcesList()
  210.         for item in source.list:
  211.             if(item.str().find("deb http://archive.ubuntukylin.com/ubuntukylin") != -1):
  212.                 return

  213.         source.add("deb", "http://archive.ubuntukylin.com/ubuntukylin/", "raring main", "")
  214.         source.save()

  215.     remove ubuntukylin source in /etc/apt/sources.list
  216.     def remove_source_ubuntukylin(self):
  217.         source = aptsources.sourceslist.SourcesList()
  218.         sources = source.list
  219.         for item in sources:
  220.             if(item.str().find("deb http://archive.ubuntukylin.com/ubuntukylin") != -1):
  221.                 source.remove(item)
  222.         source.save()

  223. if __name__ == "__main__":
  224.     ad = AptDaemon(None)

  225.          print ad.check_pkgs_status(["gedit", "cairo-dock", "unity"])
  226.         print ad.check_pkgs_status_rtn_list(["gedit", "cairo-dock", "unity", "haha", "hehe"])
  227.          ad.apt_get_update()
  228.     ad.add_source_ubuntukylin()
  229.          ad.remove_source_ubuntukylin()

  230.     while True:
  231.         print "\ninput your command: "
  232.         cmd = raw_input()
  233.         if cmd == "l":
  234.             for name in ad.pkgNameList:
  235.                 print name + "\n"
  236.         elif cmd == "i":
  237.             print "input pkgName to install: "
  238.             pkgName = raw_input()
  239.             ad.install_pkg(pkgName)
  240.         elif cmd == "n":
  241.             print "input pkgName to uninstall: "
  242.             pkgName = raw_input()
  243.             ad.uninstall_pkg(pkgName)
  244.         elif cmd == "u":
  245.             print "input pkgName to update: "
  246.             pkgName = raw_input()
  247.             ad.update_pkg(pkgName)
  248.         elif cmd == "c":
  249.             print "input pkgName to check status: "
  250.             pkgName = raw_input()
  251.             print ad.check_pkg_status(pkgName)
  252.         else:
  253.             print "nothing..."

  254.          print ad.get_pkg_by_name('gedit')
  255.     pnl = ad.getpkglist()
  256.     print len(pnl)
  257.          name1 = ad.search_pkgs_name('wesnoth-1.10-core')
  258.          print name1
  259.     print 'aaa' + str(1)
  260.          ad.install_pkg(name1)
  261.          ad.uninstall_pkg(name1)
  262.     p = ad.get_pkg_by_name(name1)
  263.     print p.id
  264.     c = AptCache()
  265.     c.hahaha()
  266.     print c.hahaha()
  267.     pkgs = []
  268.     ca = apt.Cache()
  269.     i = 0
  270.     for a in ca:
  271.              i += 1
  272.              pkgs.append(a.name)
  273.              print a.name
  274.     print i
  275.     nanop = ca['nano']
  276.     print nanop
  277.     nanop.mark_install()
  278.     ca.commit()
我要挑毛病挑对了,给我点积分我认钱,微软挖漏洞的无论大小都有奖励的,我不要人民我要麒麟币,还有铮亮的纽扣挂我的头像下面,,

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=18226
赞同 0
评论 0 条
XxL0
粉丝 0 发表 7 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2944
【软件正版化】软件正版化工作要点  2864
统信UOS试玩黑神话:悟空  2823
信刻光盘安全隔离与信息交换系统  2718
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1251
grub引导程序无法找到指定设备和分区  1217
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  164
点击报名 | 京东2025校招进校行程预告  163
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  161
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!