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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Oliver | Approve | ||
Review via email: mp+17860@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
mac9416 (mac9416) wrote : | # |
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:/
> 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 | 224 | for p in packages: | 224 | for p in packages: |
6 | 225 | errcode, failure = commands.getstatusoutput("sudo apt-get -y -o dir::cache::archives=\"%s\" install %s" % (downloads_folder, p)) | 225 | errcode, failure = commands.getstatusoutput("sudo apt-get -y -o dir::cache::archives=\"%s\" install %s" % (downloads_folder, p)) |
7 | 226 | if errcode: | 226 | if errcode: |
9 | 227 | logging.error(failure) | 227 | #FIXME: this line is causing unicode errors |
10 | 228 | #logging.error(failure) | ||
11 | 229 | print failure | ||
12 | 228 | return | 230 | return |
13 | 229 | 231 | ||
14 | 230 | print "Finished installing.\n" \ | 232 | print "Finished installing.\n" \ |
15 | @@ -349,6 +351,7 @@ | |||
16 | 349 | 351 | ||
17 | 350 | if found: | 352 | if found: |
18 | 351 | #TODO: Remove the source from the database | 353 | #TODO: Remove the source from the database |
19 | 354 | pass | ||
20 | 352 | else: | 355 | else: |
21 | 353 | logging.error("Source line not found in database: %s" % line) | 356 | logging.error("Source line not found in database: %s" % line) |
22 | 354 | return False | 357 | return False |
23 | @@ -407,7 +410,6 @@ | |||
24 | 407 | 410 | ||
25 | 408 | def __calculate_downloads(self, downloads, package, ver=None): | 411 | def __calculate_downloads(self, downloads, package, ver=None): |
26 | 409 | """Calculates a list of packages to download""" | 412 | """Calculates a list of packages to download""" |
27 | 410 | |||
28 | 411 | # If we aren't looking for a specific version, get the latest | 413 | # If we aren't looking for a specific version, get the latest |
29 | 412 | if not ver: | 414 | if not ver: |
30 | 413 | url, ver = self.apt_client.get_best_binary_version(package) | 415 | url, ver = self.apt_client.get_best_binary_version(package) |
31 | @@ -417,11 +419,16 @@ | |||
32 | 417 | if pkg: | 419 | if pkg: |
33 | 418 | pkg = pkg[0] | 420 | pkg = pkg[0] |
34 | 419 | else: | 421 | else: |
35 | 422 | #TODO: Check if the elusive software is provided by another package. | ||
36 | 420 | logging.error('Package %s not found.' % package) | 423 | logging.error('Package %s not found.' % package) |
37 | 421 | return downloads | 424 | return downloads |
38 | 422 | 425 | ||
41 | 423 | # Add the package itself to be downloaded if it is not installed | 426 | # Add the package itself to be downloaded if the latest is not installed |
42 | 424 | downloads.append(pkg) | 427 | if self.__is_installed(package, '>=', ver): |
43 | 428 | print "%s is already the newest version" % (package) | ||
44 | 429 | return | ||
45 | 430 | else: | ||
46 | 431 | downloads.append(pkg) | ||
47 | 425 | 432 | ||
48 | 426 | # We need to grab both the depends and recommends packages | 433 | # We need to grab both the depends and recommends packages |
49 | 427 | dependencies = [] | 434 | dependencies = [] |
50 | @@ -430,9 +437,10 @@ | |||
51 | 430 | if pkg.has_key('recommends'): | 437 | if pkg.has_key('recommends'): |
52 | 431 | dependencies += pkg['recommends'].split(',') | 438 | dependencies += pkg['recommends'].split(',') |
53 | 432 | 439 | ||
55 | 433 | # Iterate through each package | 440 | # Iterate through each dependency |
56 | 434 | for dep in dependencies: | 441 | for dep in dependencies: |
58 | 435 | # Get "or" packages | 442 | # dep will hold a list of [name, version] tuples representing |
59 | 443 | # several packages that can fill the dependency ("or" packages) | ||
60 | 436 | dep = dep.split('|') | 444 | dep = dep.split('|') |
61 | 437 | 445 | ||
62 | 438 | # Build (name, version) tuples for each in this section | 446 | # Build (name, version) tuples for each in this section |
63 | @@ -448,48 +456,43 @@ | |||
64 | 448 | 456 | ||
65 | 449 | found = False | 457 | found = False |
66 | 450 | # Check if any of these are installed or ready to be downloaded | 458 | # Check if any of these are installed or ready to be downloaded |
68 | 451 | #TODO: Check the installed/download package's Provides as well | 459 | # If any is found, the dependency is taken care of, and we'll move |
69 | 460 | # onto the next dependency. | ||
70 | 452 | for p in dep: | 461 | for p in dep: |
75 | 453 | try: | 462 | if len(p[1].split()) > 1: |
76 | 454 | comparison, version = p[1].split() | 463 | # A version is specified |
77 | 455 | needed_version = DpkgVersion(version) | 464 | comparison, needed_version = p[1].split() |
78 | 456 | except: | 465 | else: |
79 | 457 | # We have no version specified | 466 | # We have no version specified |
94 | 458 | comparison = '>>' | 467 | comparison = '>>' #FIXME: Should this be '>=' ? |
95 | 459 | needed_version = DpkgVersion('0') | 468 | needed_version = '0' |
96 | 460 | 469 | ||
97 | 461 | # Test against status entries | 470 | # Test against downloads |
98 | 462 | #FIXME: Can we reference these through the backref install?? | 471 | for d in downloads: |
99 | 463 | status_refs = self.session.query(Status). \ | 472 | if d['package'] == p[0]: |
100 | 464 | filter(Status.proj_id==self.project_ref.id). \ | 473 | # Matching package name, test its version against |
101 | 465 | filter(Status.name==p[0]).all() | 474 | installed_version = d['version'] |
102 | 466 | 475 | found = self.__compare_found(installed_version, | |
103 | 467 | for ref in status_refs: | 476 | comparison, |
104 | 468 | installed_version = DpkgVersion(ref.version) | 477 | needed_version) |
91 | 469 | found = self.__compare_found(installed_version, | ||
92 | 470 | comparison, | ||
93 | 471 | needed_version) | ||
105 | 472 | if found: | 478 | if found: |
121 | 473 | break | 479 | break # Break out of this loop... |
107 | 474 | |||
108 | 475 | if not found: | ||
109 | 476 | # Test against downloads | ||
110 | 477 | for d in downloads: | ||
111 | 478 | if d['package'] == p[0]: | ||
112 | 479 | # Matching package name, test its version against | ||
113 | 480 | installed_version = DpkgVersion(d['version']) | ||
114 | 481 | found = self.__compare_found(installed_version, | ||
115 | 482 | comparison, | ||
116 | 483 | needed_version) | ||
117 | 484 | if found: | ||
118 | 485 | break | ||
119 | 486 | |||
120 | 487 | # We must have found it on the past iteration | ||
122 | 488 | if found: | 480 | if found: |
123 | 481 | break # Now break out of the bigger loop. | ||
124 | 482 | |||
125 | 483 | # See if this dependency is already installed | ||
126 | 484 | #TODO: upgrade if possible | ||
127 | 485 | if self.__is_installed(p[0], comparison, needed_version): | ||
128 | 486 | # The package is installed, and dependency met. Move along. | ||
129 | 487 | found = True | ||
130 | 488 | break | ||
131 | 489 | |||
132 | 490 | if self.__should_upgrade(p[0], comparison, needed_version): | ||
133 | 489 | break | 491 | break |
134 | 490 | 492 | ||
135 | 491 | if not found: | 493 | if not found: |
137 | 492 | # Just grab the first package | 494 | # This dependency is not satisifed, so we should just get the |
138 | 495 | # first option among the "or" packages. | ||
139 | 493 | #print "Checking %s" % dep[0][0] | 496 | #print "Checking %s" % dep[0][0] |
140 | 494 | downloads = self.__calculate_downloads(downloads, dep[0][0]) | 497 | downloads = self.__calculate_downloads(downloads, dep[0][0]) |
141 | 495 | 498 | ||
142 | @@ -504,8 +507,41 @@ | |||
143 | 504 | 507 | ||
144 | 505 | return downloads | 508 | return downloads |
145 | 506 | 509 | ||
146 | 510 | def __is_installed(self, package, comparison, version): | ||
147 | 511 | """Checks whether a package is installed""" | ||
148 | 512 | #TODO: Check provides as well | ||
149 | 513 | # Check against status entries | ||
150 | 514 | #FIXME: Can we reference these through the backref install?? | ||
151 | 515 | status_refs = self.session.query(Status). \ | ||
152 | 516 | filter(Status.proj_id==self.project_ref.id). \ | ||
153 | 517 | filter(Status.name==package).all() | ||
154 | 518 | |||
155 | 519 | for ref in status_refs: | ||
156 | 520 | installed_version = ref.version | ||
157 | 521 | needed_version = version | ||
158 | 522 | found = self.__compare_found(installed_version, | ||
159 | 523 | comparison, | ||
160 | 524 | needed_version) | ||
161 | 525 | if found: | ||
162 | 526 | return True | ||
163 | 527 | return False | ||
164 | 528 | |||
165 | 529 | def __should_upgrade(self, package, comparison, needed_version): | ||
166 | 530 | """Check whether there is a newer version available and whether | ||
167 | 531 | it fits the dependency | ||
168 | 532 | """ | ||
169 | 533 | latest_version = self.apt_client.get_best_binary_version(package)[1] | ||
170 | 534 | if self.__is_installed(package, "<<", latest_version): | ||
171 | 535 | # The latest version is not installed | ||
172 | 536 | if self.__compare_found(latest_version, comparison, needed_version): | ||
173 | 537 | # The latest version fits the comparison | ||
174 | 538 | return True | ||
175 | 539 | return False | ||
176 | 540 | |||
177 | 507 | def __compare_found(self, v1, comparison, v2): | 541 | def __compare_found(self, v1, comparison, v2): |
178 | 508 | """Make a comparison between two versions and return the result""" | 542 | """Make a comparison between two versions and return the result""" |
179 | 543 | v1 = DpkgVersion(v1) | ||
180 | 544 | v2 = DpkgVersion(v2) | ||
181 | 509 | if (comparison == '>>' and v1 > v2) or \ | 545 | if (comparison == '>>' and v1 > v2) or \ |
182 | 510 | (comparison == '>=' and v1 >= v2) or \ | 546 | (comparison == '>=' and v1 >= v2) or \ |
183 | 511 | (comparison == '=' and v1 == v2) or \ | 547 | (comparison == '=' and v1 == v2) or \ |
184 | @@ -513,4 +549,3 @@ | |||
185 | 513 | (comparison == '<<' and v1 < v2): | 549 | (comparison == '<<' and v1 < v2): |
186 | 514 | return True | 550 | return True |
187 | 515 | return False | 551 | return False |
188 | 516 |
I'm almost certain I improved something.