Switch to ansicolor for coloring & fix pep8 errors
authorNikos Skalkotos <skalkoto@grnet.gr>
Tue, 24 Apr 2012 09:45:49 +0000 (12:45 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Tue, 24 Apr 2012 09:45:49 +0000 (12:45 +0300)
image_creator/disk.py
image_creator/kamaki_wrapper.py
image_creator/main.py
image_creator/util.py
setup.py

index e0ed6a1..71c7f17 100644 (file)
@@ -336,7 +336,6 @@ class DiskDevice(object):
                 dest.close()
         finally:
             source.close()
-        
         output("\rDumping image file...\033[K", False)
         success('image file %s was successfully created' % outfile)
 
index f325be0..56fd382 100644 (file)
@@ -61,6 +61,7 @@ def progress(message):
         yield
     return progress_gen
 
+
 class Kamaki:
     def __init__(self, account, token):
         self.account = account
@@ -100,7 +101,8 @@ class Kamaki:
             raise FatalError("Pithos client: %d %s" % (e.status, e.message))
 
     def register(self, name, location, metadata):
-        params = {'is_public':'true', 'disk_format':'diskdump'}
+
+        params = {'is_public': 'true', 'disk_format': 'diskdump'}
         try:
             self.image_client.register(name, location, params, metadata)
         except ClientError as e:
index 3207c87..86b74cc 100755 (executable)
@@ -210,7 +210,8 @@ def image_creator():
 
             output('Dumping md5sum file...', False)
             with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f:
-                f.write('%s %s'% (checksum, os.path.basename(options.outfile)))
+                f.write('%s %s' % (
+                                checksum, os.path.basename(options.outfile)))
             success('done')
 
         # Destroy the device. We only need the snapshot from now on
@@ -239,9 +240,9 @@ def image_creator():
             output()
 
         if options.register:
-            output('Registing image to ~okeanos...')
+            output('Registing image to ~okeanos...', False)
             kamaki.register(options.register, uploaded_obj, metadata)
-            output('done')
+            success('done')
             output()
 
     finally:
index 3cacba0..efccabb 100644 (file)
@@ -34,7 +34,7 @@
 import sys
 import pbs
 import hashlib
-from clint.textui import colored
+from colors import red, green, yellow
 from progress.bar import Bar
 
 
@@ -61,19 +61,19 @@ def get_command(command):
 
 def error(msg, new_line=True):
     nl = "\n" if new_line else ''
-    sys.stderr.write(colored.red('Error: %s' % msg) + nl)
+    sys.stderr.write(red('Error: %s' % msg) + nl)
 
 
 def warn(msg, new_line=True):
     if not silent:
         nl = "\n" if new_line else ''
-        sys.stderr.write(colored.yellow("Warning: %s" % msg) + nl)
+        sys.stderr.write(yellow("Warning: %s" % msg) + nl)
 
 
 def success(msg, new_line=True):
     if not silent:
         nl = "\n" if new_line else ''
-        sys.stdout.write(colored.green(msg) + nl)
+        sys.stdout.write(green(msg) + nl)
         if not nl:
             sys.stdout.flush()
 
@@ -89,15 +89,24 @@ def output(msg="", new_line=True):
 def progress(message='', bar_type="default"):
 
     MESSAGE_LENGTH = 30
-    
-    suffix={'default':'%(index)d/%(max)d',
-        'percent':'%(percent)d%%',
-        'b':'%(index)d/%(max)d B',
-        'kb':'%(index)d/%(max)d KB',
-        'mb':'%(index)d/%(max)d MB'}
 
-    return Bar(message=message.ljust(MESSAGE_LENGTH), fill='#', \
-                                                    suffix=suffix[bar_type])
+    suffix = {
+        'default': '%(index)d/%(max)d',
+        'percent': '%(percent)d%%',
+        'b': '%(index)d/%(max)d B',
+        'kb': '%(index)d/%(max)d KB',
+        'mb': '%(index)d/%(max)d MB'
+    }
+
+    bar = Bar()
+    bar.message = message.ljust(MESSAGE_LENGTH)
+    bar.fill = '#'
+    bar.suffix = suffix[bar_type]
+    bar.bar_prefix = ' ['
+    bar.bar_suffix = '] '
+
+    return bar
+
 
 def md5(filename, size):
 
@@ -114,7 +123,7 @@ def md5(filename, size):
             md5.update(data)
             left -= length
             progressbar.goto((size - left) // (2 ** 20))
-    
+
     checksum = md5.hexdigest()
     output("\rCalculating md5sum...\033[K", False)
     success(checksum)
index 29f0cd5..0e65cb0 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -47,7 +47,7 @@ setup(
     license='BSD',
     packages=['image_creator', 'image_creator.os_type'],
     include_package_data=True,
-    install_requires=['pbs', 'clint', 'progress','pysendfile'],
+    install_requires=['pbs', 'ansicolors', 'progress', 'pysendfile'],
     entry_points={
         'console_scripts': ['snf-image-creator = image_creator.main:main']
     }