various correction to add chuncked-uploads to platform V00.02
authorymh <ymh.work@gmail.com>
Wed, 27 Feb 2013 18:19:48 +0100
changeset 9 525a37ed8c18
parent 8 7352202b5d1e
child 10 a84d7feb23d0
various correction to add chuncked-uploads to platform
src/fablib/__init__.py
src/fablib/core.py
--- a/src/fablib/__init__.py	Fri Feb 22 18:01:16 2013 +0100
+++ b/src/fablib/__init__.py	Wed Feb 27 18:19:48 2013 +0100
@@ -1,10 +1,13 @@
 
-from .core import *
+from .core import (check_folder_access, syncdb, collectstatic, do_relaunch_server, 
+    export_version, do_sync_web, create_config, clean_export_folder, 
+    sync_install_build, do_create_virtualenv, clean_rsync_folder, rsync_export, 
+    do_sync_comp, get_comp_versions_dict, SyncComp)
 
-__all__ = ["check_folder_access", "syncdb", "collectstatic", 
+__all__ = ["check_folder_access", "syncdb", "collectstatic", "do_sync_comp",
     "export_version", "do_sync_web", "create_config", "clean_export_folder", "relaunch_server", 
     "do_sync_ldt", "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export",
-    "SyncComp"]
+    "get_comp_versions_dict", "SyncComp"]
 
 VERSION = (0, 1, 0, "dev", 0)
 
--- a/src/fablib/core.py	Fri Feb 22 18:01:16 2013 +0100
+++ b/src/fablib/core.py	Wed Feb 27 18:19:48 2013 +0100
@@ -14,13 +14,14 @@
 import os.path
 import re
 import shutil
+import sys
 import urlparse
 
 
 __all__ = ["check_folder_access", "syncdb", "collectstatic", "do_relaunch_server",
     "export_version", "do_sync_web", "create_config", "clean_export_folder", 
-    "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export",
-    "SyncComp"] 
+    "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export",    
+    "do_sync_comp", "get_comp_versions_dict", "SyncComp"] 
 
 def get_export_path(version):
     base_path = os.path.join(env.base_export_path,env.export_prefix).rstrip("/")
@@ -37,18 +38,32 @@
     for export_key, version in export_keys.items():
         export_path = os.path.join(path,export_key)
         
-        repo_url = env.repos[export_key]
+        repo_url = env.repos[export_key]['repo']
         url_part = urlparse.urlparse(repo_url)
         if url_part.scheme or url_part.netloc:
             # this is a remote repo. Let's clone first
             clone_path = os.path.join(path,'clone',export_keys)
             os.makedirs(clone_path)
-            local("hg clone \"%s\" \"%s\"" % (repo_url,clone_path))
+            
+            scm = "hg"            
+            with settings(warn_only=True):
+                output = local('git ls-remote \"%s\"' % repo_url)
+                scm = "git" if output.failed else "hg" 
+            if scm == "hg":
+                output = local("hg clone \"%s\" \"%s\"" % (repo_url,clone_path))
+            else:
+                local("git clone \"%s\" \"%s\"" % (repo_url,clone_path))            
         else:
             clone_path = repo_url
         
         with lcd(clone_path):
-            local("hg archive -r \'%s\' \"%s\"" % (str(version),export_path))
+            # detetct .git or .hg subfolder
+            if os.path.exists(os.path.join(clone_path,".git")):
+                os.makedirs(export_path)
+                cmd_str = "git archive \'%s\' | tar -x -C \"%s\""
+            else:
+                cmd_str = "hg archive -r \'%s\' \"%s\""
+            local(cmd_str % (str(version),export_path))
     
     print("Export version %s done"%repr(export_keys))
 
@@ -87,32 +102,54 @@
 def build_src(path):
     print("Build source dist at %s" % path)
     f = None
-    try:
-        f, pathname, description = imp.find_module("setup", [path])
-        print(" 2 Build source dist at %s" % path)
-        setup_mod = imp.load_module("setup", f, pathname, description)
-        print(" 3 Build source dist at %s" % path)
+    sys.path.append(path)
+    current_path = os.getcwdu()
+    try:    
+        os.chdir(path)    
+        try:    
+            f, pathname, description = imp.find_module("setup", [path])
+            print("Build source dist at %s : found setup" % path)
+            setup_mod = imp.load_module("setup", f, pathname, description)
+            print("Build source dist at %s : setup loaded" % path)
+        finally:
+            if f:
+                f.close()
+            
+            setup_mod.launch_setup("setup.py", ['sdist'])
     finally:
-        if f:
-            f.close()
-        
-    setup_mod.launch_setup("setup.py", ['sdist'])
-    
+        os.chdir(current_path)
     print("Build source dist at %s done" % path)
     
 
-def get_src_version(mod_name, path):
-    print("get src version for %s at %s" % (mod_name,path))
+def get_src_version(key, path):
+        
+    print("get src version for %s at %s" % (key,path))
+    
+    mod_name = env.repos[key].get('module', key)
+    
     f = None
+    sys.path.append(path)
+    current_path = os.getcwdu()
+    os.chdir(path)
     try:
         f, pathname, description = imp.find_module(mod_name, [path])
-        ldt_mod = imp.load_module(mod_name, f, pathname, description)
+        src_mod = imp.load_module(mod_name, f, pathname, description)
     finally:
+        os.chdir(current_path)
         if f:
             f.close()
-    version = ldt_mod.VERSION
-    version_str = ldt_mod.get_version()
-    
+    if hasattr(src_mod, "VERSION"):
+        version = src_mod.VERSION
+    elif hasattr(src_mod, "__version__"):
+        version = src_mod.__version__
+
+    if not isinstance(version, basestring):
+        if hasattr(src_mod, "get_version"):
+            version_str = src_mod.get_version()
+        else:
+            version_str = str(version)
+    else:
+        version_str = version
     return (version, version_str) 
     
 
@@ -204,7 +241,7 @@
 def do_sync_comp(key, export_path):
     print("do_sync_comp with  path %s" % (export_path))
     
-    src_path = os.path.join(export_path,"src")
+    src_path = os.path.join(export_path,env.repos[key]['src_root'])
     # find setup.py
     for root, _, files in os.walk(src_path):
         if "setup.py" in files:
@@ -255,7 +292,7 @@
         return comp_versions
     with open(requirement_file_path) as f:
         for line in f:
-            m = re.match('^(\w+)\s+\(\s*\=\=\s*([\.\d\w]+)\s*\)', line)
+            m = re.match('^([\w-]+)\s+\(\s*\=\=\s*([\.\d\w]+)\s*\)', line)
             if m:
                 key, version_req = m.groups()
                 if "." in version_req: