source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/applications/admin/controllers/openshift.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 2.3 KB
Line 
1import os
2try:
3    from distutils import dir_util
4except ImportError:
5    session.flash = T('requires distutils, but not installed')
6    redirect(URL('default', 'site'))
7try:
8    from git import *
9except ImportError:
10    session.flash = T('requires python-git, but not installed')
11    redirect(URL('default', 'site'))
12
13from gluon.settings import settings
14if not settings.is_source:
15    session.flash = 'Requires running web2py from source'
16    redirect(URL(request.application, 'default', 'site'))
17
18def 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
62class 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)
Note: See TracBrowser for help on using the repository browser.