-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstaller.py
More file actions
executable file
·130 lines (106 loc) · 4.21 KB
/
Copy pathinstaller.py
File metadata and controls
executable file
·130 lines (106 loc) · 4.21 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
# (c) 2015 Magnus "Tuxie" Johnsson, magnusjjj@gmail.com
# Licensed under the BSD license, see LICENSE.TXT in the root folder.
# Revision 1
# Changelog:
# 2015-04-14 - Magnus Johnsson - Added the license header
# This is a bleeding test
import sys
import random
import string
import os
class Installer:
def pip_install(self):
# Install all the python dependencies :)
os.system(sys.executable + " -m pip install --upgrade pip")
os.system(sys.executable + " -m easy_install setuptools==25.1.0")
os.system(sys.executable + " -m pip install --upgrade -r requirements.txt")
def installer_console_tutorial(self):
# We generate the settings file. This function *looks* big and scary, but is really super duper simple. Watch:
# Open the settings file for writing:
fout = open("gfe/settings_local.py", "w")
# Generate a naive security key for cookies and things:
SECRET_KEY = ''.join(random.SystemRandom().choice(string.uppercase + string.digits) for _ in xrange(20))
# Get the current directory
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Get the directory to store all the static files in:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# Get the directory to store all the media (image uploads, etc) in:
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Ask the user a bunch of questions:
print("What mail do you want to send emails from? ")
EMAILFROM = sys.stdin.readline().strip()
print("What is the database name? ")
DATABASE_NAME = sys.stdin.readline().strip()
print("What is the database user? ")
DATABASE_USER = sys.stdin.readline().strip()
print("What is the database password? ")
DATABASE_PASSWORD = sys.stdin.readline().strip()
print("What is the database host? ")
DATABASE_HOST = sys.stdin.readline().strip()
# Generate the string with the settings file in, yay!
file = """
SECRET_KEY = '""" + SECRET_KEY + """'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '""" + DATABASE_NAME.encode("string_escape") + """',
'USER': '""" + DATABASE_USER.encode("string_escape") + """',
'PASSWORD': '""" + DATABASE_PASSWORD.encode("string_escape") + """',
'HOST': '""" + DATABASE_HOST.encode("string_escape") + """'
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT= '""" + STATIC_ROOT.encode("string_escape") + """'
MEDIA_ROOT = '""" + MEDIA_ROOT.encode("string_escape") + """'
MEDIA_URL = "/media/"
EMAILFROM = '""" + EMAILFROM.encode("string_escape") + """'"""
# Save and close. Done!
fout.write(file)
fout.close()
# That wasn't so bad, was it?
def post_config(self):
os.system("git update-index --assume-unchanged gfe/settings_local.py")
# All the configuration *after* the settings have been saved
os.system(sys.executable + " manage.py collectstatic")
os.system(sys.executable + " manage.py makemigrations")
os.system(sys.executable + " manage.py migrate")
os.system(sys.executable + " manage.py createcachetable spirit_cache")
# Fix ownership of files
# os.system("chown " + str(os.stat("installer.py").st_uid) + " -R ./")
# os.system("chgrp " + str(os.stat("installer.py").st_gid) + " -R ./")
os.system(sys.executable + " manage.py createcachetable spirit_cache")
print(
"Do you want to fill the database with sample data? (write lowercase yes for yes, anything else is treated as no\n")
dofill = sys.stdin.readline().strip()
if dofill == "yes":
os.system(sys.executable + " manage.py populatedata 1")
else:
os.system(sys.executable + " manage.py populatedata")
print("All done!\n")
print("What do you want to do? ")
print("1) Install requirements ")
print("2) Create a config file")
print("3) Do post config")
print("Anything else exits")
command = sys.stdin.readline().strip()
installer = Installer()
if command == "1":
installer.pip_install()
if command == "2":
installer.installer_console_tutorial()
if command == "3":
installer.post_config()