This repository has been archived by the owner on Jan 14, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpab
executable file
·117 lines (84 loc) · 3.34 KB
/
pab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
#
# This file is part of plinth-app-bootstrapper
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Script to quickly bootstrap a new plinth app
"""
import argparse
import os
import string
import subprocess
import cfg
CURR_DIR = "/".join(os.path.realpath(cfg.__file__).split("/")[:-1])
def parse_arguments():
""" Return parsed command line arguments as dictionary. """
parser = argparse.ArgumentParser(
description='Script to quickly bootstrap a new plinth app',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--app', help="Name of the new app")
parser.add_argument('--plinth-home', default=cfg.plinth_home,
help="Location of Plinth's repository")
arguments = parser.parse_args()
cfg.plinth_home = arguments.plinth_home
cfg.app = arguments.app
def create_git_branch():
"""Checkout a new git branch from master"""
subprocess.call(['git', 'checkout', 'master'])
subprocess.call(['git', 'checkout', '-b', cfg.app])
def enable_module():
"""Add app to enabled modules"""
with open(os.path.join('data/etc/plinth/modules-enabled', cfg.app),
'w') as f:
f.write(".".join(["plinth.modules", cfg.app]))
f.write("\n")
def create_actions_file():
"""Create a new actions file"""
actions_file = os.path.join('actions', cfg.app)
template_file = os.path.join(CURR_DIR, 'templates', 'action')
with open(template_file, 'r') as f:
template = f.read()
with open(actions_file, 'w') as f:
f.write(string.replace(template, "$app", cfg.app))
subprocess.call(['chmod', '+x', actions_file])
def create_django_app():
"""Create a new django app for the new plinth app"""
django_app_dir = os.path.join("plinth", "modules", cfg.app)
os.path.exists(django_app_dir) or os.makedirs(django_app_dir)
module_path = os.path.join(CURR_DIR, "templates", "module")
for fil in os.listdir(module_path):
with open(os.path.join(module_path, fil), 'r') as f:
template = f.read()
with open(os.path.join(django_app_dir, fil), 'w') as f:
f.write(string.replace(template, "$app", cfg.app))
def create_apache_config():
"""Create apache configuration"""
path = os.path.join(cfg.plinth_home, 'data/etc/apache2/conf-available',
"{}-plinth.conf".format(cfg.app))
os.path.exists(path) or subprocess.call(['touch', path])
def bootstrap():
os.chdir(cfg.plinth_home)
create_git_branch()
enable_module()
create_actions_file()
create_django_app()
create_apache_config()
def main():
"""Parse arguments and perform all duties."""
parse_arguments()
bootstrap()
if __name__ == '__main__':
main()