| author | ymh <ymh.work@gmail.com> |
| Tue, 23 Oct 2018 11:32:03 +0200 | |
| changeset 32 | 800b7b8aa439 |
| parent 29 | 690b89879211 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Feb 20, 2013 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
7 |
# from fabric.api import run, local, env, cd, put, prefix, sudo, lcd |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
8 |
# from fabric.colors import green |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
9 |
# from fabric.context_managers import settings |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
10 |
# from fabric.contrib.files import exists, upload_template |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
11 |
# from fabric.contrib.project import rsync_project |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
12 |
# from fabric.tasks import Task |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
13 |
from fabric import Connection |
| 0 | 14 |
import imp |
15 |
import os.path |
|
16 |
import re |
|
17 |
import shutil |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
18 |
import sys |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
19 |
import urllib.parse |
| 0 | 20 |
|
21 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
22 |
# __all__ = ["check_folder_access", "migrate", "collectstatic", "do_relaunch_server", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
23 |
# "export_version", "do_sync_web", "create_config", "clean_export_folder", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
24 |
# "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
25 |
# "do_sync_comp", "get_comp_versions_dict", "SyncComp", "get_src_version", "sync_build", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
26 |
# "install_build", "do_create_virtualenv_requirement", "build_src"] |
| 0 | 27 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
28 |
def get_export_path(env, version): |
| 0 | 29 |
base_path = os.path.join(env.base_export_path,env.export_prefix).rstrip("/") |
30 |
return os.path.expanduser(base_path) + "_%s" % (str(version)) |
|
31 |
||
32 |
def clean_export_folder(path): |
|
33 |
print("Removing %s" % path) |
|
34 |
if os.path.isdir(path): |
|
35 |
shutil.rmtree(path, ignore_errors=True) |
|
36 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
37 |
def do_export_version(c, path, **export_keys): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
38 |
print("Export version %s : %s" % (path,repr(export_keys))) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
39 |
|
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
40 |
env = c.env |
| 0 | 41 |
|
42 |
for export_key, version in export_keys.items(): |
|
43 |
export_path = os.path.join(path,export_key) |
|
| 22 | 44 |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
45 |
repo_url = env.repos[export_key]['repo'] |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
46 |
url_part = urllib.parse.urlparse(repo_url) |
| 0 | 47 |
if url_part.scheme or url_part.netloc: |
48 |
# this is a remote repo. Let's clone first |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
49 |
clone_path = os.path.join(path,'clone',export_keys[export_key]) |
| 0 | 50 |
os.makedirs(clone_path) |
| 22 | 51 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
52 |
output = c.run('git ls-remote \"%s\"' % repo_url, warn=True) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
53 |
print("OUTPUT %r" % output) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
54 |
scm = "hg" if output.failed else "git" |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
55 |
if scm == "hg": |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
56 |
output = c.run("hg clone \"%s\" \"%s\"" % (repo_url,clone_path)) |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
57 |
else: |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
58 |
c.run("git clone \"%s\" \"%s\"" % (repo_url,clone_path)) |
| 0 | 59 |
else: |
60 |
clone_path = repo_url |
|
| 22 | 61 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
62 |
with c.cd(clone_path): |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
63 |
# detetct .git or .hg subfolder |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
64 |
if os.path.exists(os.path.join(clone_path,".git")): |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
65 |
os.makedirs(export_path) |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
66 |
cmd_str = "git archive \'%s\' | tar -x -C \"%s\"" |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
67 |
else: |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
68 |
cmd_str = "hg archive -r \'%s\' \"%s\"" |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
69 |
c.run(cmd_str % (str(version),export_path)) |
| 22 | 70 |
|
| 0 | 71 |
print("Export version %s done"%repr(export_keys)) |
72 |
||
| 22 | 73 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
74 |
# def get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, settings_key, settings_module=''): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
75 |
# if not settings_module: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
76 |
# settings_module = '%s.%s' % (platform_web_module, 'settings') |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
77 |
# activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
78 |
# with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
79 |
# tempfilepath = run("mktemp -t fablib.XXXXXX") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
80 |
# with settings(warn_only=True): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
81 |
# run("echo \"import os\" > %s" % (tempfilepath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
82 |
# map(lambda str_echo: run("echo \"%s\" >> %s" % (str_echo, tempfilepath)), |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
83 |
# ["os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s')" % (settings_module), |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
84 |
# "from django.conf import settings", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
85 |
# "print(settings.%s)" % (settings_key)]) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
86 |
# res = run("python < %s" % (tempfilepath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
87 |
# run("rm -f \"%s\"" % (tempfilepath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
88 |
# return res |
| 22 | 89 |
|
90 |
||
91 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
92 |
# def rsync_export(path, remotepath, filters): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
93 |
# print("Rsync %s to %s",(path,remotepath)) |
| 22 | 94 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
95 |
# filter_option_str = "--progress --stats" |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
96 |
# if filters: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
97 |
# filter_option_str += " " + " ".join(["--filter \"%s\"" % (f) for f in filters]) |
| 22 | 98 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
99 |
# run("mkdir -p \"%s\"" % remotepath) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
100 |
# rsync_project(remotepath, local_dir=path, extra_opts=filter_option_str, delete=True) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
101 |
# print("Rsync %s to %s done",(path,remotepath)) |
| 22 | 102 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
103 |
# def clean_rsync_folder(remotepath): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
104 |
# print("clean rsync folder %s" % remotepath) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
105 |
# run("rm -fr \"%s\"" % remotepath) |
| 22 | 106 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
107 |
def build_src(c, path): |
| 0 | 108 |
print("Build source dist at %s" % path) |
109 |
f = None |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
110 |
sys.path.append(path) |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
111 |
current_path = os.getcwd() |
| 22 | 112 |
try: |
113 |
os.chdir(path) |
|
114 |
try: |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
115 |
f, pathname, description = imp.find_module("setup", [path]) |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
116 |
print("Build source dist at %s : found setup" % path) |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
117 |
setup_mod = imp.load_module("setup", f, pathname, description) |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
118 |
print("Build source dist at %s : setup loaded" % path) |
| 21 | 119 |
except: |
120 |
e = sys.exc_info()[0] |
|
121 |
print("Error when building %s : %s" % (path, str(e))) |
|
122 |
raise |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
123 |
finally: |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
124 |
if f: |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
125 |
f.close() |
| 22 | 126 |
|
| 21 | 127 |
setup_mod.launch_setup("setup.py", ['sdist']) |
| 0 | 128 |
finally: |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
129 |
os.chdir(current_path) |
| 0 | 130 |
print("Build source dist at %s done" % path) |
| 14 | 131 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
132 |
# def get_version(version): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
133 |
# version_str = '%s.%s' % (version[0], version[1]) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
134 |
# if version[2]: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
135 |
# version_str = '%s.%s' % (version_str, version[2]) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
136 |
# if version[3:] == ('alpha', 0): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
137 |
# version_str = '%s pre-alpha' % version_str |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
138 |
# else: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
139 |
# if version[3] != 'final': |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
140 |
# version_str = '%s %s %s' % (version_str, version[3], version[4]) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
141 |
# return version_str |
| 22 | 142 |
|
| 0 | 143 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
144 |
def get_src_version(c, key, path): |
| 22 | 145 |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
146 |
print("get src version for %s at %s" % (key,path)) |
| 22 | 147 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
148 |
env = c.env |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
149 |
|
| 13 | 150 |
mod_name = env.repos[key].get('module', key) or key |
| 22 | 151 |
|
| 0 | 152 |
f = None |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
153 |
sys.path.append(path) |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
154 |
current_path = os.getcwd() |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
155 |
os.chdir(path) |
| 0 | 156 |
try: |
157 |
f, pathname, description = imp.find_module(mod_name, [path]) |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
158 |
src_mod = imp.load_module(mod_name, f, pathname, description) |
| 14 | 159 |
except: |
160 |
src_mod = None |
|
| 22 | 161 |
print("Could not import module, trying to parse") |
| 0 | 162 |
finally: |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
163 |
os.chdir(current_path) |
| 0 | 164 |
if f: |
165 |
f.close() |
|
| 14 | 166 |
version = None |
167 |
if src_mod is None: |
|
| 15 | 168 |
with open(os.path.join(path,mod_name,"__init__.py"),'r') as init_file: |
| 14 | 169 |
for line in init_file: |
170 |
m = re.search('VERSION\s+=\s+\((.+)\)', line, re.I) |
|
| 22 | 171 |
if m: |
| 14 | 172 |
version = tuple([re.sub('[\s\"\']','', item) for item in m.group(1).split(',')]) |
173 |
break |
|
174 |
elif hasattr(src_mod, "VERSION"): |
|
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
175 |
version = src_mod.VERSION |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
176 |
elif hasattr(src_mod, "__version__"): |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
177 |
version = src_mod.__version__ |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
178 |
|
| 15 | 179 |
print("VERSION : %s" % repr(version)) |
| 22 | 180 |
|
| 14 | 181 |
if version is None: |
182 |
version = "" |
|
183 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
184 |
if not isinstance(version, str): |
| 14 | 185 |
if src_mod and hasattr(src_mod, "get_version"): |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
186 |
version_str = src_mod.get_version() |
| 14 | 187 |
elif isinstance(version, tuple): |
|
16
c0bf35ee1aed
correct get version to use integer instead of str
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
188 |
#convert num |
|
c0bf35ee1aed
correct get version to use integer instead of str
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
189 |
version_str = get_version([int(s) if s.isdigit() else s for s in version]) |
|
9
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
190 |
else: |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
191 |
version_str = str(version) |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
192 |
else: |
|
525a37ed8c18
various correction to add chuncked-uploads to platform
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
193 |
version_str = version |
| 22 | 194 |
|
| 15 | 195 |
print("VERSION str : %s" % repr(version_str)) |
| 22 | 196 |
return (version, version_str) |
197 |
||
| 0 | 198 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
199 |
def sync_build(c, path): |
| 0 | 200 |
print("Sync build %s" % path) |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
201 |
env = c.env |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
202 |
with Connection(env['hosts'][0]) as host_connection: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
203 |
with host_connection.cd(env.remote_path['build_export']): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
204 |
filename = os.path.basename(path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
205 |
res_trans = host_connection.put(path, os.path.join(env.remote_path['build_export'], filename)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
206 |
print("Sync build %s to %s" % (path,res_trans.remote)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
207 |
return res_trans |
| 0 | 208 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
209 |
# def remove_build(path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
210 |
# print("remove build build %s" % path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
211 |
# run("rm \"%s\"" % path) |
| 22 | 212 |
|
| 0 | 213 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
214 |
# def install_build(remotepath, remotevirtualenvpath, module_to_uninstall= None): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
215 |
# print("Install build %s in %s" % (remotepath, remotevirtualenvpath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
216 |
# activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
| 22 | 217 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
218 |
# with prefix("source %s" % activate_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
219 |
# if module_to_uninstall: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
220 |
# with settings(warn_only=True): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
221 |
# run("pip uninstall -y %s" % module_to_uninstall) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
222 |
# run("pip install --no-cache-dir \"%s\"" % remotepath) |
| 0 | 223 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
224 |
# def collectstatic(remotepath, remotevirtualenvpath, platform_web_module, module_settings="", admin_cmd="python manage.py"): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
225 |
# print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
226 |
# remotestaticsitepath = get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, "STATIC_ROOT", env.settings) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
227 |
# activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
228 |
# with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
229 |
# #remove old files optio -c of collect static fail ! |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
230 |
# run("rm -fr \"%s\"/*" % (remotestaticsitepath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
231 |
# run("%s collectstatic --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else "")) |
| 0 | 232 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
233 |
# def migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
234 |
# { |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
235 |
# 'syncdb': do_syncdb, |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
236 |
# 'migrate': do_migrate, |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
237 |
# }.get(getattr(env, 'migrate_method', 'migrate'), do_syncdb)(remotepath, remotevirtualenvpath, module_settings, admin_cmd) |
| 22 | 238 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
239 |
# def do_syncdb(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
240 |
# activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
241 |
# with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
242 |
# run("%s syncdb --migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else "")) |
| 22 | 243 |
|
244 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
245 |
# def do_migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
246 |
# activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
247 |
# with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
248 |
# run("%s migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else "")) |
| 22 | 249 |
|
250 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
251 |
# def create_config(export_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
252 |
# print("Create config from %s" % (export_path,)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
253 |
# remotepath = env.remote_path['src'] |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
254 |
# remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
255 |
# template_path = os.path.join(export_path, "src", env.platform_web_module, "config.py.tmpl") |
| 22 | 256 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
257 |
# context = { |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
258 |
# 'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/", |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
259 |
# 'asctime': '%(asctime)s', |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
260 |
# 'levelname': '%(levelname)s', |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
261 |
# 'message': '%(message)s', |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
262 |
# 'module': '%(module)s', |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
263 |
# } |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
264 |
# context.update(env.config['web']) |
| 22 | 265 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
266 |
# if not exists(remote_config_path, verbose=True): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
267 |
# upload_template(template_path, remote_config_path, context=context) |
| 0 | 268 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
269 |
def export_version(c, **kwargs): |
| 0 | 270 |
print("export version %s" % (repr(kwargs))) |
| 22 | 271 |
|
| 0 | 272 |
export_path = kwargs.get('path', None) |
| 22 | 273 |
|
274 |
if not export_path: |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
275 |
export_path = get_export_path(c.env, "_".join(["%s_%s" % (k,v) for k,v in kwargs.items()])) |
| 22 | 276 |
|
| 0 | 277 |
clean_export_folder(export_path) |
| 22 | 278 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
279 |
do_export_version(c, export_path,**kwargs) |
| 22 | 280 |
|
| 0 | 281 |
return export_path |
282 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
283 |
def do_create_virtualenv(c, remote_venv_export_path, remotevirtualenvpath): |
| 0 | 284 |
print("Create virtualenv export_path : %s - remote venvpath : %s" % (remote_venv_export_path, remotevirtualenvpath)) |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
285 |
env = c.env |
| 0 | 286 |
activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
287 |
if env.get('remote_baseline_venv'): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
288 |
prefix_str = "source \"%s\"" % os.path.join(env.get('remote_baseline_venv'), "bin/activate") |
| 0 | 289 |
else: |
290 |
prefix_str = "echo" |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
291 |
with Connection(env['hosts'][0]) as rconnection: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
292 |
rconnection.run("rm -fr \"%s\"" % remotevirtualenvpath, warn=True) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
293 |
run("mkdir -p \"%s\"" % remotevirtualenvpath) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
294 |
with rconnection.prefix(prefix_str), rconnection.cd(os.path.join(remote_venv_export_path,"virtualenv","web")): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
295 |
rconnection.run("python create_python_env.py") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
296 |
rconnection.run("python project-boot.py \"%s\"" % remotevirtualenvpath) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
297 |
with rconnection.prefix("source \"%s\"" % activate_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
298 |
rconnection.run("pip install --no-cache-dir -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt")) |
| 0 | 299 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
300 |
def do_create_virtualenv_requirement(c, remote_venv_requirement_path, remotevirtualenvpath, python_version = "2"): |
| 29 | 301 |
print("Create virtualenv export_path : %s - remote venvpath : %s" % (remote_venv_requirement_path, remotevirtualenvpath)) |
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
302 |
env = c.env |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
303 |
with Connection(env['hosts'][0]) as rconnection: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
304 |
rconnection.sudo("rm -fr \"%s\"" % remotevirtualenvpath, warn=True) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
305 |
rconnection.sudo("mkdir -p \"%s\"" % remotevirtualenvpath) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
306 |
# rconnection.run("virtualenv -p `which python%s` %s" % (python_version, remotevirtualenvpath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
307 |
rconnection.run("python%s -m venv %s" % (python_version, remotevirtualenvpath)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
308 |
with rconnection.prefix("source \"%s\"" % os.path.join(remotevirtualenvpath, "bin/activate")): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
309 |
rconnection.run("pip install -r \"%s\"" % remote_venv_requirement_path) |
| 29 | 310 |
|
311 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
312 |
# def do_sync_comp(key, export_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
313 |
# print("do_sync_comp with path %s" % (export_path)) |
| 22 | 314 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
315 |
# src_path = os.path.join(export_path,env.repos[key]['src_root']) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
316 |
# # find setup.py |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
317 |
# for root, _, files in os.walk(src_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
318 |
# if "setup.py" in files: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
319 |
# src_path = root |
| 22 | 320 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
321 |
# build_src(src_path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
322 |
# (_,version_str) = get_src_version(key, src_path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
323 |
# build_path = os.path.join(src_path,"dist","%s-%s.tar.gz" % (key,version_str)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
324 |
# sync_install_build(build_path, key) |
| 22 | 325 |
|
| 0 | 326 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
327 |
# def sync_install_build(build_path, module_to_uninstall=None): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
328 |
# res_trans = None |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
329 |
# try: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
330 |
# res_trans = sync_build(build_path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
331 |
# install_build(res_trans[0], env.remote_path['virtualenv'], module_to_uninstall) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
332 |
# finally: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
333 |
# if res_trans: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
334 |
# remove_build(res_trans[0]) |
| 0 | 335 |
|
336 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
337 |
# def do_sync_web(version, export_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
338 |
# print("do_sync_web with version %s and path %s" % (version,export_path)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
339 |
# #sync src |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
340 |
# src_path = os.path.join(export_path,"src/") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
341 |
# rsync_export(src_path, env.remote_path['src'], env.rsync_filters['src']) |
| 22 | 342 |
|
343 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
344 |
# def check_folder_access(): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
345 |
# print("Check folder access") |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
346 |
# # get remote user |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
347 |
# for folder_path in env.folders: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
348 |
# if not os.path.isabs(folder_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
349 |
# folder_path = env.remote_path['web'].rstrip("/")+ "/" + folder_path |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
350 |
# with settings(warn_only=True): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
351 |
# if not exists(folder_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
352 |
# run("mkdir -p \"%s\"" % folder_path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
353 |
# run("chown -R :%s \"%s\"" % (env.web_group, folder_path)) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
354 |
# run("chmod -R g+w \"%s\"" % folder_path) |
| 0 | 355 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
356 |
# def get_comp_versions_dict(export_path_web): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
357 |
# comp_versions = {} |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
358 |
# requirement_file_path = os.path.join(export_path_web, 'src', 'requirement.txt') |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
359 |
# if not os.path.exists(requirement_file_path): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
360 |
# return comp_versions |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
361 |
# with open(requirement_file_path) as f: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
362 |
# for line in f: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
363 |
# m = re.match('^([\w-]+)\s+\(\s*\=\=\s*([\.\d\w]+)\s*\)', line) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
364 |
# if m: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
365 |
# key, version_req = m.groups() |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
366 |
# if "." in version_req: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
367 |
# version_req = "V" + ".".join(["%02d" % (int(s)) if s.isdigit() else s for s in version_req.split(".")]) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
368 |
# comp_versions[key] = version_req |
| 22 | 369 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
370 |
# return comp_versions |
| 0 | 371 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
372 |
# def do_relaunch_server(do_collectstatic, do_migrate, do_check_folder_access): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
373 |
# if do_check_folder_access: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
374 |
# check_folder_access() |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
375 |
# if do_migrate: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
376 |
# migrate(env.remote_path['src'], env.remote_path['virtualenv'], env.get('settings', ''), env.get('admin_cmd', 'python manage.py')) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
377 |
# if do_collectstatic: |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
378 |
# collectstatic(env.remote_path['src'], env.remote_path['virtualenv'], env.platform_web_module, env.get('settings', ''), env.get('admin_cmd', 'python manage.py')) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
379 |
# sudo(env.web_relaunch_cmd, shell=False) |
| 0 | 380 |
|
381 |
||
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
382 |
# class SyncComp(Task): |
| 22 | 383 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
384 |
# def __init__(self, key): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
385 |
# self.key = key |
| 0 | 386 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
387 |
# def __get_name(self): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
388 |
# return "sync_" + self.key |
| 22 | 389 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
390 |
# name = property(__get_name) |
| 22 | 391 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
392 |
# def run(self, version): |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
393 |
# print(green("sync %s with version %s" % (self.key, version))) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
394 |
# export_path_web = export_version(web=version) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
395 |
# export_path_web_full = os.path.join(export_path_web,'web') |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
396 |
# comp_versions = get_comp_versions_dict(export_path_web_full) |
| 0 | 397 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
398 |
# export_path = export_version(**{self.key:comp_versions[self.key]}) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
399 |
# export_path_full = os.path.join(export_path,self.key) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
400 |
# do_sync_comp(self.key, export_path_full) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
401 |
# clean_export_folder(export_path) |
|
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
402 |
# clean_export_folder(export_path_web) |
| 22 | 403 |
|
|
32
800b7b8aa439
first iteration of migration to fabric 2 / python 3
ymh <ymh.work@gmail.com>
parents:
29
diff
changeset
|
404 |
# do_relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=True) |