forked from mytardis/mytardis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mytardis.py
executable file
·43 lines (37 loc) · 1.67 KB
/
mytardis.py
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
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import warnings
from tardis.tardis_portal.deprecations import RemovedInMyTardis42Warning
def run():
warnings.warn(
"mytardis.py will be removed in MyTardis 4.2. "
"Please use manage.py instead.",
RemovedInMyTardis42Warning
)
custom_settings = 'tardis.settings'
custom_settings_file = custom_settings.replace('.', '/') + '.py'
demo_settings = 'tardis.default_settings'
if os.path.isfile(custom_settings_file):
os.environ.setdefault("DJANGO_SETTINGS_MODULE", custom_settings)
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", demo_settings)
print('Using demo settings in "tardis/default_settings.py",'
' please add your own settings file, '
'"tardis/settings.py".')
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
if __name__ == "__main__":
from django.core.exceptions import ImproperlyConfigured
try:
run()
except ImproperlyConfigured as e:
if 'SECRET_KEY' in str(e):
print(r'''
# execute this wonderful command to have your settings.py created/updated
# with a generated Django SECRET_KEY (required for MyTardis to run)
python -c "import os; from random import choice; key_line = '%sSECRET_KEY=\"%s\" # generated from build.sh\n' % ('from .default_settings import * \n\n' if not os.path.isfile('tardis/settings.py') else '', ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789@#%^&*(-_=+)') for i in range(50)])); f=open('tardis/settings.py', 'a+'); f.write(key_line); f.close()"
''')
else:
raise