Commits

Garth Johnson  committed fad67e4

Checkmix version command mods (in progress)

  • Participants
  • Parent commits 656c03e

Comments (0)

Files changed (3)

File djaboto/__init__.py

 # -*- coding: utf-8 -*-
 VERSION = (0,0,6,'alpha',3)
 
-import debian
+import debian, pve
 
 def get_version(version=None):
     """Derives a PEP386-compliant version number from VERSION."""

File djaboto/management/commands/checkmix.py

 ###TODO: move all code from this command to libraries and connect aws command to the same calls
 
 import optparse
-import pip, xmlrpclib
 import sys, os
 from django.core.management.base import BaseCommand
 import djaboto
 
     option_list = BaseCommand.option_list + (
         optparse.make_option('-s', '--system',
-            action='store_true',
-            dest='check_system',
-            help='check the current system environment for required modules and updates.',
-        ),
+                             action='store_true',
+                             dest='check_system',
+                             help='check the current system environment for required modules and updates.',
+                             ),
+        optparse.make_option('-a', '--all',
+                             action='store_true',
+                             dest='check_all',
+                             help='check for all updates, not just the specified versions in the requirements file.',
+                             ),
         )
 
     def handle(self, *args, **options):
 
         if options.get('check_system', False):
             djaboto.debian.install_system()
+        if options.get('check_all', False):
+            check_available();
 
-        pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
-        for dist in pip.get_installed_distributions():
-            available = pypi.package_releases(dist.project_name)
 
-            if not available:
-                # Try to capitalize pkg name
-                available = pypi.package_releases(dist.project_name.capitalize())
+        djaboto.pve.check_requirements('requirements.txt')
 
-            if available and (available[0] != dist.version):
-                msg = '{} available'.format(available[0])
-                pkg_info = '{dist.project_name} {dist.version}'.format(dist=dist)
-                print '{pkg_info:40} {msg}'.format(pkg_info=pkg_info, msg=msg)
+
+
+def check_available():
+    import pip, xmlrpclib
+
+    pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
+    for dist in pip.get_installed_distributions():
+        available = pypi.package_releases(dist.project_name)
+
+        if not available:
+            # Try to capitalize pkg name
+            available = pypi.package_releases(dist.project_name.capitalize())
+
+        if available and (available[0] != dist.version):
+            msg = '{} available'.format(available[0])
+            pkg_info = '{dist.project_name} {dist.version}'.format(dist=dist)
+            print '{pkg_info:40} {msg}'.format(pkg_info=pkg_info, msg=msg)
 
 def gitReady(target_dir, git_url=None):
     import git

File djaboto/pve.py

     check_call(['pip', 'install', '--upgrade', '--download-cache=%s' % cache_dir, '--source=%s' % cache_dir, 'distribute>=0.6.30'])
     print "...upgrading/installing MySQL-python"
     check_call(['pip', 'install', '--upgrade', '--download-cache=%s' % cache_dir, '--source=%s' % cache_dir, 'MySQL-python==1.2.3'])
-    
+
+def check_requirements(requirements_path):
+    """
+    Check all requirements and respond on mismatched ones
+    """
+
+    from pkg_resources import WorkingSet, DistributionNotFound, VersionConflict
+    from setuptools.command.easy_install import main as install
+
+
+    with open(requirements_path) as f_in:
+        requirements = (line.rstrip() for line in f_in)
+        requirements = (line for line in requirements if line[0]!='#') # Non-comment lines
+        requirements = (line for line in requirements if not line.startswith('hg+')) # Non-hg+ lines
+        requirements = (line for line in requirements if not line.startswith('git+')) # Non-hg+ lines
+        requirements = list(line for line in requirements if line)
+
+    working_set = WorkingSet()
+
+    for requirement in requirements:
+
+        if not requirement or requirement[0]=='#':
+            continue
+
+        ## Detecting if module is installed
+        try:
+            dep = working_set.require(requirement)
+        except DistributionNotFound:
+            print "DistributionNotFound for %s" % requirement
+            #install([requirement])
+        except VersionConflict, err:
+            print "VersionConflict for %s" % requirement
+            #install([requirement])
+        #except Exception, err:
+        #    print err
+        #else:
+        #    print "%s is currently installed. %s" % (requirement, dep[0])
+
+
+    # Printing all installed modules
+    #from pprint import pprint
+    #pprint(tuple(working_set))
+
+