Merge lp:~mac9416/keryx/1.0 into lp:~keryx-admins/keryx/1.0

Proposed by mac9416
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mac9416/keryx/1.0
Merge into: lp:~keryx-admins/keryx/1.0
Diff against target: 188 lines (+77/-42)
1 file modified
src/libkeryx/definitions/apt_def/__init__.py (+77/-42)
To merge this branch: bzr merge lp:~mac9416/keryx/1.0
Reviewer Review Type Date Requested Status
Chris Oliver Approve
Review via email: mp+17860@code.launchpad.net
To post a comment you must log in.
Revision history for this message
mac9416 (mac9416) wrote :

I'm almost certain I improved something.

Revision history for this message
Chris Oliver (excid3) wrote :

Looks good. Go ahead and merge :)

review: Approve
Revision history for this message
mac9416 (mac9416) wrote :

Roger roger.

On Thu, Jan 21, 2010 at 8:11 PM, Chris Oliver <email address hidden> wrote:
> Review: Approve
> Looks good. Go ahead and merge :)
> --
> https://code.launchpad.net/~mac9416/keryx/1.0/+merge/17860
> You are the owner of lp:~mac9416/keryx/1.0.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libkeryx/definitions/apt_def/__init__.py'
2--- src/libkeryx/definitions/apt_def/__init__.py 2010-01-17 00:03:51 +0000
3+++ src/libkeryx/definitions/apt_def/__init__.py 2010-01-22 00:52:13 +0000
4@@ -224,7 +224,9 @@
5 for p in packages:
6 errcode, failure = commands.getstatusoutput("sudo apt-get -y -o dir::cache::archives=\"%s\" install %s" % (downloads_folder, p))
7 if errcode:
8- logging.error(failure)
9+ #FIXME: this line is causing unicode errors
10+ #logging.error(failure)
11+ print failure
12 return
13
14 print "Finished installing.\n" \
15@@ -349,6 +351,7 @@
16
17 if found:
18 #TODO: Remove the source from the database
19+ pass
20 else:
21 logging.error("Source line not found in database: %s" % line)
22 return False
23@@ -407,7 +410,6 @@
24
25 def __calculate_downloads(self, downloads, package, ver=None):
26 """Calculates a list of packages to download"""
27-
28 # If we aren't looking for a specific version, get the latest
29 if not ver:
30 url, ver = self.apt_client.get_best_binary_version(package)
31@@ -417,11 +419,16 @@
32 if pkg:
33 pkg = pkg[0]
34 else:
35+ #TODO: Check if the elusive software is provided by another package.
36 logging.error('Package %s not found.' % package)
37 return downloads
38
39- # Add the package itself to be downloaded if it is not installed
40- downloads.append(pkg)
41+ # Add the package itself to be downloaded if the latest is not installed
42+ if self.__is_installed(package, '>=', ver):
43+ print "%s is already the newest version" % (package)
44+ return
45+ else:
46+ downloads.append(pkg)
47
48 # We need to grab both the depends and recommends packages
49 dependencies = []
50@@ -430,9 +437,10 @@
51 if pkg.has_key('recommends'):
52 dependencies += pkg['recommends'].split(',')
53
54- # Iterate through each package
55+ # Iterate through each dependency
56 for dep in dependencies:
57- # Get "or" packages
58+ # dep will hold a list of [name, version] tuples representing
59+ # several packages that can fill the dependency ("or" packages)
60 dep = dep.split('|')
61
62 # Build (name, version) tuples for each in this section
63@@ -448,48 +456,43 @@
64
65 found = False
66 # Check if any of these are installed or ready to be downloaded
67- #TODO: Check the installed/download package's Provides as well
68+ # If any is found, the dependency is taken care of, and we'll move
69+ # onto the next dependency.
70 for p in dep:
71- try:
72- comparison, version = p[1].split()
73- needed_version = DpkgVersion(version)
74- except:
75+ if len(p[1].split()) > 1:
76+ # A version is specified
77+ comparison, needed_version = p[1].split()
78+ else:
79 # We have no version specified
80- comparison = '>>'
81- needed_version = DpkgVersion('0')
82-
83- # Test against status entries
84- #FIXME: Can we reference these through the backref install??
85- status_refs = self.session.query(Status). \
86- filter(Status.proj_id==self.project_ref.id). \
87- filter(Status.name==p[0]).all()
88-
89- for ref in status_refs:
90- installed_version = DpkgVersion(ref.version)
91- found = self.__compare_found(installed_version,
92- comparison,
93- needed_version)
94+ comparison = '>>' #FIXME: Should this be '>=' ?
95+ needed_version = '0'
96+
97+ # Test against downloads
98+ for d in downloads:
99+ if d['package'] == p[0]:
100+ # Matching package name, test its version against
101+ installed_version = d['version']
102+ found = self.__compare_found(installed_version,
103+ comparison,
104+ needed_version)
105 if found:
106- break
107-
108- if not found:
109- # Test against downloads
110- for d in downloads:
111- if d['package'] == p[0]:
112- # Matching package name, test its version against
113- installed_version = DpkgVersion(d['version'])
114- found = self.__compare_found(installed_version,
115- comparison,
116- needed_version)
117- if found:
118- break
119-
120- # We must have found it on the past iteration
121+ break # Break out of this loop...
122 if found:
123+ break # Now break out of the bigger loop.
124+
125+ # See if this dependency is already installed
126+ #TODO: upgrade if possible
127+ if self.__is_installed(p[0], comparison, needed_version):
128+ # The package is installed, and dependency met. Move along.
129+ found = True
130+ break
131+
132+ if self.__should_upgrade(p[0], comparison, needed_version):
133 break
134
135 if not found:
136- # Just grab the first package
137+ # This dependency is not satisifed, so we should just get the
138+ # first option among the "or" packages.
139 #print "Checking %s" % dep[0][0]
140 downloads = self.__calculate_downloads(downloads, dep[0][0])
141
142@@ -504,8 +507,41 @@
143
144 return downloads
145
146+ def __is_installed(self, package, comparison, version):
147+ """Checks whether a package is installed"""
148+ #TODO: Check provides as well
149+ # Check against status entries
150+ #FIXME: Can we reference these through the backref install??
151+ status_refs = self.session.query(Status). \
152+ filter(Status.proj_id==self.project_ref.id). \
153+ filter(Status.name==package).all()
154+
155+ for ref in status_refs:
156+ installed_version = ref.version
157+ needed_version = version
158+ found = self.__compare_found(installed_version,
159+ comparison,
160+ needed_version)
161+ if found:
162+ return True
163+ return False
164+
165+ def __should_upgrade(self, package, comparison, needed_version):
166+ """Check whether there is a newer version available and whether
167+ it fits the dependency
168+ """
169+ latest_version = self.apt_client.get_best_binary_version(package)[1]
170+ if self.__is_installed(package, "<<", latest_version):
171+ # The latest version is not installed
172+ if self.__compare_found(latest_version, comparison, needed_version):
173+ # The latest version fits the comparison
174+ return True
175+ return False
176+
177 def __compare_found(self, v1, comparison, v2):
178 """Make a comparison between two versions and return the result"""
179+ v1 = DpkgVersion(v1)
180+ v2 = DpkgVersion(v2)
181 if (comparison == '>>' and v1 > v2) or \
182 (comparison == '>=' and v1 >= v2) or \
183 (comparison == '=' and v1 == v2) or \
184@@ -513,4 +549,3 @@
185 (comparison == '<<' and v1 < v2):
186 return True
187 return False
188-

Subscribers

People subscribed via source and target branches

to all changes: