The method will search for existing matching repos and will try to
reuse them as far as possible
'''
comps = orig_comps[:]
for source in self.list:
if not (source.disabled) and not (source.invalid) and source.type == type and uri == source.uri and source.dist == dist:
for new_comp in comps:
if new_comp in source.comps:
del comps[comps.index(new_comp)]
if len(comps) == 0:
return source
continue
len(comps) == 0
for source in self.list:
if not (source.disabled) and not (source.invalid) and source.type == type and uri == source.uri and source.dist == dist:
comps = uniq(source.comps + comps)
source.comps = comps
return source
if source.disabled and not (source.invalid) and source.type == type and uri == source.uri and source.dist == dist and len(set(source.comps) & set(comps)) == len(comps):
source.disabled = False
return source
line = '%s %s %s' % (type, uri, dist)
for c in comps:
line = line + ' ' + c
line = line + '\n'
new_entry = SourceEntry(line)
if file is not None:
new_entry.file = file
self.matcher.match(new_entry)
self.list.insert(pos, new_entry)
return new_entry
def remove(self, source_entry):
''' remove the specified entry from the sources.list '''
self.list.remove(source_entry)
def restoreBackup(self, backup_ext):
''' restore sources.list files based on the backup extension '''
header = '## See sources.list(5) for more information, especialy\n# Remember that you can only use http, ftp or file URIs\n# CDROMs are managed through the apt-cdrom tool.\n'
open(path, 'w').write(header)
return None
for source in self.list:
if source.file not in files:
files[source.file] = open(source.file, 'w')
files[source.file].write(source.str())
for f in files:
files[f].close()
def check_for_relations(self, sources_list):
'''get all parent and child channels in the sources list'''
parents = []
used_child_templates = { }
for source in sources_list:
if source.template is None:
continue
if source.template.child:
key = source.template
if key not in used_child_templates:
used_child_templates[key] = []
temp = used_child_templates[key]
temp.append(source)
continue
if len(source.template.children) > 0:
parents.append(source)
continue
return (parents, used_child_templates)
class SourceEntryMatcher:
''' matcher class to make a source entry look nice
lots of predefined matchers to make it i18n/gettext friendly
'''
def __init__(self, matcherPath):
self.templates = []
spec_files = glob.glob('%s/*.info' % matcherPath)
for f in spec_files:
f = os.path.basename(f)
i = f.find('.info')
f = f[0:i]
dist = DistInfo(f, base_dir = matcherPath)
for template in dist.templates:
if template.match_uri is not None:
self.templates.append(template)
continue
def match(self, source):
'''Add a matching template to the source'''
_ = gettext.gettext
found = False
for template in self.templates:
if re.search(template.match_uri, source.uri) and re.match(template.match_name, source.dist):
found = True
source.template = template
break
continue
if template.is_mirror(source.uri) and re.match(template.match_name, source.dist):