Rename kamaki.py to cli.py
authorGiorgos Verigakis <verigak@gmail.com>
Thu, 5 Jan 2012 14:27:19 +0000 (16:27 +0200)
committerGiorgos Verigakis <verigak@gmail.com>
Thu, 5 Jan 2012 14:27:19 +0000 (16:27 +0200)
Use absolute imports
Update build script

build
kamaki/cli.py [moved from kamaki/kamaki.py with 98% similarity]

diff --git a/build b/build
index feb8951..10bb580 100755 (executable)
--- a/build
+++ b/build
@@ -1,32 +1,49 @@
 #!/usr/bin/env python
 
 import os
+import shutil
 import stat
 
+from os.path import exists, join
+
+
 SRCDIR = 'kamaki'
-SRC = 'kamaki.py'
-CLIENT = 'client.py'
 DSTDIR = 'bin'
 DST = 'kamaki'
 
+FILES = ('config.py', 'utils.py', 'client.py', 'cli.py')
+
+
+def cat(path, dst, skipheader=True):
+    dst.write('\n')
+    
+    in_header = True
+    for line in open(path):
+        if in_header and line.strip() and not line.startswith('#'):
+            in_header = False
+        
+        if line.startswith('from kamaki.'):
+            continue    # Skip local imports
+        
+        if skipheader and in_header:
+            continue
+        
+        dst.write(line)
+
 
 def main():
-    if not os.path.exists(DSTDIR):
+    if not exists(DSTDIR):
         os.makedirs(DSTDIR)
-    dstpath = os.path.join(DSTDIR, DST)
+    dstpath = join(DSTDIR, DST)
+    
     dst = open(dstpath, 'w')
     
-    srcpath = os.path.join(SRCDIR, SRC)
-    clientpath = os.path.join(SRCDIR, CLIENT)
-
-    for line in open(srcpath):
-        if line.startswith('from client import'):
-            for l in open(clientpath):
-                if l.startswith('#'):
-                    continue    # Skip comments
-                dst.write(l)
-        else:
-            dst.write(line)
+    dst.write('#!/usr/bin/env python\n')
+    
+    cat(join(SRCDIR, '__init__.py'), dst, skipheader=False)
+    
+    for file in FILES:
+        cat(join(SRCDIR, file), dst)
     
     dst.close()
     
similarity index 98%
rename from kamaki/kamaki.py
rename to kamaki/cli.py
index b8b874f..1766745 100755 (executable)
@@ -76,9 +76,9 @@ from grp import getgrgid
 from optparse import OptionParser
 from pwd import getpwuid
 
-from client import ComputeClient, ImagesClient, ClientError
-from config import Config, ConfigError
-from utils import OrderedDict, print_addresses, print_dict, print_items
+from kamaki.client import ComputeClient, ImagesClient, ClientError
+from kamaki.config import Config, ConfigError
+from kamaki.utils import OrderedDict, print_addresses, print_dict, print_items
 
 
 # Path to the file that stores the configuration