Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
172 changed files
with
41,167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import os | ||
import os.path | ||
import threading | ||
import time | ||
import signal | ||
import sqlite3 | ||
import sys | ||
|
||
import cherrypy | ||
import cherrypy.lib.auth_basic | ||
|
||
import sickbeard | ||
|
||
from sickbeard import exceptions, db, helpers, nzb, searchBacklog, searchCurrent, tvnzbbot, updateShows, webserve | ||
from sickbeard.tv import TVShow, TVEpisode | ||
from sickbeard.logging import * | ||
from sickbeard.common import * | ||
|
||
from lib.configobj import ConfigObj | ||
|
||
signal.signal(signal.SIGINT, sickbeard.sig_handler) | ||
signal.signal(signal.SIGTERM, sickbeard.sig_handler) | ||
|
||
def loadShowsFromDB(): | ||
|
||
myDB = db.DBConnection() | ||
myDB.checkDB() | ||
|
||
sqlResults = [] | ||
myShowList = [] | ||
|
||
try: | ||
sql = "SELECT * FROM tv_shows" | ||
sqlResults = myDB.connection.execute(sql).fetchall() | ||
#print "found", sqlResults | ||
|
||
except sqlite3.DatabaseError as e: | ||
Logger().log("Fatal error executing query '" + sql + "': " + str(e), ERROR) | ||
raise | ||
|
||
for sqlShow in sqlResults: | ||
curShow = TVShow(sqlShow["location"]) | ||
curShow.saveToDB() | ||
myShowList.append(curShow) | ||
#TODO: make it update the existing shows if the showlist has something in it | ||
|
||
return myShowList | ||
|
||
|
||
|
||
def main(): | ||
|
||
# do some preliminary stuff | ||
sickbeard.PROG_DIR = os.path.dirname(os.path.normpath(os.path.abspath(sys.argv[0]))) | ||
sickbeard.CONFIG_FILE = "config.ini" | ||
|
||
# rename the main thread | ||
threading.currentThread().name = "MAIN" | ||
|
||
Logger().log("Starting up midgetPVR from " + os.path.join(sickbeard.PROG_DIR, sickbeard.CONFIG_FILE)) | ||
|
||
# load the config and publish it to the sickbeard package | ||
if not os.path.isfile(os.path.join(sickbeard.PROG_DIR, sickbeard.CONFIG_FILE)): | ||
Logger().log("Unable to find config.ini - aborting", ERROR) | ||
sys.exit() | ||
sickbeard.CFG = ConfigObj(os.path.join(sickbeard.PROG_DIR, sickbeard.CONFIG_FILE)) | ||
|
||
# initialize the config and our threads | ||
sickbeard.initialize() | ||
|
||
# build from the DB to start with | ||
Logger().log("Loading initial show list") | ||
sickbeard.showList = loadShowsFromDB() | ||
|
||
# setup cherrypy logging | ||
if os.path.isdir(sickbeard.LOG_DIR) and sickbeard.WEB_LOG: | ||
cherry_log = os.path.join(sickbeard.LOG_DIR, "cherrypy.log") | ||
Logger().log("Using " + cherry_log + " for cherrypy log") | ||
else: | ||
cherry_log = None | ||
|
||
# cherrypy setup | ||
webRoot = webserve.Whatever() | ||
cherrypy.config.update({ | ||
'server.socket_port': sickbeard.WEB_PORT, | ||
'server.socket_host': '0.0.0.0', | ||
'log.screen': False, | ||
'log.access_file': cherry_log | ||
}) | ||
|
||
userpassdict = {sickbeard.WEB_USERNAME: sickbeard.WEB_PASSWORD} | ||
checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userpassdict) | ||
|
||
if sickbeard.WEB_USERNAME == "" or sickbeard.WEB_PASSWORD == "": | ||
useAuth = False | ||
else: | ||
useAuth = True | ||
|
||
conf = {'/': { | ||
'tools.staticdir.root': os.path.join(sickbeard.PROG_DIR, 'data'), | ||
'tools.auth_basic.on': useAuth, | ||
'tools.auth_basic.realm': 'MidgetPVR', | ||
'tools.auth_basic.checkpassword': checkpassword}, | ||
'/images': {'tools.staticdir.on': True, | ||
'tools.staticdir.dir': 'images'}, | ||
'/css': {'tools.staticdir.on': True, | ||
'tools.staticdir.dir': 'css'}, | ||
'/js': {'tools.staticdir.on': True, | ||
'tools.statirdir.dir': 'scripts'} | ||
} | ||
|
||
cherrypy.tree.mount(webRoot, '/', conf) | ||
|
||
# launch a browser if we need to | ||
browserURL = 'http://localhost:' + str(sickbeard.WEB_PORT) + '/' | ||
|
||
try: | ||
cherrypy.server.start() | ||
cherrypy.server.wait() | ||
except IOError: | ||
Logger().log("Unable to start web server, is something else running?", ERROR) | ||
Logger().log("Launching browser and exiting", ERROR) | ||
sickbeard.launchBrowser(browserURL) | ||
sys.exit() | ||
|
||
# fire up all our threads | ||
sickbeard.start() | ||
|
||
# launch browser if we're supposed to | ||
if sickbeard.LAUNCH_BROWSER: | ||
sickbeard.launchBrowser(browserURL) | ||
|
||
# stay alive while my threads do the work | ||
while (True): | ||
|
||
time.sleep(1) | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.