aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xinstall.py50
-rw-r--r--requirements.pip2
-rw-r--r--servo/management/commands/makedirs.py3
3 files changed, 33 insertions, 22 deletions
diff --git a/install.py b/install.py
index 5b761e1..f2c1beb 100755
--- a/install.py
+++ b/install.py
@@ -6,37 +6,42 @@ import django
import requests
from string import Template
from subprocess import call
+from six.moves import input
+
+assert not os.path.exists('local_settings.py'), 'Local_settings already defined'
default_hostname = socket.gethostname()
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
-tpl_url = 'https://gist.githubusercontent.com/filipp/cba2ffecd0d5790f7245/raw/'
+tpl_url = 'https://gist.githubusercontent.com/filipp/cba2ffecd0d5790f7245/raw/9d5b140ed23c1bbdbadbd5c674d3a00c00d80047/local_settings.py'
fh = open('local_settings.py', 'w')
print("** Creating local configuration file **")
args = {}
-args['dbadmin'] = raw_input('DB admin username [pgsql]: ') or 'pgsql'
+args['dbadmin'] = input('DB admin username [pgsql]: ') or os.getenv('pgsql')
+args['dbhost'] = input('1/10 Database host [localhost]: ') or 'localhost'
+args['dbname'] = input('2/10 Database [servo]: ') or 'servo'
+args['dbuser'] = input('3/10 DB user [servo]: ') or 'servo'
+args['dbpwd'] = input('4/10 DB password []: ') or ''
+
+assert call(['createuser', args['dbuser'], '-U', args['dbadmin']]) == 0, 'Could not create DB user'
+
args['secret_key'] = os.urandom(32).encode('base-64').strip()
-args['install_locale'] = raw_input('1/10 Locale [sv_SE.UTF-8]: ') or 'sv_SE.UTF-8'
+args['install_locale'] = input('51/10 Locale [sv_SE.UTF-8]: ') or 'sv_SE.UTF-8'
default_country = args['install_locale'].split('_')[0]
-args['install_country'] = raw_input('2/10 Country [%s]: ' % default_country) or default_country
+args['install_country'] = input('6/10 Country [%s]: ' % default_country) or default_country
default_lang = args['install_locale'].split('_')[1][:2]
-args['install_language'] = raw_input('3/10 Language [%s]: ' % default_lang) or default_lang
-args['timezone'] = raw_input('4/10 Timezone [Europe/Stockholm]: ') or 'Europe/Stockholm'
-args['install_id'] = raw_input('5/10 Installation ID [22]: ') or '22'
-args['hostname'] = raw_input('6/10 Hostname [%s]: ' % default_hostname) or default_hostname
-args['dbhost'] = raw_input('7/10 Database host [localhost]: ') or 'localhost'
-args['dbname'] = raw_input('8/10 Database [servo]: ') or 'servo'
-args['dbuser'] = raw_input('9/10 DB user [servo]: ') or 'servo'
-args['dbpwd'] = raw_input('10/10 DB password []: ') or ''
+args['install_language'] = input('7/10 Language [%s]: ' % default_lang) or default_lang
+args['timezone'] = input('8/10 Timezone [Europe/Stockholm]: ') or 'Europe/Stockholm'
+args['install_id'] = input('9/10 Installation ID [22]: ') or '22'
+args['hostname'] = input('10/10 Hostname [%s]: ' % default_hostname) or default_hostname
raw = requests.get(tpl_url).text
template = Template(raw)
s = template.substitute(**args)
-call(['createuser', args['dbuser'], '-U', args['dbadmin']])
call(['createdb', args['dbname'], '-O', args['dbuser'], '-U', args['dbadmin']])
fh.write(s)
@@ -55,12 +60,12 @@ call(['./manage.py', 'createsuperuser'])
loc = {}
django.setup() # To avoid django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
print("** Creating initial Service Location **")
-loc['title'] = raw_input('1/6 Name [PretendCo Inc]: ') or 'PretendCo Inc'
-loc['email'] = raw_input('2/6 Email [service@pretendo.com]: ') or 'service@pretendo.com'
-loc['phone'] = raw_input('3/6 Phone [123456789]: ') or '123456789'
-loc['address'] = raw_input('4/6 Address [Somestreet 1]: ') or 'Somestreet 1'
-loc['zip_code'] = raw_input('5/6 Postal code [1234]: ') or '1234'
-loc['city'] = raw_input('6/6 City [Stockholm]: ') or 'Stockholm'
+loc['title'] = input('1/6 Name [PretendCo Inc]: ') or 'PretendCo Inc'
+loc['email'] = input('2/6 Email [service@pretendo.com]: ') or 'service@pretendo.com'
+loc['phone'] = input('3/6 Phone [123456789]: ') or '123456789'
+loc['address'] = input('4/6 Address [Somestreet 1]: ') or 'Somestreet 1'
+loc['zip_code'] = input('5/6 Postal code [1234]: ') or '1234'
+loc['city'] = input('6/6 City [Stockholm]: ') or 'Stockholm'
from servo.models.common import Location
from servo.models.account import User
@@ -83,4 +88,7 @@ call(['openssl', 'req', '-nodes', '-x509', '-newkey', 'rsa:2048',
'-days', '365', '-subj', subj,
'-keyout', 'servo.key', '-out', 'servo.crt'])
-print("Your Servo installation is ready for action at https://%s" % args['hostname'])
+print("""
+Your Servo installation is ready for action at https://%s.
+For testing purposes, you can also run it with ./manage runserver.
+""" % args['hostname'])
diff --git a/requirements.pip b/requirements.pip
index 24724ae..015471d 100644
--- a/requirements.pip
+++ b/requirements.pip
@@ -6,7 +6,7 @@ djangorestframework
babel
markdown
python-memcached
-psycopg2
+psycopg2-binary
Pillow
reportlab
pytz
diff --git a/servo/management/commands/makedirs.py b/servo/management/commands/makedirs.py
index 2718f5f..16a9913 100644
--- a/servo/management/commands/makedirs.py
+++ b/servo/management/commands/makedirs.py
@@ -13,6 +13,9 @@ class Command(BaseCommand):
'products', 'repairs', 'return_labels',
'settings', 'temp', 'templates']
+ if not os.path.exists(settings.MEDIA_ROOT):
+ os.mkdir(settings.MEDIA_ROOT)
+
for d in dirs:
fp = os.path.join(settings.MEDIA_ROOT, d)
try: