#!/usr/bin/python import os import sys import gettext import locale from softwareproperties.SoftwareProperties import SoftwareProperties from softwareproperties.ppa import expand_ppa_line from aptsources.sourceslist import SourceEntry from optparse import OptionParser from gettext import gettext as _ if __name__ == "__main__": try: locale.setlocale(locale.LC_ALL, "") except: pass usage = """usage: %prog sourceline %prog is a script for removing apt sources.list entries. It can be used to remove any repository and also provides a shorthand synatax for Launchpad PPA (Personal Package Archive) repositories via ppa:user/repository """ parser = OptionParser(usage) # FIXME: provide a --sources-list-file= option that # puts the line into a specific file in sources.list.d (options, args) = parser.parse_args() if os.geteuid() != 0: print _("Error: must run as root") sys.exit(1) if (len(args) != 1): print _("Error: need a repository as argument") sys.exit(1) # force new ppa file to be 644 (LP: #399709) os.umask(0022) sp = SoftwareProperties(options) line = args[0] (line, file) = expand_ppa_line(line.strip(), sp.distro.codename) new_entry = SourceEntry(line, file) match = False for entry in sp.sourceslist: if new_entry == entry: match = True new_entry = entry if not match: print _("Error: '%s' not found" % new_entry) sys.exit(1) if not new_entry.invalid: sp.remove_source(new_entry) else: print _("Error: invalid entry")