forked from mrkipling/maraschino
/
Maraschino.py
141 lines (110 loc) · 3.4 KB
/
Maraschino.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
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
131
132
133
134
135
136
137
138
139
140
141
import sys
import os
rundir = os.path.dirname(os.path.abspath(__file__))
try:
frozen = sys.frozen
except AttributeError:
frozen = False
# Define path based on frozen state
if frozen:
path_base = os.environ['_MEIPASS2']
rundir = os.path.dirname(sys.executable)
else:
path_base = rundir
# Include paths
sys.path.insert(0, path_base)
sys.path.insert(0, os.path.join(path_base, 'lib'))
from flask import Flask
app = Flask(__name__)
def import_modules():
import modules.applications
import modules.controls
import modules.currently_playing
import modules.diskspace
import modules.index
import modules.library
import modules.log
import modules.recently_added
import modules.remote
import modules.sabnzbd
import modules.search
import modules.sickbeard
import modules.trakt
import modules.traktplus
import modules.transmission
import modules.updater
import modules.utorrent
import modules.weather
import modules.xbmc_notify
import mobile
@app.teardown_request
def shutdown_session(exception=None):
from maraschino.database import db_session
db_session.remove()
import maraschino
def main():
from optparse import OptionParser
p = OptionParser()
p.add_option('-p', '--port',
dest='port',
default=None,
help="Force webinterface to listen on this port")
p.add_option('-d', '--daemon',
dest='daemon',
action='store_true',
help='Run as a daemon')
p.add_option('--pidfile',
dest='pidfile',
help='Create a pid file (only relevant when running as a daemon)')
p.add_option('--log',
dest='log',
help='Create a log file at a desired location')
p.add_option('-v', '--verbose',
dest='verbose',
action='store_true',
help='Silence the logger')
p.add_option('--develop',
action="store_true",
dest='develop',
help="Start instance of development server")
p.add_option('--database',
dest='database',
help='Custom database file location')
p.add_option('--webroot',
dest='webroot',
help='web root for Maraschino')
options, args = p.parse_args()
if options.daemon:
maraschino.DAEMON = True
maraschino.VERBOSE = False
if options.pidfile:
maraschino.PIDFILE = options.pidfile
maraschino.VERBOSE = False
if options.port:
PORT = int(options.port)
else:
PORT = 7000
if options.log:
maraschino.LOG_FILE = options.log
if options.verbose:
maraschino.VERBOSE = True
if options.develop:
maraschino.DEVELOPMENT = True
if options.database:
DATABASE = options.database
else:
DATABASE = os.path.join(rundir, 'maraschino.db')
if options.webroot:
maraschino.WEBROOT = options.webroot
maraschino.RUNDIR = rundir
maraschino.FULL_PATH = os.path.join(rundir, 'Maraschino.py')
maraschino.ARGS = sys.argv[1:]
maraschino.PORT = PORT
maraschino.DATABASE = DATABASE
maraschino.initialize()
import_modules()
if maraschino.PIDFILE or maraschino.DAEMON:
maraschino.daemonize()
maraschino.start()
if __name__ == '__main__':
main()