summaryrefslogtreecommitdiff
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
parent21ef2ab57d68de87a2b44a23d9a3bfb87d24d46d (diff)
downloadpython-apt-a953d82143f0ec979e18f17e8d9bbacbac954868.tar.gz
Fixes to blank lines, to conform with PEP 8.
-rw-r--r--apt/cache.py17
-rw-r--r--apt/cdrom.py6
-rw-r--r--apt/debfile.py6
-rw-r--r--apt/package.py25
-rw-r--r--apt/progress.py37
-rw-r--r--aptsources/__init__.py1
-rw-r--r--aptsources/distinfo.py27
-rw-r--r--aptsources/distro.py13
-rw-r--r--aptsources/sourceslist.py19
-rw-r--r--doc/examples/acquire.py4
-rw-r--r--doc/examples/action.py12
-rwxr-xr-xdoc/examples/build-deps.py2
-rw-r--r--doc/examples/cdrom.py6
-rwxr-xr-xdoc/examples/deb_inspect.py3
-rw-r--r--doc/examples/desc.py1
-rwxr-xr-xdoc/examples/gui-inst.py19
-rw-r--r--doc/examples/inst.py10
-rw-r--r--doc/examples/progress.py14
-rwxr-xr-xdoc/examples/recommends.py6
-rw-r--r--tests/cache.py2
-rw-r--r--tests/depcache.py1
-rw-r--r--tests/lock.py1
-rw-r--r--tests/pkgproblemresolver.py1
-rw-r--r--tests/pkgrecords.py2
-rw-r--r--tests/pkgsrcrecords.py2
-rw-r--r--tests/test_aptsources.py3
-rwxr-xr-xutils/get_debian_mirrors.py2
-rwxr-xr-xutils/get_ubuntu_mirrors.py2
-rwxr-xr-xutils/get_ubuntu_mirrors_from_lp.py3
29 files changed, 195 insertions, 52 deletions
diff --git a/apt/cache.py b/apt/cache.py
index 6773aeec..35da7970 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -25,16 +25,22 @@ import apt.progress
import os
import sys
+
class FetchCancelledException(IOError):
" Exception that is thrown when the user cancels a fetch operation "
pass
+
+
class FetchFailedException(IOError):
" Exception that is thrown when fetching fails "
pass
+
+
class LockFailedException(IOError):
" Exception that is thrown when locking fails "
pass
+
class Cache(object):
""" Dictionary-like package cache
This class has all the packages that are available in it's
@@ -227,6 +233,7 @@ class Cache(object):
return (res == pm.ResultCompleted)
# cache changes
+
def cachePostChange(self):
" called internally if the cache has changed, emit a signal then "
self._runCallbacks("cache_post_change")
@@ -243,28 +250,36 @@ class Cache(object):
self._callbacks[name] = []
self._callbacks[name].append(callback)
+
# ----------------------------- experimental interface
+
+
class Filter(object):
""" Filter base class """
+
def apply(self, pkg):
""" Filter function, return True if the package matchs a
filter criteria and False otherwise
"""
return True
+
class MarkedChangesFilter(Filter):
""" Filter that returns all marked changes """
+
def apply(self, pkg):
if pkg.markedInstall or pkg.markedDelete or pkg.markedUpgrade:
return True
else:
return False
+
class FilteredCache(object):
""" A package cache that is filtered.
Can work on a existing cache or create a new one
"""
+
def __init__(self, cache=None, progress=None):
if cache == None:
self.cache = Cache(progress)
@@ -274,6 +289,7 @@ class FilteredCache(object):
self.cache.connect("cache_post_open", self.filterCachePostChange)
self._filtered = {}
self._filters = []
+
def __len__(self):
return len(self._filtered)
@@ -323,6 +339,7 @@ class FilteredCache(object):
def cache_pre_changed():
print "cache pre changed"
+
def cache_post_changed():
print "cache post changed"
diff --git a/apt/cdrom.py b/apt/cdrom.py
index c0e57094..7f9b4776 100644
--- a/apt/cdrom.py
+++ b/apt/cdrom.py
@@ -1,7 +1,9 @@
import apt_pkg
from progress import CdromProgress
+
class Cdrom(object):
+
def __init__(self, progress=None, mountpoint=None, nomount=True):
""" Support for apt-cdrom like features.
Options:
@@ -22,15 +24,18 @@ class Cdrom(object):
apt_pkg.Config.Set("APT::CDROM::NoMount", "true")
else:
apt_pkg.Config.Set("APT::CDROM::NoMount", "false")
+
def add(self):
" add cdrom to the sources.list "
return self._cdrom.Add(self._progress)
+
def ident(self):
" identify the cdrom "
(res, ident) = self._cdrom.Ident(self._progress)
if res:
return ident
return None
+
@property
def inSourcesList(self):
" check if the cdrom is already in the current sources.list "
@@ -44,4 +49,3 @@ class Cdrom(object):
if not line.startswith("#") and cdid in line:
return True
return False
-
diff --git a/apt/debfile.py b/apt/debfile.py
index 73e0288d..365847d7 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -4,9 +4,11 @@ from apt_inst import arCheckMember
from gettext import gettext as _
+
class NoDebArchiveException(IOError):
pass
+
class DebPackage(object):
_supported_data_members = ("data.tar.gz", "data.tar.bz2", "data.tar.lzma")
@@ -31,10 +33,12 @@ class DebPackage(object):
def filelist(self):
""" return the list of files in the deb """
files = []
+
def extract_cb(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
#print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\
# % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor)
files.append(Name)
+
for member in self._supported_data_members:
if arCheckMember(open(self.filename), member):
try:
@@ -46,7 +50,6 @@ class DebPackage(object):
filelist = property(filelist)
-
if __name__ == "__main__":
import sys
@@ -55,4 +58,3 @@ if __name__ == "__main__":
print d["Maintainer"]
print "Files:"
print "\n".join(d.filelist)
-
diff --git a/apt/package.py b/apt/package.py
index 043f58ca..b771c677 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -26,40 +26,53 @@ import string
#from gettext import gettext as _
import gettext
+
+
def _(s): return gettext.dgettext("python-apt", s)
+
class BaseDependency(object):
" a single dependency "
+
def __init__(self, name, rel, ver, pre):
self.name = name
self.relation = rel
self.version = ver
self.preDepend = pre
+
class Dependency(object):
+
def __init__(self, alternatives):
self.or_dependencies = alternatives
+
class Record(object):
""" represents a pkgRecord, can be accessed like a
dictionary and gives the original package record
if accessed as a string """
+
def __init__(self, s):
self._str = s
self._rec = apt_pkg.ParseSection(s)
+
def __str__(self):
return self._str
+
def __getitem__(self, key):
k = self._rec.get(key)
if k is None:
raise KeyError
return k
+
def has_key(self, key):
return self._rec.has_key(key)
+
class Package(object):
""" This class represents a package in the cache
"""
+
def __init__(self, cache, depcache, records, sourcelist, pcache, pkgiter):
""" Init the Package object """
self._cache = cache # low level cache
@@ -71,6 +84,7 @@ class Package(object):
pass
# helper
+
def _lookupRecord(self, UseCandidate=True):
""" internal helper that moves the Records to the right
position, must be called before _records is accessed """
@@ -173,6 +187,7 @@ class Package(object):
if ver == None:
return False
return ver.Downloadable
+
def candidateDownloadable(self):
" returns if the canidate is downloadable "
return self._downloadable(useCandidate=True)
@@ -279,6 +294,7 @@ class Package(object):
installedRecord = property(installedRecord)
# depcache states
+
def markedInstall(self):
""" Package is marked for install """
return self._depcache.MarkedInstall(self._pkg)
@@ -320,6 +336,7 @@ class Package(object):
isUpgradable = property(isUpgradable)
# size
+
def packageSize(self):
""" The size of the candidate deb package """
ver = self._depcache.GetCandidateVer(self._pkg)
@@ -345,8 +362,9 @@ class Package(object):
return ver.InstalledSize
installedSize = property(installedSize)
- # canidate origin
class Origin:
+ """ Candidate origin """
+
def __init__(self, pkg, VerFileIter):
self.component = VerFileIter.Component
self.archive = VerFileIter.Archive
@@ -359,6 +377,7 @@ class Package(object):
self.trusted = True
else:
self.trusted = False
+
def __repr__(self):
return "component: '%s' archive: '%s' origin: '%s' label: '%s' " \
"site '%s' isTrusted: '%s'"% (self.component, self.archive,
@@ -376,11 +395,13 @@ class Package(object):
candidateOrigin = property(candidateOrigin)
# depcache actions
+
def markKeep(self):
""" mark a package for keep """
self._pcache.cachePreChange()
self._depcache.MarkKeep(self._pkg)
self._pcache.cachePostChange()
+
def markDelete(self, autoFix=True, purge=False):
""" mark a package for delete. Run the resolver if autoFix is set.
Mark the package as purge (remove with configuration) if 'purge'
@@ -397,6 +418,7 @@ class Package(object):
Fix.InstallProtect()
Fix.Resolve()
self._pcache.cachePostChange()
+
def markInstall(self, autoFix=True, autoInst=True, fromUser=True):
""" mark a package for install. Run the resolver if autoFix is set,
automatically install required dependencies if autoInst is set
@@ -411,6 +433,7 @@ class Package(object):
fixer.Protect(self._pkg)
fixer.Resolve(True)
self._pcache.cachePostChange()
+
def markUpgrade(self):
""" mark a package for upgrade """
if self.isUpgradable:
diff --git a/apt/progress.py b/apt/progress.py
index 19237a01..b50b2915 100644
--- a/apt/progress.py
+++ b/apt/progress.py
@@ -30,29 +30,36 @@ import apt_pkg
import apt
+
class OpProgress(object):
""" Abstract class to implement reporting on cache opening
Subclass this class to implement simple Operation progress reporting
"""
+
def __init__(self):
pass
+
def update(self, percent):
pass
+
def done(self):
pass
+
class OpTextProgress(OpProgress):
""" A simple text based cache open reporting class """
+
def __init__(self):
OpProgress.__init__(self)
+
def update(self, percent):
sys.stdout.write("\r%s: %.2i " % (self.subOp,percent))
sys.stdout.flush()
+
def done(self):
sys.stdout.write("\r%s: Done\n" % self.op)
-
class FetchProgress(object):
""" Report the download/fetching progress
Subclass this class to implement fetch progress reporting
@@ -92,17 +99,22 @@ class FetchProgress(object):
if self.currentCPS > 0:
self.eta = (self.totalBytes-self.currentBytes)/float(self.currentCPS)
return True
+
def mediaChange(self, medium, drive):
pass
+
class TextFetchProgress(FetchProgress):
""" Ready to use progress object for terminal windows """
+
def __init__(self):
self.items = {}
+
def updateStatus(self, uri, descr, shortDescr, status):
if status != self.dlQueued:
print "\r%s %s" % (self.dlStatusStr[status], descr)
self.items[uri] = status
+
def pulse(self):
FetchProgress.pulse(self)
if self.currentCPS > 0:
@@ -114,8 +126,10 @@ class TextFetchProgress(FetchProgress):
print "\r%s" % (s),
sys.stdout.flush()
return True
+
def stop(self):
print "\rDone downloading "
+
def mediaChange(self, medium, drive):
""" react to media change events """
res = True;
@@ -126,26 +140,34 @@ class TextFetchProgress(FetchProgress):
res = false;
return res
+
class DumbInstallProgress(object):
""" Report the install progress
Subclass this class to implement install progress reporting
"""
+
def __init__(self):
pass
+
def startUpdate(self):
pass
+
def run(self, pm):
return pm.DoInstall()
+
def finishUpdate(self):
pass
+
def updateInterface(self):
pass
+
class InstallProgress(DumbInstallProgress):
""" A InstallProgress that is pretty useful.
It supports the attributes 'percent' 'status' and callbacks
for the dpkg errors and conffiles and status changes
"""
+
def __init__(self):
DumbInstallProgress.__init__(self)
self.selectTimeout = 0.1
@@ -156,15 +178,19 @@ class InstallProgress(DumbInstallProgress):
self.read = ""
self.percent = 0.0
self.status = ""
+
def error(self, pkg, errormsg):
" called when a error is detected during the install "
pass
+
def conffile(self,current,new):
" called when a conffile question from dpkg is detected "
pass
+
def statusChange(self, pkg, percent, status):
" called when the status changed "
pass
+
def updateInterface(self):
if self.statusfd != None:
try:
@@ -199,8 +225,10 @@ class InstallProgress(DumbInstallProgress):
self.percent = float(percent)
self.status = string.strip(status_str)
self.read = ""
+
def fork(self):
return os.fork()
+
def waitChild(self):
while True:
select.select([self.statusfd],[],[], self.selectTimeout)
@@ -209,6 +237,7 @@ class InstallProgress(DumbInstallProgress):
if pid == self.child_pid:
break
return os.WEXITSTATUS(res)
+
def run(self, pm):
pid = self.fork()
if pid == 0:
@@ -219,20 +248,26 @@ class InstallProgress(DumbInstallProgress):
res = self.waitChild()
return res
+
class CdromProgress:
""" Report the cdrom add progress
Subclass this class to implement cdrom add progress reporting
"""
+
def __init__(self):
pass
+
def update(self, text, step):
""" update is called regularly so that the gui can be redrawn """
pass
+
def askCdromName(self):
pass
+
def changeCdrom(self):
pass
+
# module test code
if __name__ == "__main__":
import apt_pkg
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")
-
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
index cce3fb0d..07f8da0e 100644
--- a/doc/examples/acquire.py
+++ b/doc/examples/acquire.py
@@ -4,6 +4,7 @@ import os
import sys
import tempfile
+
def get_file(fetcher, uri, destFile):
cwd = os.getcwd()
# create a temp dir
@@ -86,6 +87,3 @@ print "fetcher.Run() returned: %s" % res
print "now runing pm.DoInstall()"
res = pm.DoInstall(1)
print "pm.DoInstall() returned: %s"% res
-
-
-
diff --git a/doc/examples/action.py b/doc/examples/action.py
index adf26539..9277129e 100644
--- a/doc/examples/action.py
+++ b/doc/examples/action.py
@@ -21,15 +21,6 @@ cache.Update(progress)
print "Exiting"
sys.exit(0)
-
-
-
-
-
-
-
-
-
iter = cache["base-config"]
print "example package iter: %s" % iter
@@ -45,7 +36,6 @@ depcache.Init(progress)
#sys.exit()
-
# get a canidate version
ver= depcache.GetCandidateVer(iter)
print "Candidate version: %s " % ver
@@ -66,7 +56,6 @@ depcache.MarkDelete(iter)
print "DelCount: %s " % depcache.DelCount
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
-
iter = cache["3dchess"]
print "\nMarking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
@@ -100,7 +89,6 @@ for pkg in cache.Packages:
if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) and depcache.IsUpgradable(pkg):
print "Upgrade didn't upgrade (kept): %s" % pkg.Name
-
print "\nPerforming DistUpgrade"
depcache.Upgrade(True)
print "Keep: %s " % depcache.KeepCount
diff --git a/doc/examples/build-deps.py b/doc/examples/build-deps.py
index fae7b55b..2d83a54f 100755
--- a/doc/examples/build-deps.py
+++ b/doc/examples/build-deps.py
@@ -5,6 +5,7 @@ import apt_pkg
import sys
import sets # only needed for python2.3, python2.4 supports this naively
+
def get_source_pkg(pkg, records, depcache):
""" get the source package name of a given package """
version = depcache.GetCandidateVer(pkg)
@@ -18,6 +19,7 @@ def get_source_pkg(pkg, records, depcache):
srcpkg = pkg.Name
return srcpkg
+
# main
apt_pkg.init()
cache = apt_pkg.GetCache()
diff --git a/doc/examples/cdrom.py b/doc/examples/cdrom.py
index bf044d7c..e54eb763 100644
--- a/doc/examples/cdrom.py
+++ b/doc/examples/cdrom.py
@@ -22,11 +22,5 @@ print "ident result is: %s (%s) " % (res, ident)
apt_pkg.Config.Set("APT::CDROM::Rename", "True")
cdrom.Add(progress)
-
-
print "Exiting"
sys.exit(0)
-
-
-
-
diff --git a/doc/examples/deb_inspect.py b/doc/examples/deb_inspect.py
index b57526c6..68219d6d 100755
--- a/doc/examples/deb_inspect.py
+++ b/doc/examples/deb_inspect.py
@@ -6,6 +6,7 @@ import apt_inst
import sys
import os.path
+
def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
""" callback for debExtract """
@@ -40,8 +41,10 @@ if __name__ == "__main__":
dir = "/tmp/deb"
os.mkdir(dir)
apt_inst.debExtractArchive(open(file),dir)
+
def visit(arg, dirname, names):
print "%s/" % dirname
for file in names:
print "\t%s" % file
+
os.path.walk(dir, visit, None)
diff --git a/doc/examples/desc.py b/doc/examples/desc.py
index 87b9473b..1d43f2f9 100644
--- a/doc/examples/desc.py
+++ b/doc/examples/desc.py
@@ -22,4 +22,3 @@ records.Lookup((f,index))
desc = records.LongDesc
print len(desc)
print desc
-
diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py
index 5e5d2c99..28887d34 100755
--- a/doc/examples/gui-inst.py
+++ b/doc/examples/gui-inst.py
@@ -18,7 +18,9 @@ import posix
from apt.progress import OpProgress, FetchProgress, InstallProgress
+
class GuiFetchProgress(gtk.Window, FetchProgress):
+
def __init__(self):
gtk.Window.__init__(self)
self.vbox = gtk.VBox()
@@ -31,12 +33,15 @@ class GuiFetchProgress(gtk.Window, FetchProgress):
self.vbox.pack_start(self.progress)
self.vbox.pack_start(self.label)
self.resize(300,100)
+
def start(self):
print "start"
self.progress.set_fraction(0.0)
self.show()
+
def stop(self):
self.hide()
+
def pulse(self):
FetchProgress.pulse(self)
self.label.set_text("Speed: %s/s" % apt_pkg.SizeToStr(self.currentCPS))
@@ -45,7 +50,9 @@ class GuiFetchProgress(gtk.Window, FetchProgress):
gtk.main_iteration()
return True
+
class TermInstallProgress(InstallProgress, gtk.Window):
+
def __init__(self):
gtk.Window.__init__(self)
InstallProgress.__init__(self)
@@ -63,13 +70,16 @@ class TermInstallProgress(InstallProgress, gtk.Window):
self.progressbar = gtk.ProgressBar()
self.progressbar.show()
box.pack_start(self.progressbar)
+
def child_exited(self,term, pid, status):
print "child_exited: %s %s %s %s" % (self,term,pid,status)
self.apt_status = posix.WEXITSTATUS(status)
self.finished = True
+
def startUpdate(self):
print "start"
self.show()
+
def waitChild(self):
while not self.finished:
self.updateInterface()
@@ -78,18 +88,20 @@ class TermInstallProgress(InstallProgress, gtk.Window):
time.sleep(0.001)
sys.stdin.readline()
return self.apt_status
+
def statusChange(self, pkg, percent, status):
print "statusChange", pkg, percent
self.progressbar.set_fraction(float(percent)/100.0)
self.progressbar.set_text(string.strip(status))
+
def fork(self):
env = ["VTE_PTY_KEEP_FD=%s"%self.writefd]
return self.term.forkpty(envv=env)
+
cache = apt.Cache()
print "Available packages: %s " % cache._cache.PackageCount
-
# update the cache
fprogress = GuiFetchProgress()
iprogress = TermInstallProgress()
@@ -101,12 +113,10 @@ iprogress = TermInstallProgress()
#depcache.ReadPinFile()
#depcache.Init(progress)
-
# show the interface
while gtk.events_pending():
gtk.main_iteration()
-
pkg = cache["3dchess"]
print "\n%s"%pkg.name
@@ -119,6 +129,3 @@ cache.commit(fprogress, iprogress)
print "Exiting"
sys.exit(0)
-
-
-
diff --git a/doc/examples/inst.py b/doc/examples/inst.py
index ff9d452c..d1e2ff99 100644
--- a/doc/examples/inst.py
+++ b/doc/examples/inst.py
@@ -8,10 +8,13 @@ import time
from apt.progress import InstallProgress
+
class TextInstallProgress(InstallProgress):
+
def __init__(self):
apt.progress.InstallProgress.__init__(self)
self.last = 0.0
+
def updateInterface(self):
InstallProgress.updateInterface(self)
if self.last >= self.percent:
@@ -19,11 +22,14 @@ class TextInstallProgress(InstallProgress):
sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status))
sys.stdout.flush()
self.last = self.percent
+
def conffile(self,current,new):
print "conffile prompt: %s %s" % (current,new)
+
def error(self, errorstr):
print "got dpkg error: '%s'" % errorstr
+
cache = apt.Cache(apt.progress.OpTextProgress())
fprogress = apt.progress.TextFetchProgress()
@@ -42,7 +48,3 @@ res = cache.commit(fprogress, iprogress)
print res
sys.exit(0)
-
-
-
-
diff --git a/doc/examples/progress.py b/doc/examples/progress.py
index b90253cb..39e73e70 100644
--- a/doc/examples/progress.py
+++ b/doc/examples/progress.py
@@ -4,7 +4,9 @@ import sys
import time
import string
+
class TextProgress(apt.OpProgress):
+
def __init__(self):
self.last=0.0
@@ -21,6 +23,7 @@ class TextProgress(apt.OpProgress):
class TextFetchProgress(apt.FetchProgress):
+
def __init__(self):
pass
@@ -32,6 +35,7 @@ class TextFetchProgress(apt.FetchProgress):
def updateStatus(self, uri, descr, shortDescr, status):
print "UpdateStatus: '%s' '%s' '%s' '%i'" % (uri,descr,shortDescr, status)
+
def pulse(self):
print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (SizeToStr(self.currentCPS), SizeToStr(self.currentBytes), SizeToStr(self.totalBytes), self.currentItems, self.totalItems)
return True
@@ -43,15 +47,20 @@ class TextFetchProgress(apt.FetchProgress):
class TextInstallProgress(apt.InstallProgress):
+
def __init__(self):
apt.InstallProgress.__init__(self)
pass
+
def startUpdate(self):
print "StartUpdate"
+
def finishUpdate(self):
print "FinishUpdate"
+
def statusChange(self, pkg, percent, status):
print "[%s] %s: %s" % (percent, pkg, status)
+
def updateInterface(self):
apt.InstallProgress.updateInterface(self)
# usefull to e.g. redraw a GUI
@@ -59,17 +68,22 @@ class TextInstallProgress(apt.InstallProgress):
class TextCdromProgress(apt.CdromProgress):
+
def __init__(self):
pass
+
# update is called regularly so that the gui can be redrawn
+
def update(self, text, step):
# check if we actually have some text to display
if text != "":
print "Update: %s %s" % (string.strip(text), step)
+
def askCdromName(self):
print "Please enter cd-name: ",
cd_name = sys.stdin.readline()
return (True, string.strip(cd_name))
+
def changeCdrom(self):
print "Please insert cdrom and press <ENTER>"
answer = sys.stdin.readline()
diff --git a/doc/examples/recommends.py b/doc/examples/recommends.py
index c1a7eb2e..03d46068 100755
--- a/doc/examples/recommends.py
+++ b/doc/examples/recommends.py
@@ -5,6 +5,7 @@ apt_pkg.init()
cache = apt_pkg.GetCache()
+
class Wanted:
def __init__(self, name):
@@ -12,6 +13,7 @@ class Wanted:
self.recommended = []
self.suggested = []
+
wanted = {}
for package in cache.Packages:
@@ -35,7 +37,3 @@ ks.sort()
for want in ks:
print want, wanted[want].recommended, wanted[want].suggested
-
-
-
-
diff --git a/tests/cache.py b/tests/cache.py
index 3ec87b40..34535e68 100644
--- a/tests/cache.py
+++ b/tests/cache.py
@@ -6,6 +6,7 @@
import apt_pkg
import sys
+
def main():
apt_pkg.init()
cache = apt_pkg.GetCache()
@@ -44,6 +45,7 @@ def main():
print "\r%i/%i=%.3f%% " % (i,all,(float(i)/float(all)*100)),
+
if __name__ == "__main__":
main()
sys.exit(0)
diff --git a/tests/depcache.py b/tests/depcache.py
index 5c78c3a1..635fea14 100644
--- a/tests/depcache.py
+++ b/tests/depcache.py
@@ -6,6 +6,7 @@
import apt_pkg
import sys
+
def main():
apt_pkg.init()
cache = apt_pkg.GetCache()
diff --git a/tests/lock.py b/tests/lock.py
index 86d704ea..a3d962d7 100644
--- a/tests/lock.py
+++ b/tests/lock.py
@@ -44,4 +44,3 @@ if __name__ == "__main__":
fd = apt_pkg.GetLock(lock,True)
print "Lockfile fd (child): %s" % fd
sys.exit(0)
-
diff --git a/tests/pkgproblemresolver.py b/tests/pkgproblemresolver.py
index 0ed32ea6..546e2f16 100644
--- a/tests/pkgproblemresolver.py
+++ b/tests/pkgproblemresolver.py
@@ -6,6 +6,7 @@
import apt_pkg
import sys
+
def main():
apt_pkg.init()
cache = apt_pkg.GetCache()
diff --git a/tests/pkgrecords.py b/tests/pkgrecords.py
index 43723569..308505f7 100644
--- a/tests/pkgrecords.py
+++ b/tests/pkgrecords.py
@@ -7,6 +7,7 @@
import apt_pkg
import sys
+
def main():
apt_pkg.init()
cache = apt_pkg.GetCache()
@@ -31,6 +32,7 @@ def main():
pass
print "\r%i/%i=%.3f%% " % (i,cache.PackageCount, (float(i)/float(cache.PackageCount)*100)),
+
if __name__ == "__main__":
main()
sys.exit(0)
diff --git a/tests/pkgsrcrecords.py b/tests/pkgsrcrecords.py
index 06c4a1ef..410140c8 100644
--- a/tests/pkgsrcrecords.py
+++ b/tests/pkgsrcrecords.py
@@ -7,6 +7,7 @@
import apt_pkg
import sys
+
def main():
apt_pkg.init()
cache = apt_pkg.GetCache()
@@ -20,6 +21,7 @@ def main():
pass
print "\r%i/%i=%.3f%% " % (i,cache.PackageCount, (float(i)/float(cache.PackageCount)*100)),
+
if __name__ == "__main__":
main()
sys.exit(0)
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py
index 734503d2..08c8194a 100644
--- a/tests/test_aptsources.py
+++ b/tests/test_aptsources.py
@@ -6,7 +6,9 @@ import apt_pkg
import os
import copy
+
class TestAptSources(unittest.TestCase):
+
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)
apt_pkg.init()
@@ -123,5 +125,6 @@ class TestAptSources(unittest.TestCase):
for key in found:
self.assertEqual(found[key], 1)
+
if __name__ == "__main__":
unittest.main()
diff --git a/utils/get_debian_mirrors.py b/utils/get_debian_mirrors.py
index 512731ed..2e3c7296 100755
--- a/utils/get_debian_mirrors.py
+++ b/utils/get_debian_mirrors.py
@@ -39,11 +39,13 @@ req = urllib2.Request("http://www.debian.org/mirror/mirrors_full")
match = re.compile("^.*>([A-Za-z0-9-.\/_]+)<\/a>.*\n$")
match_location = re.compile('^<strong><a name="([A-Z]+)">.*')
+
def add_sites(line, proto, sites, mirror_type):
path = match.sub(r"\1", line)
for site in sites:
mirror_type.append("%s://%s%s\n" % (proto, site.lstrip(), path))
+
try:
print "Downloading mirrors list from the Debian website..."
uri=urllib2.urlopen(req)
diff --git a/utils/get_ubuntu_mirrors.py b/utils/get_ubuntu_mirrors.py
index 605edcf5..8482615d 100755
--- a/utils/get_ubuntu_mirrors.py
+++ b/utils/get_ubuntu_mirrors.py
@@ -57,5 +57,3 @@ for mirror in mirrors:
list.write("%s\n" % mirror)
list.close()
print "Done."
-
-
diff --git a/utils/get_ubuntu_mirrors_from_lp.py b/utils/get_ubuntu_mirrors_from_lp.py
index 1f41e34b..59ddd84e 100755
--- a/utils/get_ubuntu_mirrors_from_lp.py
+++ b/utils/get_ubuntu_mirrors_from_lp.py
@@ -64,6 +64,8 @@ content_splits = re.split(r'<tr class="highlighted"',
'id="mirrors_list">.+?</table>',
content)[0])
lines=[]
+
+
def find(split):
country = re.search(r"<strong>(.+?)</strong>", split)
if not country:
@@ -78,6 +80,7 @@ def find(split):
split)
map(lambda u: lines.append(u[0]), urls)
+
map(find, content_splits)
print "Writing local mirrors list: %s" % list_path