Skip to content

Commit

Permalink
Fixed Settings Page. Added upcoming releases page. Changed Background…
Browse files Browse the repository at this point in the history
… Task to monitor in order for scheduled tasks to work with daemon mode.
  • Loading branch information
Michael Dlesk committed Jan 11, 2012
1 parent 5456be9 commit 16cd36a
Show file tree
Hide file tree
Showing 73 changed files with 2,044 additions and 29 deletions.
Binary file modified Gamez.db
Binary file not shown.
1 change: 1 addition & 0 deletions Gamez.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ port =
api_key = ""
host = "127.0.0.1"
port = 8081
category = ""

[Scheduler]
download_interval = 60
Expand Down
33 changes: 21 additions & 12 deletions Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
import sched
import time
import threading
import thread
import datetime
import lib.GameTasks
import ConfigParser
import cherrypy.process.plugins
from cherrypy.process.plugins import Daemonizer
from lib.ConfigFunctions import CheckConfigForAllKeys
from lib.DBFunctions import ValidateDB,AddWiiGamesIfMissing,AddXbox360GamesIfMissing
from lib.DBFunctions import ValidateDB,AddWiiGamesIfMissing,AddXbox360GamesIfMissing,AddComingSoonGames
from lib.Logger import LogEvent
import cherrypy.lib.auth_basic

app_path = os.path.dirname(os.path.abspath("__FILE__"))
config_path = os.path.join(app_path,'Gamez.ini')

class RunApp():


def RunWebServer(self,isToDaemonize):
LogEvent("Generating CherryPy configuration")
cherrypy.config.update(config_path)
Expand Down Expand Up @@ -49,10 +52,10 @@ def RunWebServer(self,isToDaemonize):
'/css/navigation_images':{'tools.staticdir.on':True,'tools.staticdir.dir':navigation_images_path},
'/css/datatables_images':{'tools.staticdir.on':True,'tools.staticdir.dir':datatables_images_path},
}
daemon = Daemonizer(cherrypy.engine)

if(isToDaemonize == 1):
LogEvent("Preparing to run in daemon mode")
LogEvent("Preparing to run in daemon mode")
daemon = Daemonizer(cherrypy.engine)
daemon.subscribe()

LogEvent("Generating Post Process Script")
Expand All @@ -66,20 +69,23 @@ def RunWebServer(self,isToDaemonize):
updateGameListInterval = config.get('Scheduler','game_list_update_interval').replace('"','')
fInterval = float(interval)
fUpdateGameListInterval = float(updateGameListInterval)
workerTask = cherrypy.process.plugins.BackgroundTask(fInterval,RunGameTask)
gameListUpdaterWorkTask = cherrypy.process.plugins.BackgroundTask(fUpdateGameListInterval,RunGameListUpdaterTask)
#thread.start_new_thread(ScheduleGameTasks,(fInterval,))
#workerTask = cherrypy.process.plugins.BackgroundTask(fInterval,RunGameTask)
#gameListUpdaterWorkTask = cherrypy.process.plugins.BackgroundTask(fUpdateGameListInterval,RunGameListUpdaterTask)
try:
workerTask.start()
gameListUpdaterWorkTask.start()

LogEvent("Setting up download scheduler")
gameTasksScheduler = cherrypy.process.plugins.Monitor(cherrypy.engine,RunGameTask,fInterval)
gameTasksScheduler.subscribe()
LogEvent("Setting up game list update scheduler")
gameListUpdaterScheduler = cherrypy.process.plugins.Monitor(cherrypy.engine,RunGameListUpdaterTask,fUpdateGameListInterval)
gameListUpdaterScheduler.subscribe()
LogEvent("Starting the Gamez web server")
cherrypy.quickstart(WebRoot(app_path),'/',config=conf)
except KeyboardInterrupt:
LogEvent("Shutting down Gamez")
workerTask.cancel()
gameListUpdaterWorkTask.cancel()
if(isToDaemonize == 1):
daemon.unsubscribe()
sys.exit()

def GenerateSabPostProcessScript():
config = ConfigParser.RawConfigParser()
Expand Down Expand Up @@ -128,13 +134,14 @@ def RunGameTask():
sabnzbdHost = config.get('Sabnzbd','host').replace('"','')
sabnzbdPort = config.get('Sabnzbd','port').replace('"','')
sabnzbdApi = config.get('Sabnzbd','api_key').replace('"','')
sabnzbdCategory = config.get('Sabnzbd','category').replace('"','')
newznabWiiCat = config.get('Newznab','wii_category_id').replace('"','')
newznabXbox360Cat = config.get('Newznab','xbox360_category_id').replace('"','')
newznabApi = config.get('Newznab','api_key').replace('"','')
newznabHost = config.get('Newznab','host').replace('"','')
newznabPort = config.get('Newznab','port').replace('"','')
LogEvent("Searching for games")
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat)
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat,sabnzbdCategory)
except:
errorMessage = "Major error occured when running scheduled tasks"
for message in sys.exc_info():
Expand All @@ -148,6 +155,8 @@ def RunGameListUpdaterTask():
LogEvent("Wii Game List Updated")
AddXbox360GamesIfMissing()
LogEvent("XBOX 360 Game List Updated")
AddComingSoonGames
LogEvent("Coming Soon Game List Updated")
except:
errorMessage = "Major error occured when running Update Game List scheduled tasks"
for message in sys.exc_info():
Expand All @@ -165,4 +174,4 @@ def RunGameListUpdaterTask():
if(param == "-d"):
isToDaemonize = 1

RunApp().RunWebServer(isToDaemonize)
RunApp().RunWebServer(isToDaemonize)
Binary file modified cherrypy/__init__.pyc
Binary file not shown.
Binary file modified cherrypy/_cpchecker.pyc
Binary file not shown.
Binary file modified cherrypy/_cpcompat.pyc
Binary file not shown.
Binary file modified cherrypy/_cpconfig.pyc
Binary file not shown.
Binary file modified cherrypy/_cpdispatch.pyc
Binary file not shown.
Binary file modified cherrypy/_cperror.pyc
Binary file not shown.
Binary file modified cherrypy/_cplogging.pyc
Binary file not shown.
Binary file modified cherrypy/_cpreqbody.pyc
Binary file not shown.
Binary file modified cherrypy/_cprequest.pyc
Binary file not shown.
Binary file modified cherrypy/_cpserver.pyc
Binary file not shown.
Binary file modified cherrypy/_cptools.pyc
Binary file not shown.
Binary file modified cherrypy/_cptree.pyc
Binary file not shown.
Binary file modified cherrypy/_cpwsgi.pyc
Binary file not shown.
Binary file modified cherrypy/_cpwsgi_server.pyc
Binary file not shown.
Binary file modified cherrypy/lib/__init__.pyc
Binary file not shown.
Binary file modified cherrypy/lib/auth.pyc
Binary file not shown.
Binary file modified cherrypy/lib/auth_basic.pyc
Binary file not shown.
Binary file modified cherrypy/lib/auth_digest.pyc
Binary file not shown.
Binary file modified cherrypy/lib/caching.pyc
Binary file not shown.
Binary file modified cherrypy/lib/cptools.pyc
Binary file not shown.
Binary file modified cherrypy/lib/encoding.pyc
Binary file not shown.
Binary file modified cherrypy/lib/httpauth.pyc
Binary file not shown.
Binary file modified cherrypy/lib/httputil.pyc
Binary file not shown.
Binary file modified cherrypy/lib/jsontools.pyc
Binary file not shown.
Binary file modified cherrypy/lib/reprconf.pyc
Binary file not shown.
Binary file modified cherrypy/lib/sessions.pyc
Binary file not shown.
Binary file modified cherrypy/lib/static.pyc
Binary file not shown.
Binary file modified cherrypy/lib/xmlrpcutil.pyc
Binary file not shown.
Binary file modified cherrypy/process/__init__.pyc
Binary file not shown.
Binary file modified cherrypy/process/plugins.pyc
Binary file not shown.
Binary file modified cherrypy/process/servers.pyc
Binary file not shown.
Binary file modified cherrypy/process/win32.pyc
Binary file not shown.
Binary file modified cherrypy/process/wspbus.pyc
Binary file not shown.
Binary file modified cherrypy/wsgiserver/__init__.pyc
Binary file not shown.
Binary file modified cherrypy/wsgiserver/wsgiserver2.pyc
Binary file not shown.
93 changes: 93 additions & 0 deletions cron/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from app.config.cplog import CPLog
from app.lib.cron.eta import startEtaCron, etaQueue
from app.lib.cron.renamer import startRenamerCron
from app.lib.cron.movierss import startMovieRSSCron
from app.lib.cron.kinepolisrss import startKinepolisRSSCron
from app.lib.cron.trakt import startTraktCron
from app.lib.cron.subtitle import subtitleQueue, startSubtitleCron
from app.lib.cron.trailer import startTrailerCron, trailerQueue
from app.lib.cron.yarr import startYarrCron
from app.lib.provider.movie.search import movieSearcher
from app.lib.provider.yarr.search import Searcher
from app.lib.sabNzbd import sabNzbd
from app.lib.nzbget import nzbGet
from app.lib.transmission import transmission
from cherrypy.process import plugins
import cherrypy
import sys

log = CPLog(__name__)

class CronJobs(plugins.SimplePlugin):

config = {}
threads = {}
searchers = {}

def __init__(self, bus, config, debug):
plugins.SimplePlugin.__init__(self, bus)

self.config = config
self.debug = debug

def start(self):

config = self.config

log.info("Starting Cronjobs.")
self.config = config

#searchers
yarrSearch = Searcher(config, self.debug);
movieSearch = movieSearcher(config);
self.searchers['yarr'] = yarrSearch
self.searchers['movie'] = movieSearch

#trailer cron
trailerCronJob = startTrailerCron(config, self.debug)
self.threads['trailer'] = trailerCronJob
self.searchers['trailerQueue'] = trailerQueue

#subtitle cron
subtitleCronJob = startSubtitleCron(config, self.debug)
self.threads['subtitle'] = subtitleCronJob
self.searchers['subtitleQueue'] = subtitleQueue

etaCron = startEtaCron(config, self.debug)
self.threads['eta'] = etaCron
self.searchers['etaQueue'] = etaQueue

#renamer cron
renamerCronJob = startRenamerCron(config, self.searchers, self.debug)
self.threads['renamer'] = renamerCronJob

#Movie RSS cron
MovieRSSCronJob = startMovieRSSCron(config, self.searchers, self.debug)
self.threads['MovieRSS'] = MovieRSSCronJob

#Kinepolis RSS cron
KinepolisRSSCronJob = startKinepolisRSSCron(config, self.searchers, self.debug)
self.threads['KinepolisRSS'] = KinepolisRSSCronJob

#Trakt cron
TraktCronJob = startTraktCron(config, self.searchers, self.debug)
self.threads['Trakt'] = TraktCronJob

#nzb cronjob
yarrCronJob = startYarrCron(config, self.debug, yarrSearch)
yarrCronJob.sabNzbd = sabNzbd(config)
yarrCronJob.transmission = transmission(config)
yarrCronJob.nzbGet = nzbGet(config)
self.threads['yarr'] = yarrCronJob

#log all errors/tracebacks to logfile
#sys.stderr = LogFile('stderr')

def stop(self):
log.info("Stopping Cronjobs.")
for t in self.threads.itervalues():
if t.quit:
t.quit()
t.join()

start.priority = 70
Binary file added cron/__init__.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions cron/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import threading

class cronBase(threading.Thread):

abort = False
running = False
debug = False

def isRunning(self):
return self.running

def quit(self):
self.abort = True

def canShutdown(self):
return (self.abort and not self.running)
Binary file added cron/base.pyc
Binary file not shown.
104 changes: 104 additions & 0 deletions cron/eta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from app.config.cplog import CPLog
from app.config.db import Movie, MovieETA, Session as Db
from app.lib.cron.base import cronBase
from app.lib.provider.rss import rss
from dateutil.parser import parse
from sqlalchemy.sql.expression import or_
from urllib import urlencode
import Queue
import cherrypy
import time
import json

etaQueue = Queue.Queue()
log = CPLog(__name__)

class etaCron(rss, cronBase):

apiUrl = 'http://couchpotatoapp.com/api/eta/%s/'

def conf(self, option):
return self.config.get('RottenTomatoes', option)

def run(self):
log.info('ETA thread is running.')

timeout = 0.1 if self.debug else 1
while True and not self.abort:

try:
queue = etaQueue.get(timeout = timeout)
if queue.get('id'):
movie = Db.query(Movie).filter_by(id = queue.get('id')).first()
else:
movie = queue.get('movie')

if not cherrypy.config.get('debug'):
#do a search
self.running = True
result = self.search(movie)
if result:
self.save(movie, result)
self.running = False

etaQueue.task_done()
time.sleep(timeout)
except Queue.Empty:
pass

log.info('ETA thread shutting down.')

def all(self):
activeMovies = Db.query(Movie).filter(or_(Movie.status == u'want', Movie.status == u'waiting')).all()
for movie in activeMovies:
etaQueue.put({'movie':movie})

def save(self, movie, result):

row = Db.query(MovieETA).filter_by(movieId = movie.id).first()
if not row:
row = MovieETA()
Db.add(row)

row.movieId = movie.id
row.theater = result.get('theater')
row.dvd = result.get('dvd')
row.bluray = result.get('bluray')
row.lastCheck = result.get('expires')
Db.flush()

def search(self, movie, page = 1):

# Already found it, just update the stuff
if movie.imdb:
log.debug('Updating VideoETA for %s.' % movie.name)
return self.getDetails(movie.imdb)

log.info('No IMDBid available for ETA searching')

def getDetails(self, id):

url = self.apiUrl % id

try:
data = self.urlopen(url).read()
except:
log.error('Failed to open %s.' % url)
return False

try:
dates = json.loads(data)
log.info('Found ETA: %s' % dates)
except:
log.error('Error getting ETA for %s' % id)

return dates


def startEtaCron(config, debug):
c = etaCron()
c.config = config
c.debug = debug
c.start()

return c
Binary file added cron/eta.pyc
Binary file not shown.
Loading

0 comments on commit 16cd36a

Please sign in to comment.