1 | import os |
---|
2 | try: |
---|
3 | from distutils import dir_util |
---|
4 | except ImportError: |
---|
5 | session.flash = T('requires distutils, but not installed') |
---|
6 | redirect(URL('default', 'site')) |
---|
7 | try: |
---|
8 | from git import * |
---|
9 | except ImportError: |
---|
10 | session.flash = T('requires python-git, but not installed') |
---|
11 | redirect(URL('default', 'site')) |
---|
12 | |
---|
13 | from gluon.settings import settings |
---|
14 | if not settings.is_source: |
---|
15 | session.flash = 'Requires running web2py from source' |
---|
16 | redirect(URL(request.application, 'default', 'site')) |
---|
17 | |
---|
18 | def deploy(): |
---|
19 | apps = sorted(file for file in os.listdir(apath(r=request))) |
---|
20 | form = SQLFORM.factory( |
---|
21 | Field( |
---|
22 | 'osrepo', default='/tmp', label=T('Path to local openshift repo root.'), |
---|
23 | requires=EXISTS(error_message=T('directory not found'))), |
---|
24 | Field('osname', default='web2py', label=T('WSGI reference name')), |
---|
25 | Field('applications', 'list:string', |
---|
26 | requires=IS_IN_SET(apps, multiple=True), |
---|
27 | label=T('web2py apps to deploy'))) |
---|
28 | |
---|
29 | cmd = output = errors = "" |
---|
30 | if form.accepts(request, session): |
---|
31 | try: |
---|
32 | kill() |
---|
33 | except: |
---|
34 | pass |
---|
35 | |
---|
36 | ignore_apps = [ |
---|
37 | item for item in apps if not item in form.vars.applications] |
---|
38 | regex = re.compile('\(applications/\(.*') |
---|
39 | w2p_origin = os.getcwd() |
---|
40 | osrepo = form.vars.osrepo |
---|
41 | osname = form.vars.osname |
---|
42 | #Git code starts here |
---|
43 | repo = Repo(form.vars.osrepo) |
---|
44 | index = repo.index |
---|
45 | assert repo.bare == False |
---|
46 | |
---|
47 | for i in form.vars.applications: |
---|
48 | appsrc = os.path.join(apath(r=request), i) |
---|
49 | appdest = os.path.join(osrepo, 'wsgi', osname, 'applications', i) |
---|
50 | dir_util.copy_tree(appsrc, appdest) |
---|
51 | #shutil.copytree(appsrc,appdest) |
---|
52 | index.add(['wsgi/' + osname + '/applications/' + i]) |
---|
53 | new_commit = index.commit("Deploy from Web2py IDE") |
---|
54 | |
---|
55 | origin = repo.remotes.origin |
---|
56 | origin.push |
---|
57 | origin.push() |
---|
58 | #Git code ends here |
---|
59 | return dict(form=form, command=cmd) |
---|
60 | |
---|
61 | |
---|
62 | class EXISTS(object): |
---|
63 | def __init__(self, error_message='file not found'): |
---|
64 | self.error_message = error_message |
---|
65 | |
---|
66 | def __call__(self, value): |
---|
67 | if os.path.exists(value): |
---|
68 | return (value, None) |
---|
69 | return (value, self.error_message) |
---|