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
=== modified file 'src/libkeryx/definitions/apt_def/__init__.py'
--- src/libkeryx/definitions/apt_def/__init__.py 2010-01-17 00:03:51 +0000
+++ src/libkeryx/definitions/apt_def/__init__.py 2010-01-22 00:52:13 +0000
@@ -224,7 +224,9 @@
224 for p in packages:224 for p in packages:
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))
226 if errcode:226 if errcode:
227 logging.error(failure)227 #FIXME: this line is causing unicode errors
228 #logging.error(failure)
229 print failure
228 return230 return
229 231
230 print "Finished installing.\n" \232 print "Finished installing.\n" \
@@ -349,6 +351,7 @@
349351
350 if found:352 if found:
351 #TODO: Remove the source from the database353 #TODO: Remove the source from the database
354 pass
352 else:355 else:
353 logging.error("Source line not found in database: %s" % line)356 logging.error("Source line not found in database: %s" % line)
354 return False357 return False
@@ -407,7 +410,6 @@
407410
408 def __calculate_downloads(self, downloads, package, ver=None):411 def __calculate_downloads(self, downloads, package, ver=None):
409 """Calculates a list of packages to download"""412 """Calculates a list of packages to download"""
410
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
412 if not ver:414 if not ver:
413 url, ver = self.apt_client.get_best_binary_version(package)415 url, ver = self.apt_client.get_best_binary_version(package)
@@ -417,11 +419,16 @@
417 if pkg:419 if pkg:
418 pkg = pkg[0]420 pkg = pkg[0]
419 else:421 else:
422 #TODO: Check if the elusive software is provided by another package.
420 logging.error('Package %s not found.' % package)423 logging.error('Package %s not found.' % package)
421 return downloads424 return downloads
422425
423 # Add the package itself to be downloaded if it is not installed426 # Add the package itself to be downloaded if the latest is not installed
424 downloads.append(pkg)427 if self.__is_installed(package, '>=', ver):
428 print "%s is already the newest version" % (package)
429 return
430 else:
431 downloads.append(pkg)
425432
426 # We need to grab both the depends and recommends packages433 # We need to grab both the depends and recommends packages
427 dependencies = []434 dependencies = []
@@ -430,9 +437,10 @@
430 if pkg.has_key('recommends'):437 if pkg.has_key('recommends'):
431 dependencies += pkg['recommends'].split(',')438 dependencies += pkg['recommends'].split(',')
432439
433 # Iterate through each package440 # Iterate through each dependency
434 for dep in dependencies:441 for dep in dependencies:
435 # Get "or" packages442 # dep will hold a list of [name, version] tuples representing
443 # several packages that can fill the dependency ("or" packages)
436 dep = dep.split('|')444 dep = dep.split('|')
437445
438 # Build (name, version) tuples for each in this section446 # Build (name, version) tuples for each in this section
@@ -448,48 +456,43 @@
448456
449 found = False457 found = False
450 # Check if any of these are installed or ready to be downloaded458 # Check if any of these are installed or ready to be downloaded
451 #TODO: Check the installed/download package's Provides as well459 # If any is found, the dependency is taken care of, and we'll move
460 # onto the next dependency.
452 for p in dep:461 for p in dep:
453 try:462 if len(p[1].split()) > 1:
454 comparison, version = p[1].split()463 # A version is specified
455 needed_version = DpkgVersion(version)464 comparison, needed_version = p[1].split()
456 except: 465 else:
457 # We have no version specified466 # We have no version specified
458 comparison = '>>'467 comparison = '>>' #FIXME: Should this be '>=' ?
459 needed_version = DpkgVersion('0')468 needed_version = '0'
460469
461 # Test against status entries470 # Test against downloads
462 #FIXME: Can we reference these through the backref install??471 for d in downloads:
463 status_refs = self.session.query(Status). \472 if d['package'] == p[0]:
464 filter(Status.proj_id==self.project_ref.id). \473 # Matching package name, test its version against
465 filter(Status.name==p[0]).all()474 installed_version = d['version']
466475 found = self.__compare_found(installed_version,
467 for ref in status_refs:476 comparison,
468 installed_version = DpkgVersion(ref.version) 477 needed_version)
469 found = self.__compare_found(installed_version,
470 comparison,
471 needed_version)
472 if found:478 if found:
473 break479 break # Break out of this loop...
474
475 if not found:
476 # Test against downloads
477 for d in downloads:
478 if d['package'] == p[0]:
479 # Matching package name, test its version against
480 installed_version = DpkgVersion(d['version'])
481 found = self.__compare_found(installed_version,
482 comparison,
483 needed_version)
484 if found:
485 break
486
487 # We must have found it on the past iteration
488 if found: 480 if found:
481 break # Now break out of the bigger loop.
482
483 # See if this dependency is already installed
484 #TODO: upgrade if possible
485 if self.__is_installed(p[0], comparison, needed_version):
486 # The package is installed, and dependency met. Move along.
487 found = True
488 break
489
490 if self.__should_upgrade(p[0], comparison, needed_version):
489 break491 break
490492
491 if not found:493 if not found:
492 # Just grab the first package494 # This dependency is not satisifed, so we should just get the
495 # first option among the "or" packages.
493 #print "Checking %s" % dep[0][0]496 #print "Checking %s" % dep[0][0]
494 downloads = self.__calculate_downloads(downloads, dep[0][0])497 downloads = self.__calculate_downloads(downloads, dep[0][0])
495 498
@@ -504,8 +507,41 @@
504507
505 return downloads508 return downloads
506509
510 def __is_installed(self, package, comparison, version):
511 """Checks whether a package is installed"""
512 #TODO: Check provides as well
513 # Check against status entries
514 #FIXME: Can we reference these through the backref install??
515 status_refs = self.session.query(Status). \
516 filter(Status.proj_id==self.project_ref.id). \
517 filter(Status.name==package).all()
518
519 for ref in status_refs:
520 installed_version = ref.version
521 needed_version = version
522 found = self.__compare_found(installed_version,
523 comparison,
524 needed_version)
525 if found:
526 return True
527 return False
528
529 def __should_upgrade(self, package, comparison, needed_version):
530 """Check whether there is a newer version available and whether
531 it fits the dependency
532 """
533 latest_version = self.apt_client.get_best_binary_version(package)[1]
534 if self.__is_installed(package, "<<", latest_version):
535 # The latest version is not installed
536 if self.__compare_found(latest_version, comparison, needed_version):
537 # The latest version fits the comparison
538 return True
539 return False
540
507 def __compare_found(self, v1, comparison, v2):541 def __compare_found(self, v1, comparison, v2):
508 """Make a comparison between two versions and return the result"""542 """Make a comparison between two versions and return the result"""
543 v1 = DpkgVersion(v1)
544 v2 = DpkgVersion(v2)
509 if (comparison == '>>' and v1 > v2) or \545 if (comparison == '>>' and v1 > v2) or \
510 (comparison == '>=' and v1 >= v2) or \546 (comparison == '>=' and v1 >= v2) or \
511 (comparison == '=' and v1 == v2) or \547 (comparison == '=' and v1 == v2) or \
@@ -513,4 +549,3 @@
513 (comparison == '<<' and v1 < v2): 549 (comparison == '<<' and v1 < v2):
514 return True550 return True
515 return False551 return False
516

Subscribers

People subscribed via source and target branches

to all changes: