-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanage.py
68 lines (50 loc) · 2.45 KB
/
manage.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
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
#! /usr/bin/python
"""
Test class which runs a python server for testing the web application, along the lines of
Django manage.py. The globals module _DEBUG_ variable is set to True, which means
this program is run in debug mode
Usage
python manage.py runserver [port] (or r [port])
python manage.py openbrowser [port] (or o [port])
(port is optional. When not run from within the manage.py directory 'manage.py'
must be typed with full path)
(c) 2014, GFZ Potsdam
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any later
version. For more information, see http://www.gnu.org/
"""
from __future__ import print_function
__author__="Riccardo Zaccarelli, PhD <riccardo(at)gfz-potsdam.de, riccardo.zaccarelli(at)gmail.com>"
__date__ ="$Jun 12, 2014 9:14:21 AM$"
import os.path
import sys #for parsing command line args
import os
if __name__ == "__main__":
import caravan.settings.globals as glb
glb._DEBUG_ = True; #set it to True if executing this script
#change the python working directory, if we called this script from outside the
#dir this file is. It is necessary otherwise all referrences to files, which are
#relative, will be messed up in our app
#pt = os.path.realpath(__file__)
#os.chdir(os.path.dirname(pt))
openbrowser = ("o", "openbrowser")
runserver = ("r", "runserver")
file = "" #"caravan/static/index.html"
port = 8080
#set debug mode to true:
import caravan.settings.globals as glb
glb._DEBUG_ = True
#first argument is the script name (manage.py), therefore we start reading from index 1
if (len(sys.argv)<2 or not (sys.argv[1] in openbrowser or sys.argv[1] in runserver)):
print("ERROR! call manage.py opt port (where port is optional, defaults to 8080)")
print( "where opt is:")
print( "\t{0} to run a server at the specified url and port ".format(' or '.join([v for v in runserver])))
print( "\t{0} to run a server and open the browser at the specified url and port ".format(' or '.join([v for v in openbrowser])))
quit()
if(len(sys.argv)>2):
port = sys.argv[2]
from caravan_wsgi import CaravanApp
from miniwsgi import run
import main
run(main.application, file=file, openbrowser= (sys.argv[1] in openbrowser), port = port)