Commits

Eric Larson  committed 8d3dd46

pep8

  • Participants
  • Parent commits d4a15e7

Comments (0)

Files changed (3)

 from paver.setuputils import *
 
 
-
 setup(
     name='Xenv',
     version='0.1',
     entry_points={
         'console_scripts': [
             'xe = xenv.main:xe',
-            'xepython = xenv.main:xepython', 
+            'xepython = xenv.main:xepython',
             ]
         }
     )
-
-
-
-
-

File xenv/main.py

 '''
 import os
 import sys
-from subprocess import call
 
 from argparse import ArgumentParser
 from xenv.models import Xenv, Package
 def run_cmd(xenv, args):
     xenv.run(args.cmd.pop())
 
+
 @with_root
 def create_xenv_cmd(xenv, args):
     xenv.create()
 
+
 @with_root
 def install_package_cmd(xenv, args):
     pkg = Package(args.name, args.version, args.repo)
     xenv.install(pkg)
 
+
 @with_root
 def uninstall_package_cmd(xenv, args):
     pkg = Package(args.name, args.version)
     xenv.uninstall(pkg)
 
-    
 
 class CLI(object):
     description = '''Utilize a specific executable environment (xenv) for running applications'''
 
     def __init__(self):
         self.parser = ArgumentParser(description=self.description)
-        self.parser.add_argument('--root', '-r', default=os.environ.get('XE_ROOT'),
-                                 help='The xenv root. This will override using the XE_ROOT env var.')
-        
+        self.parser.add_argument('--root', '-r',
+                                 default=os.environ.get('XE_ROOT'),
+                                 help='Override the XE_ROOT env var.')
+
         self.subs = self.parser.add_subparsers(help='sub command help')
 
         # Create a new xenv
                          help='The command and flags to run via the xenv')
         run.set_defaults(func=run_cmd)
 
-
         # install a package
         install_pkg = self.subs.add_parser('install',
                                            help='Install a package in an xenv')
         install_pkg.add_argument('name', help='The package to install')
-        install_pkg.add_argument('version', help='The version to install')    
+        install_pkg.add_argument('version', help='The version to install')
         install_pkg.add_argument('--repo', '-b', default='file://',
                          help='The base URL of the package. \
                                The default is the current directory')
 
         # uninstall a package
         uninstall_pkg = self.subs.add_parser('uninstall',
-                                             help='Install a package in an xenv')
+                                             help='Uninstall a package')
         uninstall_pkg.add_argument('name', help='The package to uninstall')
-        uninstall_pkg.add_argument('version', help='The version to uninstall')    
+        uninstall_pkg.add_argument('version', help='The version to uninstall')
         uninstall_pkg.set_defaults(func=uninstall_package_cmd)
 
     def run(self, args=None):
         if args:
             return self.parser.parse_args(args)
         return self.parser.parse_known_args()
-    
+
 
 def _run(args):
     if args.root:
         args.root = os.path.abspath(args.root)
     if args.func:
         args.func(args)
-    
+
+
 def xe():
     cli = CLI()
     args, extras = cli.run()
     _run(args)
-        
+
+
 def xepython():
     cli = CLI()
     cargs = ['run', 'python']
     if len(sys.argv) > 1:
         cargs.extend(sys.argv[1:])
     args = cli.run(cargs)
-    _run(args)    
-    
+    _run(args)

File xenv/models.py

 import os
 from paver.easy import path
-from subprocess import Popen, call, check_output
+from subprocess import call, check_output
 from urllib2 import urlopen
 from urlparse import urljoin
 
 
     def create_base_env(self):
         (self.root / 'local').mkdir()
-    
+
     def create_venv(self):
         venv = self.root.abspath() / 'usr'
         cmd = 'virtualenv --no-site-packages %s' % venv
         self.xenv_fs.create_base_env()
         self.xenv_fs.create_venv()
 
-
     def install(self, pkg):
         pkgfile = pkg.fetch(self)
         call(['tar', 'xf', pkgfile], cwd=self.root)
         if install_hook.isfile():
             call(install_hook.abspath(), cwd=self.root)
             install_hook.move(history)
-        (self.root/ pkg.fname).move(history)
+        (self.root / pkg.fname).move(history)
 
     def uninstall(self, pkg):
+        pkg_path = self.root / 'packages' / pkg.name / pkg.version / pkg.fname
         filelist = check_output([
-            'tar', 'tf', self.root/'packages'/pkg.name/pkg.version/pkg.fname
+            'tar', 'tf', pkg_path
         ])
-        uninstall_hook = self.root/'packages'/pkg.name/pkg.version/'uninstall'
+        uninstall_hook = os.path.join(self.root, 'packages',
+                                      pkg.name, pkg.version,
+                                      'uninstall')
         history = self.root / 'packages' / pkg.name / pkg.version
-        
+
         for line in filelist.split('\n'):
             name = path(line)
             if name.isfile():
             for line in fh:
                 pkg.write(line)
         return pkgfile
-
-