Ejemplo n.º 1
0
    def add_source_from_shortcut(self, shortcut, enable_source_code=False):
        """
    Add a source with the given shortcut and add the signing key if the
    site is in whitelist or the shortcut implementer adds it.
    """

        (deb_line, file) = shortcut.expand(codename=self.distro.codename,
                                           distro=self.distro.id.lower())
        deb_line = self.expand_http_line(deb_line)
        debsrc_entry_type = 'deb-src' if enable_source_code else '# deb-src'
        debsrc_line = debsrc_entry_type + deb_line[3:]
        new_deb_entry = SourceEntry(deb_line, file)
        new_debsrc_entry = SourceEntry(debsrc_line, file)
        if new_deb_entry.invalid or new_debsrc_entry.invalid:
            return False
        worker = self.check_and_add_key_for_whitelisted_shortcut(shortcut)
        self.sourceslist.add(new_deb_entry.type,
                             new_deb_entry.uri,
                             new_deb_entry.dist,
                             new_deb_entry.comps,
                             comment=new_deb_entry.comment,
                             file=new_deb_entry.file,
                             architectures=new_deb_entry.architectures)
        self.sourceslist.add(debsrc_entry_type,
                             new_debsrc_entry.uri,
                             new_debsrc_entry.dist,
                             new_debsrc_entry.comps,
                             comment=new_debsrc_entry.comment,
                             file=new_debsrc_entry.file,
                             architectures=new_debsrc_entry.architectures)
        self.set_modified_sourceslist()
        if worker:
            # wait for GPG key to be downloaded
            worker.join(30)
        return True
Ejemplo n.º 2
0
    def update_debline(cls, debline):
        # Be careful to handle deblines with pockets.
        source_entry = SourceEntry(debline)
        distro_pocket = source_entry.dist.split('-')
        distro_pocket[0] = get_distro().get_codename()
        source_entry.dist = "-".join(distro_pocket)

        return unicode(source_entry)
Ejemplo n.º 3
0
    def update_debline(cls, debline):
        # Be careful to handle deblines with pockets.
        source_entry = SourceEntry(debline)
        distro_pocket = source_entry.dist.split('-')
        distro_pocket[0] = get_distro().get_codename()
        source_entry.dist = "-".join(distro_pocket)

        return unicode(source_entry)
Ejemplo n.º 4
0
 def test_strip_auth_from_source_entry(self):
     from aptsources.sourceslist import SourceEntry
     # entry with PW
     s = SourceEntry("deb http://user:pass@some-ppa/ ubuntu main")
     self.assertTrue(
         "user" not in utils.get_string_with_no_auth_from_source_entry(s))
     self.assertTrue(
         "pass" not in utils.get_string_with_no_auth_from_source_entry(s))
     self.assertEqual(utils.get_string_with_no_auth_from_source_entry(s),
                      "deb http://hidden-u:hidden-p@some-ppa/ ubuntu main")
     # no pw
     s = SourceEntry("deb http://some-ppa/ ubuntu main")
     self.assertEqual(utils.get_string_with_no_auth_from_source_entry(s),
                      "deb http://some-ppa/ ubuntu main")
Ejemplo n.º 5
0
 def _is_line_in_whitelisted_channel(self, srcline):
     """
 helper that checks if a given line is in the source list
 return the channel name or None if not found
 """
     srcentry = SourceEntry(srcline)
     if os.path.exists(self.CHANNEL_PATH):
         for f in glob.glob("%s/*.list" % self.CHANNEL_PATH):
             for line in open(f):
                 if line.strip().startswith("#"):
                     continue
                 if srcentry == SourceEntry(line):
                     return os.path.splitext(os.path.basename(f))[0]
     return None
Ejemplo n.º 6
0
 def _feed_in_private_sources_list_entry(self, source_entry):
     """
     this feeds in a private sources.list entry that is
     available to the user (like a private PPA) that may or
     may not be active 
     """
     # FIXME: strip out password and use apt/auth.conf
     potential_new_entry = SourceEntry(source_entry)
     # look if we have it
     sources = SourcesList()
     for source in sources.list:
         if source == potential_new_entry:
             return False
     # need to add it as a not yet enabled channel
     name = human_readable_name_from_ppa_uri(potential_new_entry.uri)
     # FIXME: use something better than uri as name
     private_channel = SoftwareChannel(name,
                                       None,
                                       None,
                                       source_entry=source_entry)
     private_channel.needs_adding = True
     if private_channel in self.extra_channels:
         return False
     # add it
     self.extra_channels.append(private_channel)
     return True
Ejemplo n.º 7
0
 def ModifyPPA(self, old_source, new_source, sender=None, conn=None):
     self._check_polkit_privilege(
         sender, conn, 'ro.santopiet.repoman.modppa'
     )
     # PPA Modify code here
     try:
         self.sp.reload_sourceslist()
         old_source = self._strip_source_line(old_source)
         isvs = self.sp.get_isv_sources()
         for i in isvs:
             if str(i) == old_source:
                 source = i
         index = self.sp.sourceslist.list.index(source)
         file = self.sp.sourceslist.list[index].file
         new_source_entry = SourceEntry(new_source,file)
         self.sp.sourceslist.list[index] = new_source_entry
         self.sp.sourceslist.save()
         self.cache.open()
         self.cache.update()
         self.cache.open(None)
         self.cache.close()
         self.sp.reload_sourceslist()
         return 0
     except:
         raise AptException("Could not modify the APT Source")
Ejemplo n.º 8
0
    def add_source_from_shortcut(self, shortcut, enable_source_code=False):
        """
    Add a source with the given shortcut and add the signing key if the
    site is in whitelist or the shortcut implementer adds it.
    """

        (deb_line, file) = shortcut.expand(codename=self.distro.codename,
                                           distro=self.distro.id.lower())
        deb_line = self.expand_http_line(deb_line)
        debsrc_entry_type = 'deb-src' if enable_source_code else '# deb-src'
        debsrc_line = debsrc_entry_type + deb_line[3:]
        new_deb_entry = SourceEntry(deb_line, file)
        new_debsrc_entry = SourceEntry(debsrc_line, file)
        if new_deb_entry.invalid or new_debsrc_entry.invalid:
            return False
        worker = self.check_and_add_key_for_whitelisted_shortcut(shortcut)
        self.sourceslist.add(new_deb_entry.type,
                             new_deb_entry.uri,
                             new_deb_entry.dist,
                             new_deb_entry.comps,
                             comment=new_deb_entry.comment,
                             file=new_deb_entry.file,
                             architectures=new_deb_entry.architectures)
        self.sourceslist.add(debsrc_entry_type,
                             new_debsrc_entry.uri,
                             new_debsrc_entry.dist,
                             new_debsrc_entry.comps,
                             comment=new_debsrc_entry.comment,
                             file=new_debsrc_entry.file,
                             architectures=new_debsrc_entry.architectures)
        self.set_modified_sourceslist()
        if worker:
            # wait for GPG key to be downloaded
            worker.join(30)
            if worker.isAlive():
                # thread timed out.
                raise shortcuts.ShortcutException(
                    "Error: retrieving gpg key timed out.")
            result, msg = self.myqueue.get()
            if not result:
                raise shortcuts.ShortcutException(msg)

        if self.options and self.options.update:
            import apt
            cache = apt.Cache()
            cache.update(sources_list=new_debsrc_entry.file)
        return True
Ejemplo n.º 9
0
 def revert_sourceslist(self):
     """Restore the source list from the startup of the dialog"""
     self.sourceslist.list = []
     for source in self.sourceslist_backup:
         source_reset = SourceEntry(line=source.line, file=source.file)
         self.sourceslist.list.append(source_reset)
     self.save_sourceslist()
     self.reload_sourceslist()
 def testVerifySourcesListEntry(self):
     from aptsources.sourceslist import SourceEntry
     v = DistUpgradeViewNonInteractive()
     d = DistUpgradeController(v, datadir=self.testdir)
     for scheme in ["http"]:
         entry = "deb %s://archive.ubuntu.com/ubuntu/ precise main universe restricted multiverse" % scheme
         self.assertTrue(
             d._sourcesListEntryDownloadable(SourceEntry(entry)),
             "entry '%s' not downloadable" % entry)
         entry = "deb %s://archive.ubuntu.com/ubuntu/ warty main universe restricted multiverse" % scheme
         self.assertFalse(
             d._sourcesListEntryDownloadable(SourceEntry(entry)),
             "entry '%s' not downloadable" % entry)
         entry = "deb %s://archive.ubuntu.com/ubuntu/ xxx main" % scheme
         self.assertFalse(
             d._sourcesListEntryDownloadable(SourceEntry(entry)),
             "entry '%s' not downloadable" % entry)
Ejemplo n.º 11
0
 def add_repository(self, line="", sourcesfile=""):
     """Add repository to the sources list."""
     entry = SourceEntry(line)
     self._client.add_repository(entry.type, entry.uri, entry.dist,
                                 entry.comps, entry.comment,
                                 sourcesfile,
                                 reply_handler=self._run_transaction,
                                 error_handler=self._on_exception)
Ejemplo n.º 12
0
 def replace_source_entry(self, old_entry, new_entry):
     # find and replace, then write
     for (index, entry) in enumerate(self.sourceslist.list):
         if str(entry) == old_entry:
             file = self.sourceslist.list[index].file
             self.sourceslist.list[index] = SourceEntry(new_entry, file)
             self.set_modified_sourceslist()
             return True
     return False
Ejemplo n.º 13
0
    def run(self):
        result = self.exec_()
        if result == QDialog.Accepted:
            line = self.get_line()

            # change repository
            index = self.sourceslist.list.index(self.source_entry)
            file = self.sourceslist.list[index].file
            self.sourceslist.list[index] = SourceEntry(line, file)
        return result
Ejemplo n.º 14
0
 def check_line(self, *args):
     """
 Check for a valid apt line and set the sensitiveness of the
 button 'add' accordingly
 """
     line = self.entry.get_text() + "\n"
     source_entry = SourceEntry(line)
     if source_entry.invalid == True or source_entry.disabled == True:
         self.button_add.set_sensitive(False)
     else:
         self.button_add.set_sensitive(True)
Ejemplo n.º 15
0
 def check_line(self, *args):
     """Check for a valid apt line and set the sensitiveness of the
    button 'add' accordingly"""
     line = self.get_line()
     if line == False:
         self.button_edit_ok.set_sensitive(False)
         return
     source_entry = SourceEntry(line)
     if source_entry.invalid == True:
         self.button_edit_ok.set_sensitive(False)
     else:
         self.button_edit_ok.set_sensitive(True)
Ejemplo n.º 16
0
    def run(self):
        res = self.main.run()
        if res == Gtk.ResponseType.OK:
            line = self.get_line()

            # change repository
            index = self.sourceslist.list.index(self.source_entry)
            file = self.sourceslist.list[index].file
            self.new_source_entry = SourceEntry(line, file)
            self.sourceslist.list[index] = self.new_source_entry
        self.main.hide()
        return res
 def check_line(self, text):
     """Check for a valid apt line and set the enabled value of the
    button 'add' accordingly"""
     line = self.entry.text()
     if line.startswith("ppa:"):
         self.button_edit_ok.setEnabled(True)
         return
     source_entry = SourceEntry(line)
     if source_entry.invalid == True or source_entry.disabled == True:
         self.button_edit_ok.setEnabled(False)
     else:
         self.button_edit_ok.setEnabled(True)
Ejemplo n.º 18
0
 def check_line(self, text):
     """Check for a valid apt line and set the enabled value of the
    button 'add' accordingly"""
     line = self.get_line()
     self.button_edit_ok = self.buttonBox.button(QDialogButtonBox.Ok)
     if line == False:
         self.button_edit_ok.setEnabled(False)
         return
     source_entry = SourceEntry(line)
     if source_entry.invalid == True:
         self.button_edit_ok.setEnabled(False)
     else:
         self.button_edit_ok.setEnabled(True)
Ejemplo n.º 19
0
def test_bootstrap_overlay(config_files):
    with open(config_files, "r") as main_file:
        parser = ConfigurationParser(main_file)
        # the host file shall win
        boostrap_source = SourceEntry(parser.get_bootstrap_repository())
        assert parser.get_bootstrap_architecture() == "i386"
        assert "main" in boostrap_source.comps
        assert boostrap_source.uri == "http://deb.debian.org/debian/"
        # the all file shall provide this key
        expected_key = "https://ftp-master.debian.org/keys/archive-key-8.asc"
        assert parser.get_bootstrap_repository_key() == expected_key
        assert boostrap_source.dist == "jessie"
        assert parser.get_bootstrap_tool() == "debootstrap"
Ejemplo n.º 20
0
 def _remove_no_longer_needed_extra_channels(self, backend, res):
     """ go over the extra channels and remove no longer needed ones"""
     removed = False
     for channel in self.extra_channels:
         if not channel._source_entry:
             continue
         sources = SourcesList()
         for source in sources.list:
             if source == SourceEntry(channel._source_entry):
                 self.extra_channels.remove(channel)
                 removed = True
     if removed:
         self.backend.emit("channels-changed", True)
Ejemplo n.º 21
0
 def __init__(self,
              repository=None,
              repository_key=None,
              architectures=None):
     if not repository:
         raise FatalError('''Missing argument 'repository'.''')
     if not architectures:
         raise FatalError('''Missing (non empty) list 'architectures'.''')
     self._repository = repository
     self._repository_key = repository_key
     self._architectures = architectures
     self._source = SourceEntry(repository)
     self._source.uri = self._source.uri.rstrip('/')
     self._compressions = ['gz', 'bz2', 'xz']
     self._checksum_algorithms = ['SHA512', 'SHA256']  # strongest first
Ejemplo n.º 22
0
    def run(self):
        res = self.main.run()
        if res == gtk.RESPONSE_OK:
            line = self.get_line()

            # change repository
            index = self.sourceslist.list.index(self.source_entry)
            file = self.sourceslist.list[index].file
            self.sourceslist.list[index] = SourceEntry(line, file)
            #self.sourceslist.add(self.selected.type,
            #                     self.selected.uri,
            #                     self.selected.dist,
            #                     self.selected_comps)
        self.main.hide()
        return res
Ejemplo n.º 23
0
 def run(self):
     index = self.sp.sourceslist.list.index(self.old_source)
     file = self.sp.sourceslist.list[index].file
     self.new_source_entry = SourceEntry(self.new_source, file)
     self.sp.sourceslist.list[index] = self.new_source_entry
     self.sp.sourceslist.save()
     self.cache.open()
     self.cache.update()
     self.cache.open(None)
     self.sp.reload_sourceslist()
     isv_list = self.sp.get_isv_sources()
     GObject.idle_add(
         self.parent.parent.parent.stack.list_all.generate_entries,
         isv_list)
     GObject.idle_add(
         self.parent.parent.parent.stack.list_all.view.set_sensitive, True)
     GObject.idle_add(self.parent.parent.parent.hbar.spinner.stop)
Ejemplo n.º 24
0
    def _rewrite_sources_list(self, targetdir, new_distro):
        from aptsources.sourceslist import SourcesList, SourceEntry
        apt_pkg.config.set(
            "Dir::Etc::sourcelist",
            os.path.abspath(
                os.path.join(targetdir, "etc", "apt", "sources.list")))
        apt_pkg.config.set(
            "Dir::Etc::sourceparts",
            os.path.abspath(
                os.path.join(targetdir, "etc", "apt", "sources.list.d")))
        sources = SourcesList()

        for entry in sources.list[:]:
            if entry.invalid or entry.disabled:
                continue
            replacement = ''
            for pocket in ('updates', 'security', 'backports'):
                if entry.dist.endswith('-%s' % pocket):
                    replacement = '%s-%s' % (new_distro, pocket)
                    break
            if replacement:
                entry.dist = replacement
            else:
                entry.dist = new_distro

        existing = os.path.join(targetdir, "etc", "apt",
                                "sources.list.apt-clone")
        sourcelist = apt_pkg.config.find_file("Dir::Etc::sourcelist")
        if os.path.exists(existing):
            with open(existing, 'r') as fp:
                for line in fp:
                    src = SourceEntry(line, sourcelist)
                    if (src.invalid or src.disabled) or src not in sources:
                        sources.list.append(src)
            os.remove(existing)

        for entry in sources.list:
            if entry.uri.startswith('cdrom:'):
                # Make sure CD entries come first.
                sources.list.remove(entry)
                sources.list.insert(0, entry)
                entry.disabled = True
        sources.save()
Ejemplo n.º 25
0
 def _wait_for_cdrom_scan_finish(self, p, tmp):
     """ glib timeout helper to wait for the cdrom scanner to finish """
     # keep the timeout running
     if p.poll() is None:
         return True
     # else we have a return code
     res = p.poll()
     if res != 0:
         self.CdromScanFailed()
         return False
     # read tmp file with source name
     line = ""
     # (read only last line)
     for x in open(tmp.name):
         line = x
     if line != "":
         self.sourceslist.list.insert(0, SourceEntry(line))
         self.set_modified_sourceslist()
     return False
Ejemplo n.º 26
0
    def modify_repo(self, old_repo, new_repo, sender=None, conn=None):
        self._check_polkit_privilege(
            sender, conn, 'org.pop_os.repoman.modifysources'
        )

        try:
            old_source = self._find_source_from_string(old_repo)
            index = self.sp.sourceslist.list.index(old_source)
            file = self.sp.sourceslist.list[index].file
            new_source_entry = SourceEntry(new_repo, file)
            self.sp.sourceslist.list[index] = new_source_entry
            self.sp.sourceslist.save()
            self.cache.open()
            self.cache.update()
            self.cache.open(None)
            self.sp.reload_sourceslist()
            return [True, '']
        except Exception as e:
            print(str(e))
            return [False, str(e)]
Ejemplo n.º 27
0
    def remove_source(self, source, remove_source_code=True):
        """Remove the given source"""
        if remove_source_code:
            if isinstance(source, str):
                # recall this method giving a SourceEntry as an argument
                source = self._find_source_from_string(source)
                self.remove_source(source, True)
            elif source is not None:
                self.remove_source(source, False)
                # remove the deb-src lines (enabled or not) associated to
                # this source entry
                source = copy.copy(source)
                source.type = 'deb-src'
                source.disabled = True
                self.remove_source(source, False)
                source.disabled = False
                self.remove_source(source, False)
            return

        # first find the source object if we got a string
        if isinstance(source, str):
            source = self._find_source_from_string(source)
        if source is None:
            return
        # if its a sources.list.d file and it contains only a single line
        # (the line that we just remove), then all references to that
        # file are gone and the file is not saved. we work around that
        # here
        if source.file != apt_pkg.config.find_file("Dir::Etc::sourcelist"):
            self.sourceslist.list.append(SourceEntry("", file=source.file))
        try:
            self.sourceslist.remove(source)
        except ValueError:
            # this exception is raised if trying to remove an entry that does
            # not exist. in this case we suppress the error because there's no
            # need to propagate it (the aim of this method is to ensure that
            # the given entries are not listed in the sourceslist)
            pass
        self.set_modified_sourceslist()
    def on_button_add_cdrom_clicked(self):
        '''Show a dialog that allows to add a repository located on a CDROM
       or DVD'''
        # testing
        #apt_pkg.config.set("APT::CDROM::Rename","true")

        saved_entry = apt_pkg.config.find("Dir::Etc::sourcelist")
        tmp = tempfile.NamedTemporaryFile()
        apt_pkg.config.set("Dir::Etc::sourcelist", tmp.name)
        progress = CdromProgress(self.datadir, self, kapp)
        cdrom = apt_pkg.Cdrom()
        # if nothing was found just return
        try:
            res = cdrom.add(progress)
        except SystemError as msg:
            title = _("CD Error")
            primary = _("Error scanning the CD")
            text = "%s\n\n<small>%s</small>" % (primary, msg)
            #KMessageBox.sorry(self.userinterface, text, title)
            QMessageBox.warning(self.userinterface, title, text)
            return
        finally:
            apt_pkg.config.set("Dir::Etc::sourcelist", saved_entry)
            progress.close()

        if res == False:
            return
        # read tmp file with source name (read only last line)
        line = ""
        for x in open(tmp.name):
            line = x
        if line != "":
            full_path = "%s%s" % (apt_pkg.config.find_dir("Dir::Etc"),
                                  saved_entry)
            # insert cdrom source first, so that it has precedence over network sources
            self.sourceslist.list.insert(0, SourceEntry(line, full_path))
            self.set_modified_sourceslist()
Ejemplo n.º 29
0
    def _run_debootstrap(self, tempdir, keyring_file, qemu_executable):
        # Ansible uses python on the target system
        # sudo is needed for privilege escalation
        additional_packages = (
            "python,sudo,netbase,net-tools,iputils-ping,ifupdown,isc-dhcp-client,"
            "resolvconf,systemd,systemd-sysv,gnupg")
        rootfs = os.path.join(tempdir, "rootfs")
        bootstrap_source = SourceEntry(self.config.get_bootstrap_repository())
        components = ",".join(bootstrap_source.comps)

        cmd = []
        cmd.append("debootstrap")
        cmd.append("--arch={0}".format(
            self.config.get_bootstrap_architecture()))
        if qemu_executable:
            cmd.append("--foreign")
        cmd.append("--variant=minbase")
        cmd.append("--include={0}".format(additional_packages))
        cmd.append("--components={0}".format(components))
        if keyring_file:
            cmd.append("--force-check-gpg")
            cmd.append("--keyring={0}".format(keyring_file))
        cmd.append(bootstrap_source.dist)
        cmd.append(rootfs)
        cmd.append(bootstrap_source.uri)
        run(cmd, sudo=True)

        if qemu_executable:
            qemu_target_path = os.path.join(rootfs, "usr", "bin")
            shutil.copy(qemu_executable, qemu_target_path)
            second_stage_cmd = get_chroot_cmd(rootfs)
            second_stage_cmd.append("/debootstrap/debootstrap")
            second_stage_cmd.append("--second-stage")
            run(second_stage_cmd, sudo=True)

        return rootfs
Ejemplo n.º 30
0
    def _run_debootstrap(self, tempdir, keyring_file, qemu_executable):
        additional_packages = ','.join(
            self.config.get_bootstrap_additional_packages())
        rootfs = os.path.join(tempdir, "rootfs")
        bootstrap_source = SourceEntry(self.config.get_bootstrap_repository())
        components = ",".join(bootstrap_source.comps)

        cmd = list()
        cmd.append("debootstrap")
        cmd.append("--arch={0}".format(
            self.config.get_bootstrap_architecture()))
        if qemu_executable:
            cmd.append("--foreign")
        cmd.append("--variant=minbase")
        cmd.append("--include={0}".format(additional_packages))
        cmd.append("--components={0}".format(components))
        if keyring_file:
            cmd.append("--force-check-gpg")
            cmd.append("--keyring={0}".format(keyring_file))
        cmd.append(bootstrap_source.dist)
        cmd.append(rootfs)
        cmd.append(bootstrap_source.uri)
        run(cmd,
            sudo=True,
            log_threshold=logging.INFO,
            env=ProxySetup().get_environment())

        if qemu_executable:
            qemu_target_path = os.path.join(rootfs, "usr", "bin")
            shutil.copy(qemu_executable, qemu_target_path)
            second_stage_cmd = get_chroot_cmd(rootfs)
            second_stage_cmd.append("/debootstrap/debootstrap")
            second_stage_cmd.append("--second-stage")
            run(second_stage_cmd, sudo=True, log_threshold=logging.INFO)

        return rootfs
Ejemplo n.º 31
0
 def backup_sourceslist(self):
     """Store a backup of the source.list in memory"""
     self.sourceslist_backup = []
     for source in self.sourceslist.list:
         source_bkp = SourceEntry(line=source.line, file=source.file)
         self.sourceslist_backup.append(source_bkp)