|
|
|
@ -70,7 +70,10 @@ apt_repository: repo='ppa:nginx/stable'
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
import glob
|
|
|
|
|
import json
|
|
|
|
|
try:
|
|
|
|
|
import json
|
|
|
|
|
except ImportError:
|
|
|
|
|
import simplejson as json
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import tempfile
|
|
|
|
@ -110,14 +113,14 @@ class InvalidSource(Exception):
|
|
|
|
|
class SourcesList(object):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.files = {} # group sources by file
|
|
|
|
|
self.default_file = apt_pkg.config.find_file('Dir::Etc::sourcelist')
|
|
|
|
|
self.default_file = self._apt_cfg_file('Dir::Etc::sourcelist')
|
|
|
|
|
|
|
|
|
|
# read sources.list if it exists
|
|
|
|
|
if os.path.isfile(self.default_file):
|
|
|
|
|
self.load(self.default_file)
|
|
|
|
|
|
|
|
|
|
# read sources.list.d
|
|
|
|
|
for file in glob.iglob('%s/*.list' % apt_pkg.config.find_dir('Dir::Etc::sourceparts')):
|
|
|
|
|
for file in glob.iglob('%s/*.list' % self._apt_cfg_dir('Dir::Etc::sourceparts')):
|
|
|
|
|
self.load(file)
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
@ -132,7 +135,7 @@ class SourcesList(object):
|
|
|
|
|
if '/' in filename:
|
|
|
|
|
return filename
|
|
|
|
|
else:
|
|
|
|
|
return os.path.abspath(os.path.join(apt_pkg.config.find_dir('Dir::Etc::sourceparts'), filename))
|
|
|
|
|
return os.path.abspath(os.path.join(self._apt_cfg_dir('Dir::Etc::sourceparts'), filename))
|
|
|
|
|
|
|
|
|
|
def _suggest_filename(self, line):
|
|
|
|
|
def _cleanup_filename(s):
|
|
|
|
@ -176,6 +179,28 @@ class SourcesList(object):
|
|
|
|
|
|
|
|
|
|
return valid, enabled, source, comment
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _apt_cfg_file(filespec):
|
|
|
|
|
'''
|
|
|
|
|
Wrapper for `apt_pkg` module for running with Python 2.5
|
|
|
|
|
'''
|
|
|
|
|
try:
|
|
|
|
|
result = apt_pkg.config.find_file(filespec)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
result = apt_pkg.Config.FindFile(filespec)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _apt_cfg_dir(dirspec):
|
|
|
|
|
'''
|
|
|
|
|
Wrapper for `apt_pkg` module for running with Python 2.5
|
|
|
|
|
'''
|
|
|
|
|
try:
|
|
|
|
|
result = apt_pkg.config.find_dir(dirspec)
|
|
|
|
|
except AttributeError:
|
|
|
|
|
result = apt_pkg.Config.FindDir(dirspec)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def load(self, file):
|
|
|
|
|
group = []
|
|
|
|
|
f = open(file, 'r')
|
|
|
|
|