forked from ungleich-public/cdist
Merge branch 'apt-ppa-fixes' of https://github.com/fieldaware/cdist
This commit is contained in:
commit
e5a8c9a2e5
1 changed files with 16 additions and 3 deletions
|
@ -7,13 +7,19 @@
|
||||||
# 1: if not
|
# 1: if not
|
||||||
# 2: on other error
|
# 2: on other error
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from aptsources import distro, sourceslist
|
from aptsources import distro, sourceslist
|
||||||
from softwareproperties import ppa
|
from softwareproperties import ppa
|
||||||
from softwareproperties.SoftwareProperties import SoftwareProperties
|
from softwareproperties.SoftwareProperties import SoftwareProperties
|
||||||
|
|
||||||
|
|
||||||
|
def remove_if_empty(file_name):
|
||||||
|
with open(file_name, 'r') as f:
|
||||||
|
if f.read().strip():
|
||||||
|
return
|
||||||
|
os.unlink(file_name)
|
||||||
|
|
||||||
def remove_repository(repository):
|
def remove_repository(repository):
|
||||||
#print 'repository:', repository
|
#print 'repository:', repository
|
||||||
codename = distro.get_distro().codename
|
codename = distro.get_distro().codename
|
||||||
|
@ -21,11 +27,18 @@ def remove_repository(repository):
|
||||||
(line, file) = ppa.expand_ppa_line(repository.strip(), codename)
|
(line, file) = ppa.expand_ppa_line(repository.strip(), codename)
|
||||||
#print 'line:', line
|
#print 'line:', line
|
||||||
#print 'file:', file
|
#print 'file:', file
|
||||||
source_entry = sourceslist.SourceEntry(line, file)
|
deb_source_entry = sourceslist.SourceEntry(line, file)
|
||||||
|
src_source_entry = sourceslist.SourceEntry('deb-src{}'.format(line[3:]), file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sp = SoftwareProperties()
|
sp = SoftwareProperties()
|
||||||
sp.remove_source(source_entry)
|
sp.remove_source(deb_source_entry)
|
||||||
|
try:
|
||||||
|
# If there's a deb-src entry, remove that too
|
||||||
|
sp.remove_source(src_source_entry)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
remove_if_empty(file)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print >> sys.stderr, "Error: '%s' doesn't exists in a sourcelist file" % line
|
print >> sys.stderr, "Error: '%s' doesn't exists in a sourcelist file" % line
|
||||||
|
|
Loading…
Reference in a new issue