Exemple #1
0
    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)
    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)
Exemple #3
0
    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()
Exemple #4
0
    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()
Exemple #5
0
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)
Exemple #6
0
    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()
Exemple #7
0
            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)


        valid = len(disabled_list) == 1
Exemple #8
0
                    '#'):
                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)