def AddFullRepo(self, name, uris, suites, components, code, sender=None, conn=None): self._check_polkit_privilege(sender, conn, 'ro.santopiet.repoman.modppa') # PPA Add code here try: new_source = repolib.Source( name=name, uris=uris.split(), suites=suites.split(), components=components.split(), ) new_source.set_source_enabled(code) new_source.filename = name.translate(repolib.util.CLEAN_CHARS) new_source.filename += '.sources' new_source.save_to_disk() return 0 except: raise AptException("Could not remove the APT Source")
def get_source(self, file): """ Returns a repolib.Source object from filename FILE. """ source = repolib.Source() source.load_from_file(filename=file) return source
def SetModifiedRepo(self, name, enabled, source_code, uris, suites, components, filename, sender=None, conn=None): self._check_polkit_privilege(sender, conn, 'ro.santopiet.repoman.modppa') # PPA Modify code here try: source = repolib.Source(filename=filename) source.load_from_file() source.name = name source.set_enabled(enabled) source.uris = uris.split() source.suites = suites.split() source.components = components.split() source.set_source_enabled(source_code) source.save_to_disk() return 0 except: raise AptException("Could not modify the APT Source")
def get_sources(self): """ Gets a list of sources from the disk. """ self.log.debug('Doing list') source_obj = repolib.Source() sources_dict = {} sources = glob.glob('{}/*.sources'.format(SOURCES_DIR)) for source in sources: suffix = '' markup_open = '<b>' markup_close = '</b>' with open(source) as source_file: for line in source_file: if 'Enabled: no' in line: markup_open = '' markup_close = '' suffix = ' <i>Disabled</i>' if not source in SYSTEM_SOURCES: source_obj.load_from_file(source) source_name = "{}{}{}{}".format(markup_open, source_obj.name, markup_close, suffix) sources_dict[source] = source_name return sources_dict
def SetSource(self, repo, state, sender=None, conn=None): self._check_polkit_privilege(sender, conn, 'ro.santopiet.repoman.modppa') try: source = repolib.Source() source.load_from_file(filename='{}.sources'.format(repo)) source.set_source_enabled(state) source.save_to_disk() return 0 except: raise AptException("Could not add %s to source %s" % (comp, repo))
def DelSuite(self, repo, suite, sender=None, conn=None): self._check_polkit_privilege(sender, conn, 'ro.santopiet.repoman.modppa') try: source = repolib.Source() source.load_from_file(filename='{}.sources'.format(repo)) if suite in source.suites: source.suites.remove(suite) source.suites.sort() source.save_to_disk() return 0 except: raise AptException("Could not add %s to source %s" % (comp, repo))
def AddComp(self, repo, comp, sender=None, conn=None): self._check_polkit_privilege(sender, conn, 'ro.santopiet.repoman.modppa') try: source = repolib.Source() source.load_from_file(filename='{}.sources'.format(repo)) if not comp in source.components: source.components.append(comp) source.components.sort() source.save_to_disk() return 0 except: raise AptException("Could not add %s to source %s" % (comp, repo))
def get_source_code_enabled(self, source_name='system'): """ Returns TRUE if source code is enabled for REPO. """ source_check = repolib.Source( filename='{}.sources'.format(source_name)) source_check.load_from_file() self.log.debug('Found types: %s' % source_check.types) for type in source_check.types: self.log.debug(type) if type.value == "deb-src": return True return False
def get_repo_for_name(name): """ Get a repo from a given name. This takes a name and gives back a repolib.Source object which represents the given source. Arguments: name (str): The name of the repo to look for. Returns: A repolib.Source (or subclass) representing the given name. """ full_path = repolib.util.get_source_path(name) if full_path: if full_path.suffix == '.sources': repo = repolib.Source(filename=full_path) else: repo = repolib.LegacyDebSource(filename=full_path) return repo raise Exception(f'Could not find a source for {name}.')