sbin/sync/fabfile.py
changeset 27 4b8a549d6399
parent 17 f8c613e43ebd
child 50 4dd7fa373ed6
equal deleted inserted replaced
26:b232a3a2f9fc 27:4b8a549d6399
    64     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
    64     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
    65     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
    65     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
    66         #remocve old files optio -c of collect static fail !
    66         #remocve old files optio -c of collect static fail !
    67         run("rm -fr \"%s\"" % (remotestaticsitepath))
    67         run("rm -fr \"%s\"" % (remotestaticsitepath))
    68         run("python manage.py collectstatic --noinput")
    68         run("python manage.py collectstatic --noinput")
       
    69 
       
    70 def migrate(remotepath, remotevirtualenvpath, platform_web_module):
       
    71     print("migrate in %s with %s" % (remotepath, remotevirtualenvpath))
       
    72     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
       
    73     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
       
    74         #remocve old files optio -c of collect static fail !
       
    75         run("python manage.py migrate --noinput")
    69         
    76         
    70 def create_config(export_path):    
    77 def create_config(export_path):    
    71     print("Create config from %s" % (export_path,))
    78     print("Create config from %s" % (export_path,))
    72     remotepath = env.remote_web_path
    79     remotepath = env.remote_web_path
    73     remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py")
    80     remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py")
   127         
   134         
   128 
   135 
   129 def do_sync_web(version, export_path):
   136 def do_sync_web(version, export_path):
   130     print("do_sync_web with version %s and path %s" % (version,export_path))
   137     print("do_sync_web with version %s and path %s" % (version,export_path))
   131     web_path = os.path.join(export_path,env.local_folders.get("web","web").rstrip("/")+"/") 
   138     web_path = os.path.join(export_path,env.local_folders.get("web","web").rstrip("/")+"/") 
   132     rsync_export(web_path, env.remote_web_path, env.web_rsync_filters)    
   139     rsync_export(web_path, env.remote_web_path, env.web_rsync_filters)
       
   140 
       
   141 def remove_lib(path):
       
   142     print("remove build build %s" % path)
       
   143     run("rm \"%s\"" % path)
       
   144 
       
   145 def install_lib(remotepath, remotevirtualenvpath):
       
   146     print("Install lib %s in %s" % (remotepath, remotevirtualenvpath))
       
   147     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
       
   148     
       
   149     with prefix("source %s" % activate_path):
       
   150         run("pip install \"%s\"" % remotepath)
       
   151 
       
   152 def sync_lib(path):
       
   153     print("Sync build %s" % path)
       
   154     run("mkdir -p \"%s\"" % env.remote_venv_export_path)
       
   155     with cd(env.remote_venv_export_path):
       
   156         filename = os.path.basename(path)
       
   157         dest_path = os.path.join(env.remote_venv_export_path, filename)
       
   158         res_trans = put(path, dest_path)
       
   159         print("Sync build %s to %s" % (path,repr(res_trans)))
       
   160         return res_trans
       
   161 
       
   162 def sync_install_lib(lib_path):
       
   163     res_trans = None
       
   164     try:
       
   165         res_trans = sync_lib(lib_path)
       
   166         install_lib(res_trans[0], env.remote_virtualenv_path)        
       
   167     finally:
       
   168         if res_trans:
       
   169             remove_lib(res_trans[0])
       
   170 
   133     
   171     
   134 def check_folder_access():
   172 def check_folder_access():
   135     print("Check folder access")
   173     print("Check folder access")
   136     # get remote user
   174     # get remote user
   137     for folder_path in env.folders:
   175     for folder_path in env.folders:
   141                 if not exists(folder_path):
   179                 if not exists(folder_path):
   142                     run("mkdir -p \"%s\"" % folder_path)
   180                     run("mkdir -p \"%s\"" % folder_path)
   143                 run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path))
   181                 run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path))
   144                 run("chmod -R -c g+w \"%s\"" % folder_path)
   182                 run("chmod -R -c g+w \"%s\"" % folder_path)
   145 @task
   183 @task
   146 def relaunch_server(do_collectstatic=True):
   184 def relaunch_server(do_collectstatic=True, do_migrate=True):
   147     print("Relaunch server")
   185     print("Relaunch server")
   148     check_folder_access()
   186     check_folder_access()
   149     if do_collectstatic:
   187     if do_collectstatic:
   150         collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module)
   188         collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module)
       
   189     if do_migrate:
       
   190         migrate(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module)
   151     sudo(env.web_relaunch_cmd, shell=False)
   191     sudo(env.web_relaunch_cmd, shell=False)
   152 
   192 
   153 @task
   193 @task
   154 def sync_web(version):
   194 def sync_web(version):
   155     print(green("sync web with version %s" % version))
   195     print(green("sync web with version %s" % version))
   170     f, pathname, description = imp.find_module("lib_create_env", [lib_path])
   210     f, pathname, description = imp.find_module("lib_create_env", [lib_path])
   171     lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
   211     lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
   172     
   212     
   173     package_path = os.path.join(export_path, env.local_folders.get("virtualenv","virtualenv"), "res", "src", lib_create_env.URLS[package]['local'])
   213     package_path = os.path.join(export_path, env.local_folders.get("virtualenv","virtualenv"), "res", "src", lib_create_env.URLS[package]['local'])
   174     
   214     
   175     sync_install_build(package_path)
   215     sync_install_lib(package_path)
   176     clean_export_folder(export_path)
   216     clean_export_folder(export_path)
   177     relaunch_server()
   217     relaunch_server()
   178 
   218 
   179 
   219 
   180 @task
   220 @task