def enableSection(self, apturl): added = False # parse sources.list sourceslist = SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sourceslist) # check if we actually need to enable anything requested_components = [] for component in apturl.section: if not component in distro.enabled_comps: requested_components.append(component) # if not, we are fine if not requested_components: return RESULT_OK # otherwise ask the user if the really wants to anble them if not self.ui.askEnableSections(apturl.section): return RESULT_CANCELT if not self.ui.doEnableSection(apturl.section): self.ui.error(_("Enabling '%s' failed") % ", ".join(apturl.section)) return RESULT_ERROR self.ui.doUpdate() self.openCache() return RESULT_OK
def go_install_drbl(self, widget): if self.linux_dist == "": self.linux_dist = self.get_linux_dist() if self.linux_dist == "not support": return -1 if self.linux_dist == "Fedora": os.system('yum -y install perl-Digest-SHA1') os.system('yum -y install wget') os.system('rm -f GPG-KEY-DRBL') os.system('wget http://drbl.nchc.org.tw/GPG-KEY-DRBL') os.system('rpm --import GPG-KEY-DRBL') os.system('wget http://drbl.nchc.org.tw/one4all/desktop/download/stable/RPMS/drbl-current.i386.rpm') os.system('yum -y install drbl-current.i386.rpm') elif self.linux_dist == "Ubuntu": sourceslist = SourcesList () distro = aptsources.distro.get_distro () try: distro.get_sources (sourceslist) except: print "your distribution is remix release!" return -1 has_drbl_repo = 0 has_drbl_comps = 0 for source in sourceslist: if source.disabled == False: if source.uri == "http://free.nchc.org.tw/drbl-core": has_drbl_repo = 1 if source.comps == self.comps: has_drbl_comps = 1 else: print "remove drbl repo" sourceslist.remove(source) if has_drbl_repo == 0 or has_drbl_comps == 0: drbl_uri = "http://free.nchc.org.tw/drbl-core" drbl_dist = "drbl" drbl_comps = self.comps distro.add_source (type="deb", uri=drbl_uri, dist=drbl_dist, comps=drbl_comps, comment="DRBL Repository (Add by drbl_assistant)") sourceslist.backup () sourceslist.save () add_key_st = os.popen("wget -q http://drbl.nchc.org.tw/GPG-KEY-DRBL -O- | apt-key add -").readlines()[0][:-1] try: cache = apt.Cache() pkg = cache['drbl'] # Access the Package object for python-apt pkg.mark_install() # Now, really install it cache.commit() except: print "apt-get install drbl" os.system("apt-get update") os.system("apt-get install drbl") else: print "Unknown linux" print "install finish"
def areRestrictedComponentsEnabled(self): # Is the restricted driver apt component enabled? distro = aptsources.distro.get_distro() sourceslist = aptsources.sourceslist.SourcesList() try: distro.get_sources(sourceslist) except: return True return 'restricted' in distro.enabled_comps
def testMatcher(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","data/sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() for s in sources: if not s.template: self.fail("source entry '%s' has no matcher" % s)
def testMatcher(self): """aptsources: Test matcher""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro(id="Ubuntu") distro.get_sources(sources) # test if all suits of the current distro were detected correctly for s in sources: if not s.template: self.fail("source entry '%s' has no matcher" % s)
def testMatcher(self): apt_pkg.Config.Set("Dir::Etc::sourcelist","sources.list") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro("Ubuntu","hardy","desc","8.04") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() for s in sources: if not s.line.strip() or s.line.startswith("#"): continue if not s.template: self.fail("source entry '%s' has no matcher" % s)
def testMatcher(self): """aptsources_ports: Test matcher.""" apt_pkg.config.set("Dir::Etc::sourcelist", "sources.list") sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro("Ubuntu", "hardy", "desc", "8.04") distro.get_sources(sources) # test if all suits of the current distro were detected correctly for s in sources: if not s.line.strip() or s.line.startswith("#"): continue if not s.template: self.fail("source entry '%s' has no matcher" % s)
def testDistribution(self): """aptsources: Test distribution detection.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro(id="Ubuntu", codename="bionic", description="Ubuntu 18.04 LTS", release="18.04") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() for s in sources: if s.template: dist_templates.add(s.template.name) #print dist_templates for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", "hardy-backports"): self.assertTrue(d in dist_templates) # test enable comp = "restricted" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and "edgy" in entry.dist): for c in entry.comps: if c == comp: if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) for key in found: self.assertEqual(found[key], 1) # add a not-already available component comp = "multiverse" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.template and entry.template.name == "edgy"): for c in entry.comps: if c == comp: if entry.dist not in found.has_key: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) for key in found: self.assertEqual(found[key], 1)
def testDistribution(self): """aptsources: Test distribution detection.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list.testDistribution") sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro(id="Ubuntu") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() for s in sources: if s.template: dist_templates.add(s.template.name) #print dist_templates for d in ("hardy", "hardy-security", "hardy-updates", "intrepid", "hardy-backports"): self.assertTrue(d in dist_templates) # test enable comp = "restricted" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and "edgy" in entry.dist): for c in entry.comps: if c == comp: if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) for key in found: self.assertEqual(found[key], 1) # add a not-already available component comp = "multiverse" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.template and entry.template.name == "edgy"): for c in entry.comps: if c == comp: if entry.dist not in found.has_key: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) for key in found: self.assertEqual(found[key], 1)
def testDistribution(self): apt_pkg.config.set("Dir::Etc::sourcelist", self.sources_list + ".testDistribution") sources = aptsources.sourceslist.SourcesList() distro = aptsources.distro.get_distro(codename="edgy") distro.get_sources(sources) # test if all suits of the current distro were detected correctly dist_templates = set() for s in sources: if s.template: dist_templates.add(s.template.name) #print(dist_templates) for d in ["edgy", "edgy-security", "edgy-updates", "hoary"]: self.assertTrue(d in dist_templates) # test enable comp = "restricted" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.uri == "http://de.archive.ubuntu.com/ubuntu/" and "edgy" in entry.dist): for c in entry.comps: if c == comp: if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print("".join([s.str() for s in sources])) for key in found: self.assertEqual(found[key], 1) # add a not-already available component comp = "multiverse" distro.enable_component(comp) found = {} for entry in sources: if (entry.type == "deb" and entry.template and entry.template.name == "edgy"): for c in entry.comps: if c == comp: if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print("".join([s.str() for s in sources])) for key in found: self.assertEqual(found[key], 1)
def main (): uri = sys.argv[1].strip () dist = sys.argv[2].strip () comps = sys.argv[3].split (' ') comment = sys.argv[4].strip () distro = aptsources.distro.get_distro () sourceslist = SourcesList () for source in sourceslist: if source.disabled == False: if source.uri == uri and source.comps == comps: print "套件庫已存在。" else: distro.get_sources (sourceslist) distro.add_source (uri=uri, dist=dist, comps=comps, comment=comment) sourceslist.backup () sourceslist.save () return 0
def test_enable_component(self): target = "./data/aptsources/sources.list.enable_comps" line = "deb http://archive.ubuntu.com/ubuntu lucid main\n" with open(target, "w") as target_file: target_file.write(line) apt_pkg.config.set("Dir::Etc::sourcelist", target) sources = aptsources.sourceslist.SourcesList(True, self.templates) distro = aptsources.distro.get_distro(id="Ubuntu") # make sure we are using the right distro distro.codename = "lucid" distro.id = "Ubuntu" distro.release = "10.04" # and get the sources distro.get_sources(sources) # test enable_component comp = "multiverse" distro.enable_component(comp) comps = set() for entry in sources: comps = comps.union(set(entry.comps)) self.assertTrue("multiverse" in comps) self.assertTrue("universe" in comps)
def test_mirrors(mirrors_list): distro = aptsources.distro.get_distro() distro.get_sources(SourcesList()) pipe = os.popen("dpkg --print-architecture") arch = pipe.read().strip() test_file = "dists/%s/%s/binary-%s/Packages.gz" % \ ( #distro.source_template.name, "quantal", distro.source_template.components[0].name, arch) app = MirrorTest(mirrors_list, test_file, ) results = app.run_download_test() winner = [100, None] print results for r in results: if r[0] < winner[0]: winner = r return winner
def main(): uri = sys.argv[1].strip() dist = sys.argv[2].strip() comps = sys.argv[3].split(' ') comment = sys.argv[4].strip() distro = aptsources.distro.get_distro() sourceslist = SourcesList() for source in sourceslist: if source.disabled == False: if source.uri == uri and source.comps == comps: print "套件庫已存在。" else: distro.get_sources(sourceslist) distro.add_source(uri=uri, dist=dist, comps=comps, comment=comment) sourceslist.backup() sourceslist.save() return 0
def enableSection(self, apturl): # parse sources.list sourceslist = SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sourceslist) # check if we actually need to enable anything requested_components = [] for component in apturl.section: if not component in distro.enabled_comps: requested_components.append(component) # if not, we are fine if not requested_components: return RESULT_OK # otherwise ask the user if the really wants to anble them if not self.ui.askEnableSections(apturl.section): return RESULT_CANCELT if not self.ui.doEnableSection(apturl.section): self.ui.error(_("Enabling '%s' failed") % ", ".join(apturl.section)) return RESULT_ERROR self.ui.doUpdate() self.openCache() return RESULT_OK
for m in mirrors: if not self.running.isSet(): break download_time = test_download_speed(m) if download_time > 0: results.append([download_time, m]) self.report_progress(mirrors.index(m) + 1, len(mirrors), (0.50,1), mod) results.sort() return results[0:max] def run(self): """Complete test exercise, set self.best when done""" self.best = self.run_full_test() self.running.clear() if __name__ == "__main__": distro = aptsources.distro.get_distro() distro.get_sources(aptsources.sourceslist.SourcesList()) pipe = os.popen("dpkg --print-architecture") arch = pipe.read().strip() running = threading.Event() running.set() test_file = "dists/%s/%s/binary-%s/Packages.gz" % \ (distro.source_template.name, distro.source_template.components[0].name, arch) app = MirrorTest(list(distro.source_template.mirror_set.values()), test_file, threading.Event(), running) app.run_full_test()
#! /usr/bin/python import aptsources.distro from aptsources.sourceslist import SourcesList, SourceEntry list=SourcesList() distro=aptsources.distro.get_distro() distro.get_sources(list) distro.enable_component("universe") distro.enable_component("multiverse") list.save()
def main (): comps = [] sourceslist = SourcesList () distro = aptsources.distro.get_distro () security_uri = "" security_dist = "" if distro.id == "Debian": comps = ["main", "contrib", "non-free"] security_uri = "http://security.debian.org/" security_dist = "%s/updates" % distro.codename elif distro.id == "Ubuntu": comps = ["main", "universe", "restricted", "multiverse"] security_uri = "http://security.ubuntu.com/ubuntu/" security_dist = "%s-security" % distro.codename else: print "can't identify distribution" return -1 try: distro.get_sources (sourceslist) except: print "your distribution is remix release!" return -1 has_medibuntu_source = 0 has_ubuntu_tweak_source = 0 has_swiftfox_source = 0 has_winehq_source = 0 for source in sourceslist: if source.disabled == False: if source.uri == "http://packages.medibuntu.org/": has_medibuntu_source = 1 if source.uri == "http://ppa.launchpad.net/tualatrix/ubuntu": has_ubuntu_tweak_source = 1 if source.uri == "http://getswiftfox.com/builds/debian": has_swiftfox_source = 1 if source.uri == "http://wine.budgetdedicated.com/apt": has_winehq_source = 1 [entry.set_enabled (False) for entry in sourceslist if entry.invalid == False] if distro.country_code == "tw" and distro.id == "Ubuntu": twaren_uri = "http://ftp.twaren.net/ubuntu" distro.change_server (uri=twaren_uri) distro.add_source (uri=twaren_uri, comps=comps, comment="國網中心伺服器 (Lazybuntu 新增)") distro.add_source (type="deb-src", uri=twaren_uri, comps=comps, comment="國網中心伺服器 (Lazybuntu 新增)") else: distro.add_source (uri=distro.nearest_server, comps=comps, comment="地區性伺服器 (Lazybuntu 新增)") distro.add_source (type="deb-src", uri=distro.nearest_server, comps=comps, comment="地區性伺服器 (Lazybuntu 新增)") distro.add_source (uri=security_uri, dist=security_dist, comps=comps, comment="安全性更新伺服器 (Lazybuntu 新增)") distro.add_source (type="deb-src", uri=security_uri, dist=security_dist, comps=comps, comment="安全性更新伺服器 (Lazybuntu 新增)") if has_medibuntu_source: medibuntu_uri = "http://packages.medibuntu.org/" medibuntu_comps = ["free non-free"] distro.add_source (uri=medibuntu_uri, comps=medibuntu_comps, comment="Medibuntu Install Source (Lazybuntu 新增)") if has_ubuntu_tweak_source: ubuntu_tweak_uri = "http://ppa.launchpad.net/tualatrix/ubuntu" ubuntu_tweak_comps = ["main"] if distro.codename == 'intrepid': ubuntu_tweak_dist = distro.codename else: ubuntu_tweak_dist = 'hardy' distro.add_source (uri=ubuntu_tweak_uri, dist=ubuntu_tweak_dist, comps=ubuntu_tweak_comps, comment="Ubuntu Tweak Install Source (Lazybuntu 新增)") distro.add_source (type="deb-src", uri=ubuntu_tweak_uri, dist=ubuntu_tweak_dist, comps=ubuntu_tweak_comps, comment="Ubuntu Tweak Install Source (Lazybuntu 新增)") if has_swiftfox_source: swiftfox_uri = "http://getswiftfox.com/builds/debian" swiftfox_comps = ["non-free"] swiftfox_dist = "unstable" distro.add_source (uri=swiftfox_uri, dist=swiftfox_dist, comps=swiftfox_comps, comment="Swiftfox Install Source (Lazybuntu 新增)") if has_winehq_source: winehq_uri = "http://wine.budgetdedicated.com/apt" winehq_comps = ["main"] distro.add_source (uri=winehq_uri, comps=winehq_comps, comment="WineHQ Install Source (Lazybuntu 新增)") sourceslist.backup () sourceslist.save () return 0
#!/usr/bin/python import sys try: import aptsources import aptsources.distro from aptsources.sourceslist import SourcesList except: sys.exit(2) sourceslist = SourcesList() sourceslist.refresh() distro = aptsources.distro.get_distro() distro.get_sources(sourceslist) sys.exit(0 if sys.argv[1] in distro.download_comps else 1)