Commits

Albert Hopkins committed 54a01a8

Various cleanups. Ready for 0.4.4

Comments (0)

Files changed (1)

 from datetime import datetime
 import json
 import os
-from os import path
 import shutil
 from subprocess import call
 import sys
 CLOUD_FILE_FORMAT = 1
 
 class InvalidCloudFile(Exception):
+    """
+    Exception raised when a filename cannot be read as a valid hemp
+    cloud file.
+    """
     pass
 
 
     assert (disk is not None)
     filename = disk.get('file')
     assert (filename)
-    shutil.copy(filename, path.join(basedir, 'images', 'base.qcow2'))
+    shutil.copy(filename, os.path.join(basedir, 'images', 'base.qcow2'))
     return
 
 
     """Create template.xml and dump it into basedir"""
 
     template = create_xml_template(domtree)
-    template.write(path.join(basedir, 'template.xml'), 'utf-8')
+    template.write(os.path.join(basedir, 'template.xml'), 'utf-8')
     return
 
 def mkdirs(basedir):
     """Make skeleton directories in basedir, including basedir"""
 
     os.mkdir(basedir)
-    dirs = [path.join(basedir, i) for i in DIRS]
+    dirs = [os.path.join(basedir, i) for i in DIRS]
     [os.mkdir(i) for i in dirs]
     return
 
 def install_files(basedir):
     """Install fabfile/helper scripts into basedir"""
-    dirname = path.dirname(path.realpath(__file__))
-    files = [path.join(dirname, i) for i in FILES]
+    dirname = os.path.dirname(os.path.realpath(__file__))
+    files = [os.path.join(dirname, i) for i in FILES]
     [shutil.copy(i, basedir) for i in files]
 
 
 
     # so some minor sanity checking
     if not (
-        os.path.exists('%s/fabfile.py' % args.path) and
-        os.path.exists('%s/images/base.qcow2' % args.path)):
+        os.path.exists(os.path.join(args.path, 'fabfile.py')) and
+        os.path.exists(os.path.join(args.path, 'images', 'base.qcow2'))):
 
         sys.stderr.write('Error: %s does not appear to be a valid hemp '
             'project.\n' % args.path)
     author = args.author or os.getlogin()
     url = args.url or ''
     outfile = args.file or '%s.cloud' % name
-    create_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+    create_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 
     metadata = dict(
         version=CLOUD_FILE_FORMAT,
 
     try:
         metadata = cloudinfo(args.filename)
-    except InvalidCloudFile as error:
+    except (InvalidCloudFile, IOError) as error:
         sys.stderr.write('%s\n' % error)
         sys.exit(1)
-        cloud_file = open(args.filename, 'rb')
 
     print 'FILE   : %s' % args.filename
     print 'CREATED: %s' % metadata['create_time']
         sys.stderr.write('%s\n')
         sys.exit(1)
     project_name = metadata['name']
-    path = '%s/%s' % (outdir, project_name)
+    path = os.path.join(outdir, project_name)
 
     try:
         os.mkdir(path)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.