summaryrefslogtreecommitdiff
path: root/aptsources
diff options
context:
space:
mode:
authorBen Finney <ben@benfinney.id.au>2008-05-16 16:11:06 +1000
committerBen Finney <ben@benfinney.id.au>2008-05-16 16:11:06 +1000
commita953d82143f0ec979e18f17e8d9bbacbac954868 (patch)
tree42e76c37d72847d4fe3ca2487e227ae1649ad3c0 /aptsources
parent21ef2ab57d68de87a2b44a23d9a3bfb87d24d46d (diff)
downloadpython-apt-a953d82143f0ec979e18f17e8d9bbacbac954868.tar.gz
Fixes to blank lines, to conform with PEP 8.
Diffstat (limited to 'aptsources')
-rw-r--r--aptsources/__init__.py1
-rw-r--r--aptsources/distinfo.py27
-rw-r--r--aptsources/distro.py13
-rw-r--r--aptsources/sourceslist.py19
4 files changed, 52 insertions, 8 deletions
diff --git a/aptsources/__init__.py b/aptsources/__init__.py
index 8b137891..e69de29b 100644
--- a/aptsources/__init__.py
+++ b/aptsources/__init__.py
@@ -1 +0,0 @@
-
diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py
index bc567a3a..4a601be3 100644
--- a/aptsources/distinfo.py
+++ b/aptsources/distinfo.py
@@ -28,14 +28,17 @@ import gettext
from os import getenv
import ConfigParser
import string
+import re
#from gettext import gettext as _
import gettext
+
+
def _(s): return gettext.dgettext("python-apt", s)
-import re
class Template:
+
def __init__(self):
self.name = None
self.child = False
@@ -62,11 +65,14 @@ class Template:
else:
return False
+
class Component:
+
def __init__(self, name, desc=None, long_desc=None):
self.name = name
self.description = desc
self.description_long = long_desc
+
def get_description(self):
if self.description_long != None:
return self.description_long
@@ -74,24 +80,32 @@ class Component:
return self.description
else:
return None
+
def set_description(self, desc):
self.description = desc
+
def set_description_long(self, desc):
self.description_long = desc
+
def get_description_long(self):
return self.description_long
+
class Mirror:
''' Storage for mirror related information '''
+
def __init__(self, proto, hostname, dir, location=None):
self.hostname = hostname
self.repositories = []
self.add_repository(proto, dir)
self.location = location
+
def add_repository(self, proto, dir):
self.repositories.append(Repository(proto, dir))
+
def get_repositories_for_proto(self, proto):
return filter(lambda r: r.proto == proto, self.repositories)
+
def has_repository(self, proto, dir):
if dir is None:
return False
@@ -99,28 +113,38 @@ class Mirror:
if r.proto == proto and dir in r.dir:
return True
return False
+
def get_repo_urls(self):
return map(lambda r: r.get_url(self.hostname), self.repositories)
+
def get_location(self):
return self.location
+
def set_location(self, location):
self.location = location
+
class Repository:
+
def __init__(self, proto, dir):
self.proto = proto
self.dir = dir
+
def get_info(self):
return self.proto, self.dir
+
def get_url(self, hostname):
return "%s://%s/%s" % (self.proto, hostname, self.dir)
+
def split_url(url):
''' split a given URL into the protocoll, the hostname and the dir part '''
return map(lambda a,b: a, re.split(":*\/+", url, maxsplit=2),
[None, None, None])
+
class DistInfo:
+
def __init__(self,
dist = None,
base_dir = "/usr/share/python-apt/templates"):
@@ -140,7 +164,6 @@ class DistInfo:
self.dist = dist
-
map_mirror_sets = {}
dist_fname = "%s/%s.info" % (base_dir, dist)
diff --git a/aptsources/distro.py b/aptsources/distro.py
index 0a977445..faccc271 100644
--- a/aptsources/distro.py
+++ b/aptsources/distro.py
@@ -28,13 +28,17 @@ import os
import sys
import gettext
+
+
def _(s): return gettext.dgettext("python-apt", s)
class NoDistroTemplateException(Exception):
pass
+
class Distribution:
+
def __init__(self, id, codename, description, release):
""" Container for distribution specific informations """
# LSB information
@@ -199,6 +203,7 @@ class Distribution:
def get_server_list(self):
''' Return a list of used and suggested servers '''
+
def compare_mirrors(mir1, mir2):
'''Helper function that handles comaprision of mirror urls
that could contain trailing slashes'''
@@ -271,6 +276,7 @@ class Distribution:
comp: the component that should be enabled
"""
+
def add_component_only_once(source, comps_per_dist):
"""
Check if we already added the component to the repository, since
@@ -347,6 +353,7 @@ class Distribution:
def change_server(self, uri):
''' Change the server of all distro specific sources to
a given host '''
+
def change_server_of_source(source, uri, seen):
# Avoid creating duplicate entries
source.uri = uri
@@ -357,6 +364,7 @@ class Distribution:
seen.append([source.uri, source.dist, comp])
if len(source.comps) < 1:
self.sourceslist.remove(source)
+
seen_binary = []
seen_source = []
self.default_server = uri
@@ -377,6 +385,7 @@ class Distribution:
else:
return False
+
class DebianDistribution(Distribution):
''' Class to support specific Debian features '''
@@ -408,12 +417,15 @@ class DebianDistribution(Distribution):
Distribution.get_mirrors(self,
mirror_template="http://ftp.%s.debian.org/debian/")
+
class UbuntuDistribution(Distribution):
''' Class to support specific Ubuntu features '''
+
def get_mirrors(self):
Distribution.get_mirrors(self,
mirror_template="http://%s.archive.ubuntu.com/ubuntu/")
+
def get_distro():
''' Check the currently used distribution and return the corresponding
distriubtion class that supports distro specific features. '''
@@ -430,4 +442,3 @@ def get_distro():
return DebianDistribution(id, codename, description, release)
else:
return Distribution(id, codename, description, release)
-
diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py
index 4067920a..a8a772a0 100644
--- a/aptsources/sourceslist.py
+++ b/aptsources/sourceslist.py
@@ -36,7 +36,10 @@ import sys
#from UpdateManager.Common.DistInfo import DistInfo
from distinfo import DistInfo
+
# some global helpers
+
+
def is_mirror(master_uri, compare_uri):
"""check if the given add_url is idential or a mirror of orig_uri
e.g. master_uri = archive.ubuntu.com
@@ -66,12 +69,15 @@ def is_mirror(master_uri, compare_uri):
return True
return False
+
def uniq(s):
""" simple and efficient way to return uniq list """
return list(set(s))
+
class SourceEntry:
""" single sources.list entry """
+
def __init__(self, line,file=None):
self.invalid = False # is the source entry valid
self.disabled = False # is it disabled ('#' in front)
@@ -96,7 +102,6 @@ class SourceEntry:
self.dist == other.dist and
self.comps == other.comps)
-
def mysplit(self, line):
""" a split() implementation that understands the sources.list
format better and takes [] into account (for e.g. cdroms) """
@@ -208,13 +213,17 @@ class SourceEntry:
line += "\n"
return line
+
class NullMatcher(object):
""" a Matcher that does nothing """
+
def match(self, s):
return True
+
class SourcesList:
""" represents the full sources.list + sources.list.d file """
+
def __init__(self,
withMatcher=True,
matcherPath="/usr/share/python-apt/templates/"):
@@ -383,9 +392,12 @@ class SourcesList:
#print self.parents
return (parents, used_child_templates)
-# matcher class to make a source entry look nice
-# lots of predefined matchers to make it i18n/gettext friendly
+
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 = []
# Get the human readable channel and comp names from the channel .infos
@@ -435,4 +447,3 @@ if __name__ == "__main__":
"http://de.archive.ubuntu.com/ubuntu/")
print is_mirror("http://archive.ubuntu.com/ubuntu/",
"http://de.archive.ubuntu.com/ubuntu")
-