-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.py
More file actions
91 lines (67 loc) · 2.91 KB
/
uninstall.py
File metadata and controls
91 lines (67 loc) · 2.91 KB
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
import argparse
import os
import virtual_host
import app
import json
import check, virtual_host
from subprocess import call
def create_client_dir(client_dir=None):
"""Create client directories"""
if not os.path.exists(client_dir):
os.makedirs(client_dir)
def create_client_sub_dir(client_dir=None):
"""Create client sub directories"""
os.chdir(client_dir)
client_sub_dirs = ['config', 'apps', 'backups']
for sub_dir in client_sub_dirs:
if not os.path.exists(sub_dir):
os.makedirs(sub_dir)
def copy_app_settings_dir(client_dir=None, app_name=None, json_dict=None):
""" Copy the entire settings dir + files to the app """
if 'template_dir' in json_dict.keys():
current_dir = os.path.dirname(os.path.realpath(__file__))
template_path = json_dict['template_dir'] + app_name
client_app_path = current_dir + '/config/'
call(['cp', '-a', template_path, client_app_path])
count = 0
app_dirs = os.listdir(client_app_path)
for app in app_dirs:
if app_name in app_dirs:
count += 1
old_app_name = client_app_path + app_name
new_app_name = client_app_path + app_name + '_' + str(count)
call(['mv', old_app_name, new_app_name])
app_name = app_name + '_' + str(count)
# Remove the copied template json file since we no longer need it
if os.path.exists(json_dict['json_copy']):
os.remove(json_dict['json_copy'])
# Remove the template and replace with the copy for this app
copied_json = client_app_path + app_name + '/copy_' + app_name.split('_',1)[0] + '.json'
template_json = client_app_path + app_name + '/' + app_name.split('_',1)[0] + '.json'
# Rename the app yml file
template_yml = client_app_path + app_name + '/' + app_name.split('_',1)[0] + '.yml'
app_yml = client_app_path + app_name + '/docker-compose.yml'
if os.path.exists(template_json):
os.remove(template_json)
os.rename(copied_json, template_json)
os.rename(template_yml, app_yml)
return app_name
def create_app_txt_file(app_details=None):
""" Save app details into some text file for Django to read """
# TODO: Change this to servers /usr/shared directory or something
os.chdir(os.path.expanduser('~/Documents/jobstuff/spinetta/sprint/mvp_platform/backend/static/'))
file = open('app_details.json','a')
file.write(json.dumps(app_details, indent=4) + ',')
call(['pwd'])
if __name__ =='__main__':
""" Root of the program """
current_dir = os.path.dirname(os.path.realpath(__file__))
parser = argparse.ArgumentParser(description='''Run this script with the following format: python root.py --client=name --app=appname --vhost=vhostname''')
parser.add_argument('--client', type=str, help='e.g. client_ikkai_benjamin')
parser.add_argument('--app', type=str, help='e.g. drupal')
args = parser.parse_args()
# Main args to build an app
client_name = args.client
app_name = args.app
print(client_name)
print(app_name)