43 lines
1.1 KiB
Python
Executable file
43 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python
|
|
#
|
|
# Remove the given apt repository.
|
|
#
|
|
# Exit with:
|
|
# 0: if it worked
|
|
# 1: if not
|
|
# 2: on other error
|
|
|
|
|
|
import sys
|
|
from aptsources import distro, sourceslist
|
|
from softwareproperties import ppa
|
|
from softwareproperties.SoftwareProperties import SoftwareProperties
|
|
|
|
|
|
def remove_repository(repository):
|
|
#print 'repository:', repository
|
|
codename = distro.get_distro().codename
|
|
#print 'codename:', codename
|
|
(line, file) = ppa.expand_ppa_line(repository.strip(), codename)
|
|
#print 'line:', line
|
|
#print 'file:', file
|
|
source_entry = sourceslist.SourceEntry(line, file)
|
|
|
|
try:
|
|
sp = SoftwareProperties()
|
|
sp.remove_source(source_entry)
|
|
return True
|
|
except ValueError:
|
|
print >> sys.stderr, "Error: '%s' doesn't exists in a sourcelist file" % line
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
if (len(sys.argv) != 2):
|
|
print >> sys.stderr, 'Error: need a repository as argument'
|
|
sys.exit(2)
|
|
repository = sys.argv[1]
|
|
if remove_repository(repository):
|
|
sys.exit(0)
|
|
else:
|
|
sys.exit(1)
|