def update_ppa_model(self): self.set_busy() self.__column.set_title('PPA Sources') model = self.get_model() model.clear() self.mode = 'ppa' ppa_source_dict = get_ppa_source_dict() for source in self.get_sourceslist(): if ppa.is_ppa(source.uri) and source.type == 'deb' and not source.disabled: try: id = ppa_source_dict[source.uri] pixbuf = get_source_logo_from_filename(SOURCE_PARSER[id]['logo']) name = SOURCE_PARSER.get_name(id) comment = SOURCE_PARSER.get_summary(id) except: id = source.uri name = ppa.get_short_name(source.uri) comment = ppa.get_homepage(source.uri) pixbuf = get_source_logo_from_filename('') self.total_num += 1 iter = model.append() log.debug("Found an enalbed PPA: %s" % name) model.set(iter, COLUMN_ICON, pixbuf, COLUMN_CHECK, False, COLUMN_NAME, str(id), COLUMN_DESC, '', COLUMN_DISPLAY, '<b>%s</b>\n%s' % (name, comment), ) self.unset_busy()
def set_enable(self, key, enable): # To make other module use the source enable feature, move the logical to here # So that other module can call gpg_key = self.get_key(key) url = self.get_url(key) distro = self.get_distro(key) comps = self.get_comps(key) comment = self.get_name(key) if ppa.is_ppa(url): file_name = '%s-%s' % (ppa.get_source_file_name(url), distro) else: file_name = self.get_slug(key) if gpg_key: proxy.add_apt_key_from_content(gpg_key) if not comps and distro: distro = distro + '/' elif not comps and not distro: distro = './' result = proxy.set_separated_entry(url, distro, comps, comment, enable, file_name) return str(result)
def do_source_operation(self, enable_str, source_json, *args): enable = int(enable_str) source = json.loads(source_json) distro = source['distro_value'] log.debug("Enable? %s for source: %s for distro: %s" % (enable, source['name'], distro)) if ppa.is_ppa(source['url']): file_name = '%s-%s' % (ppa.get_source_file_name(source['url']), distro) else: file_name = source['slug'] # TODO these kinds of source should never be featured if not source['component'] and distro: distro = distro + '/' elif not source['component'] and not distro: distro = './' try: result = proxy.set_separated_entry(source['url'], distro, source['component'], source['summary'], enable, file_name) log.debug("Enable source: %s result: %s" % (source['name'], result)) if source['key']: proxy.add_apt_key_from_content(source['key']) if result == 'enabled': notify = Notify.Notification(summary=_('New source has been enabled'), body=_('"%s" is enabled now, Please click the update button to update %s') % (source['name'], self.current_app)) notify.set_property('icon-name', 'ubuntu-tweak') notify.set_hint_string("x-canonical-append", "true") notify.show() self.update_action_button(self.UPDATE_ACTION) except Exception, e: log.error(e) self.update_sources()
def set_enable(self, key, enable): # To make other module use the source enable feature, move the logical to here # So that other module can call gpg_key = self.get_key(key) url = self.get_url(key) distro = self.get_distro(key) comps = self.get_comps(key) comment = self.get_name(key) if ppa.is_ppa(url): file_name = '%s-%s' % (ppa.get_source_file_name(url), distro) else: file_name = self.get_slug(key) if gpg_key: proxy.add_apt_key_from_content(gpg_key) if not comps and distro: distro = distro + '/' elif not comps and not distro: distro = './' if TweakSettings.get_separated_sources(): result = proxy.set_separated_entry(url, distro, comps, comment, enable, file_name) else: result = proxy.set_entry(url, distro, comps, comment, enable) return str(result)
class Daemon(PolicyKitService): #TODO use signal liststate = None list = SourcesList() # cache = apt.Cache() stable_url = 'http://ppa.launchpad.net/tualatrix/ppa/ubuntu' ppa_list = [] p = None SOURCES_LIST = '/etc/apt/sources.list' def __init__(self, bus, mainloop): bus_name = dbus.service.BusName(INTERFACE, bus=bus) PolicyKitService.__init__(self, bus_name, PATH) self.mainloop = mainloop @dbus.service.method(INTERFACE, in_signature='b', out_signature='bv') def check_sources_is_valid(self, convert_source): try: if not os.path.exists(self.SOURCES_LIST): os.system('touch %s' % self.SOURCES_LIST) except Exception, e: log.error(e) self.list.refresh() to_add_entry = [] to_rm_entry = [] disabled_list = [''] for entry in self.list: entry_line = entry.str().strip() if entry.invalid and not entry.disabled and entry_line and not entry_line.startswith( '#'): try: entry.set_enabled(False) except Exception, e: log.error(e) if entry.file not in disabled_list: disabled_list.append(entry.file) continue if convert_source: if os.path.basename(entry.file) == 'sources.list': continue log.debug("Check for url: %s, type: %s, filename: %s" % (entry.uri, entry.type, entry.file)) if ppa.is_ppa(entry.uri): filename = '%s-%s.list' % (ppa.get_source_file_name( entry.uri), entry.dist) if filename != os.path.basename(entry.file): log.debug("[%s] %s need rename to %s" % (entry.type, entry.file, filename)) to_rm_entry.append(entry) if os.path.exists(entry.file): log.debug("%s is exists, so remove it" % entry.file) os.remove(entry.file) entry.file = os.path.join(os.path.dirname(entry.file), filename) to_add_entry.append(entry)
def enable_ppa(self): self.list.refresh() for source in self.list: url = source.uri if ppa.is_ppa(url) and url in self.ppa_list: source.set_enabled(True) self.list.save()
def test_ppa(self): self.assertTrue(ppa.is_ppa(self.ppa_archive_url)) list_name = ppa.get_list_name(self.ppa_archive_url) self.failUnless(list_name == '' or list_name.startswith('/var/lib/apt/lists/')) self.assertEqual(ppa.get_short_name(self.ppa_archive_url), 'ppa:tualatrix/ppa') self.assertEqual(ppa.get_homepage(self.ppa_archive_url), self.ppa_home_url)
def disable_ppa(self): self.list.refresh() self.ppa_list = [] for source in self.list: if ppa.is_ppa(source.uri) and not source.disabled: self.ppa_list.append(source.uri) source.set_enabled(False) self.list.save()
def get_cruft(self): count = 0 for source in SourcesList(): if ppa.is_ppa(source.uri) and source.type == 'deb' and not source.disabled: count += 1 name = ppa.get_short_name(source.uri) self.emit('find_object', PPAObject(source.uri, name)) self.emit('scan_finished', True, count, 0)
def set_details(self, homepage='http://ubuntu-tweak.com', url='http://ubuntu-tweak.com', description=None): self.homepage_button.set_label(homepage) self.homepage_button.set_uri(homepage) if ppa.is_ppa(url): url = ppa.get_homepage(url) self.url_button.set_label(url) self.url_button.set_uri(url) self.description_label.set_text(description or _('Description is here'))
def set_details(self, homepage=None, url=None, description=None): if homepage: self.homepage_button.destroy() self.homepage_button = gtk.LinkButton(homepage, homepage) self.homepage_button.show() self.table.attach(self.homepage_button, 1, 2, 0, 1) if url: if ppa.is_ppa(url): url = ppa.get_homepage(url) self.url_button.destroy() self.url_button = gtk.LinkButton(url, url) self.url_button.show() self.table.attach(self.url_button, 1, 2, 1, 2) if description: self.description.set_text(description)
def set_details(self, homepage = None, url = None, description = None): if homepage: self.homepage_button.destroy() self.homepage_button = gtk.LinkButton(homepage, homepage) self.homepage_button.show() self.table.attach(self.homepage_button, 1, 2, 0, 1) if url: if ppa.is_ppa(url): url = ppa.get_homepage(url) self.url_button.destroy() self.url_button = gtk.LinkButton(url, url) self.url_button.show() self.table.attach(self.url_button, 1, 2, 1, 2) if description: self.description.set_text(description)
def set_details(self, homepage=None, url=None, description=None): self.homepage_button.set_label(homepage or 'http://ubuntu-tweak.com') self.homepage_button.set_uri(homepage or 'http://ubuntu-tweak.com') if url: if ppa.is_ppa(url): url = ppa.get_homepage(url) self.url_button.destroy() self.url_button = Gtk.LinkButton(url, url) self.url_button.show() else: url = 'http://ubuntu-tweak.com' self.url_button.set_label(homepage or 'http://ubuntu-tweak.com') self.url_button.set_uri(homepage or 'http://ubuntu-tweak.com') self.description_label.set_text(description or _('Description is here'))
def update_ppa_model(self): self.set_busy() self.__column.set_title('PPA Sources') model = self.get_model() model.clear() self.mode = 'ppa' ppa_source_dict = get_ppa_source_dict() for source in self.get_sourceslist(): if ppa.is_ppa(source.uri ) and source.type == 'deb' and not source.disabled: try: id = ppa_source_dict[source.uri] pixbuf = get_source_logo_from_filename( SOURCE_PARSER[id]['logo']) name = SOURCE_PARSER.get_name(id) comment = SOURCE_PARSER.get_summary(id) except: id = source.uri name = ppa.get_short_name(source.uri) comment = ppa.get_homepage(source.uri) pixbuf = get_source_logo_from_filename('') self.total_num += 1 iter = model.append() log.debug("Found an enalbed PPA: %s" % name) model.set( iter, COLUMN_ICON, pixbuf, COLUMN_CHECK, False, COLUMN_NAME, str(id), COLUMN_DESC, '', COLUMN_DISPLAY, '<b>%s</b>\n%s' % (name, comment), ) self.unset_busy()
def do_source_operation(self, enable_str, source_json, *args): enable = int(enable_str) source = json.loads(source_json) distro = source["distro_value"] log.debug("Enable? %s for source: %s for distro: %s" % (enable, source["name"], distro)) if ppa.is_ppa(source["url"]): file_name = "%s-%s" % (ppa.get_source_file_name(source["url"]), distro) else: file_name = source["slug"] # TODO these kinds of source should never be featured if not source["component"] and distro: distro = distro + "/" elif not source["component"] and not distro: distro = "./" try: result = proxy.set_separated_entry( source["url"], distro, source["component"], source["summary"], enable, file_name ) log.debug("Enable source: %s result: %s" % (source["name"], result)) if source["key"]: proxy.add_apt_key_from_content(source["key"]) if result == "enabled": notify = Notify.Notification( summary=_("New source has been enabled"), body=_('"%s" is enabled now, Please click the update button to update %s') % (source["name"], self.current_app), ) notify.set_property("icon-name", "ubuntu-tweak") notify.set_hint_string("x-canonical-append", "true") notify.show() self.update_action_button(self.UPDATE_ACTION) except Exception, e: log.error(e) self.update_sources()
def has_mirror_ppa(self, url): if TweakSettings.get_use_mirror_ppa(): return ppa.is_ppa(url) and url.split('/')[3] in PPA_MIRROR else: return False
if entry.invalid and not entry.disabled and entry_line and not entry_line.startswith( '#'): try: entry.set_enabled(False) except Exception, e: log.error(e) if entry.file not in disabled_list: disabled_list.append(entry.file) continue if convert_source: if os.path.basename(entry.file) == 'sources.list': continue log.debug("Check for url: %s, type: %s, filename: %s" % (entry.uri, entry.type, entry.file)) if ppa.is_ppa(entry.uri): filename = '%s-%s.list' % (ppa.get_source_file_name( entry.uri), entry.dist) if filename != os.path.basename(entry.file): log.debug("[%s] %s need rename to %s" % (entry.type, entry.file, filename)) to_rm_entry.append(entry) if os.path.exists(entry.file): log.debug("%s is exists, so remove it" % entry.file) os.remove(entry.file) entry.file = os.path.join(os.path.dirname(entry.file), filename) to_add_entry.append(entry) for entry in to_rm_entry:
def update_source_model(self, find='all', limit=-1, only_enabled=False): self.model.clear() sourceslist = self.get_sourceslist() enabled_list = [] for source in sourceslist.list: if source.type == 'deb' and not source.disabled: enabled_list.append(source.uri) if self._status: self._status.load_objects_from_parser(SOURCE_PARSER) index = 0 for id in SOURCE_PARSER: enabled = False index = index + 1 url = SOURCE_PARSER.get_url(id) enabled = url in enabled_list if enabled: enabled_list.remove(url) if only_enabled: if not enabled: continue elif not ppa.is_ppa(url): continue else: enabled = not enabled slug = SOURCE_PARSER.get_slug(id) comps = SOURCE_PARSER.get_comps(id) distro = SOURCE_PARSER.get_distro(id) category = SOURCE_PARSER.get_category(id) if find != 'all' and category != find: continue #TODO real top-10 if limit > 0 and index >= limit: break name = SOURCE_PARSER.get_name(id) comment = SOURCE_PARSER.get_summary(id) pixbuf = get_source_logo_from_filename(SOURCE_PARSER[id]['logo']) website = SOURCE_PARSER.get_website(id) key = SOURCE_PARSER.get_key(id) if self._status and not self._status.get_read_status(slug): display = '<b>%s <span foreground="#ff0000">(New!!!)</span>\n%s</b>' % ( name, comment) else: display = '<b>%s</b>\n%s' % (name, comment) iter = self.model.append() self.model.set( iter, self.COLUMN_ENABLED, enabled, self.COLUMN_ID, id, self.COLUMN_CATE, category, self.COLUMN_URL, url, self.COLUMN_DISTRO, distro, self.COLUMN_COMPS, comps, self.COLUMN_COMMENT, comment, self.COLUMN_SLUG, slug, self.COLUMN_NAME, name, self.COLUMN_DISPLAY, display, self.COLUMN_LOGO, pixbuf, self.COLUMN_HOME, website, self.COLUMN_KEY, key, ) path = os.path.join(consts.DATA_DIR, 'pixmaps/ppa-logo.png') pixbuf = icon.get_from_file(path, size=32) if enabled_list and only_enabled: for url in enabled_list: if ppa.is_ppa(url): iter = self.model.append() self.model.set( iter, self.COLUMN_ENABLED, False, self.COLUMN_ID, 9999, self.COLUMN_CATE, -1, self.COLUMN_URL, url, self.COLUMN_DISTRO, distro, self.COLUMN_COMPS, comps, self.COLUMN_COMMENT, '', self.COLUMN_SLUG, url, self.COLUMN_NAME, ppa.get_basename(url), self.COLUMN_DISPLAY, ppa.get_long_name(url), self.COLUMN_LOGO, pixbuf, self.COLUMN_HOME, ppa.get_homepage(url), self.COLUMN_KEY, '', )
def update_source_model(self, find='all', limit=-1, only_enabled=False): self.model.clear() sourceslist = self.get_sourceslist() enabled_list = [] for source in sourceslist.list: if source.type == 'deb' and not source.disabled: enabled_list.append(source.uri) if self._status: self._status.load_objects_from_parser(SOURCE_PARSER) index = 0 for id in SOURCE_PARSER: enabled = False index = index + 1 url = SOURCE_PARSER.get_url(id) enabled = url in enabled_list if enabled: enabled_list.remove(url) if only_enabled: if not enabled: continue elif not ppa.is_ppa(url): continue else: enabled = not enabled slug = SOURCE_PARSER.get_slug(id) comps = SOURCE_PARSER.get_comps(id) distro = SOURCE_PARSER.get_distro(id) category = SOURCE_PARSER.get_category(id) if find != 'all' and category != find: continue #TODO real top-10 if limit > 0 and index >= limit: break name = SOURCE_PARSER.get_name(id) comment = SOURCE_PARSER.get_summary(id) pixbuf = get_source_logo_from_filename(SOURCE_PARSER[id]['logo']) website = SOURCE_PARSER.get_website(id) key = SOURCE_PARSER.get_key(id) if self._status and not self._status.get_read_status(slug): display = '<b>%s <span foreground="#ff0000">(New!!!)</span>\n%s</b>' % (name, comment) else: display = '<b>%s</b>\n%s' % (name, comment) iter = self.model.append() self.model.set(iter, self.COLUMN_ENABLED, enabled, self.COLUMN_ID, id, self.COLUMN_CATE, category, self.COLUMN_URL, url, self.COLUMN_DISTRO, distro, self.COLUMN_COMPS, comps, self.COLUMN_COMMENT, comment, self.COLUMN_SLUG, slug, self.COLUMN_NAME, name, self.COLUMN_DISPLAY, display, self.COLUMN_LOGO, pixbuf, self.COLUMN_HOME, website, self.COLUMN_KEY, key, ) path = os.path.join(consts.DATA_DIR, 'pixmaps/ppa-logo.png') pixbuf = icon.get_from_file(path, size=32) if enabled_list and only_enabled: for url in enabled_list: if ppa.is_ppa(url): iter = self.model.append() self.model.set(iter, self.COLUMN_ENABLED, False, self.COLUMN_ID, 9999, self.COLUMN_CATE, -1, self.COLUMN_URL, url, self.COLUMN_DISTRO, distro, self.COLUMN_COMPS, comps, self.COLUMN_COMMENT, '', self.COLUMN_SLUG, url, self.COLUMN_NAME, ppa.get_basename(url), self.COLUMN_DISPLAY, ppa.get_long_name(url), self.COLUMN_LOGO, pixbuf, self.COLUMN_HOME, ppa.get_homepage(url), self.COLUMN_KEY, '', )
for entry in self.list: entry_line = entry.str().strip() if entry.invalid and not entry.disabled and entry_line and not entry_line.startswith('#'): try: entry.set_enabled(False) except Exception, e: log.error(e) if entry.file not in disabled_list: disabled_list.append(entry.file) continue if convert_source: if os.path.basename(entry.file) == 'sources.list': continue log.debug("Check for url: %s, type: %s, filename: %s" % (entry.uri, entry.type, entry.file)) if ppa.is_ppa(entry.uri): filename = '%s-%s.list' % (ppa.get_source_file_name(entry.uri), entry.dist) if filename != os.path.basename(entry.file): log.debug("[%s] %s need rename to %s" % (entry.type, entry.file, filename)) to_rm_entry.append(entry) if os.path.exists(entry.file): log.debug("%s is exists, so remove it" % entry.file) os.remove(entry.file) entry.file = os.path.join(os.path.dirname(entry.file), filename) to_add_entry.append(entry) for entry in to_rm_entry: log.debug("To remove: ", entry.uri, entry.type, entry.file) self.list.remove(entry)