Skip to content

Commit

Permalink
Merge branch 'current_dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dlesk committed Dec 25, 2011
2 parents 865cb24 + da8bf46 commit edb579c
Show file tree
Hide file tree
Showing 18 changed files with 477 additions and 21 deletions.
10 changes: 4 additions & 6 deletions Gamez.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ server.socket_host = "127.0.0.1"
server.socket_port = 8085

[NZBMatrix]
username =
api_key =
username = ""
api_key = ""

[Sabnzbd]
api_key =
api_key = ""
host = "127.0.0.1"
port = 8080
password = ""

[Scheduler]
download_interval = 60

[SystemGenerated]
is_to_ignore_update = 0
ignored_version =
ignored_version = ""

16 changes: 15 additions & 1 deletion Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import cherrypy.process.plugins
from cherrypy.process.plugins import Daemonizer
from lib.ConfigFunctions import CheckConfigForAllKeys
from lib.DBFunctions import ValidateDB
from lib.Logger import LogEvent

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)
css_path = os.path.join(app_path,'css')
images_path = os.path.join(app_path,'images')
Expand All @@ -38,20 +41,27 @@ def RunWebServer(self,isToDaemonize):
}
daemon = Daemonizer(cherrypy.engine)

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

LogEvent("Generating Post Process Script")
GenerateSabPostProcessScript()
RunGameTask()

LogEvent("Getting download interval from config file and invoking scheduler")
config = ConfigParser.RawConfigParser()
config.read('Gamez.ini')
interval = config.get('Scheduler','download_interval').replace('"','')
fInterval = float(interval)
workerTask = cherrypy.process.plugins.BackgroundTask(fInterval,RunGameTask)
try:
workerTask.start()

LogEvent("Starting the Gamez web server")
cherrypy.quickstart(WebRoot(app_path),'/',config=conf)
except KeyboardInterrupt:
LogEvent("Shutting down Gamez")
workerTask.cancel()
if(isToDaemonize == 1):
daemon.unsubscribe()
Expand Down Expand Up @@ -103,12 +113,16 @@ def RunGameTask():
sabnzbdHost = config.get('Sabnzbd','host').replace('"','')
sabnzbdPort = config.get('Sabnzbd','port').replace('"','')
sabnzbdApi = config.get('Sabnzbd','api_key').replace('"','')
LogEvent("Searching for games")
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort)
except:
print(sys.exc_info()[0])

if __name__ == '__main__':
LogEvent("Checking config file for completeness")
CheckConfigForAllKeys(app_path)
LogEvent("Checking to make sure all tables exist in the database")
ValidateDB()
isToDaemonize = 0
params = sys.argv
for param in params:
Expand Down
35 changes: 34 additions & 1 deletion css/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,37 @@ div#menu li.back .left {
background-color: khaki;
color: Maroon;
border: solid 1px silver;
}
}


.clear-log-button {
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
background: -ms-linear-gradient(top, #3e779d, #65a9d7);
background: -o-linear-gradient(top, #3e779d, #65a9d7);
padding: 5px 10px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: white;
font-size: 14px;
font-family: Georgia, serif;
text-decoration: none;
vertical-align: middle;
}
.clear-log-button:hover {
border-top-color: #28597a;
background: #28597a;
color: #ccc;
}
.clear-log-button:active {
border-top-color: #1b435e;
background: #1b435e;
}
54 changes: 54 additions & 0 deletions css/settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
body{
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
p, h1, form, button{border:0; margin:0; padding:0;}
.spacer{clear:both; height:1px;}
/* ----------- My Form ----------- */
.myform{
margin:0 auto;
width:600px;
padding:14px;
}

/* ----------- stylized ----------- */
#stylized{
border:solid 2px #b7ddf2;
background:#ebf4fb;
}
#stylized h1 {
font-size:14px;
font-weight:bold;
margin-bottom:10px;
}
#stylized label{
display:block;
font-weight:bold;
text-align:right;
width:240px;
float:left;
margin-top:5px;
}
#stylized input{
float:left;
font-size:12px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:300px;
margin:2px 0 20px 10px;
}
#stylized button{
clear:both;
margin-left:250px;
width:125px;
height:31px;
background:#666666 url(img/button.png) no-repeat;
text-align:center;
line-height:31px;
color:#FFFFFF;
font-size:11px;
font-weight:bold;
}



4 changes: 0 additions & 4 deletions lib/ConfigFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def CheckConfigForAllKeys(app_path):
config.set('Sabnzbd','host','"127.0.0.1"')
changesMade = True

if(config.has_option('Sabnzbd','password') == False):
config.set('Sabnzbd','password','""')
changesMade = True

if(config.has_option('Scheduler','download_interval') == False):
config.set('Scheduler','download_interval','60')
changesMade = True
Expand Down
Binary file modified lib/ConfigFunctions.pyc
Binary file not shown.
Binary file modified lib/Constants.pyc
Binary file not shown.
80 changes: 79 additions & 1 deletion lib/DBFunctions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sqlite3
import sys
import datetime
from Logger import LogEvent

def GetAllWiiGames():
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
Expand Down Expand Up @@ -94,6 +96,7 @@ def GetWiiGameDataFromTerm(term):
return data

def AddWiiGameToDb(db_id,status):
LogEvent("Adding game in 'Wanted' status")
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "insert into requested_games(WiiGameID,status) select '" + db_id + "','" + status + "' where not exists(select 1 from requested_games where WiiGameID='" + db_id + "')"
connection = sqlite3.connect(db_path)
Expand All @@ -117,14 +120,22 @@ def GetRequestedGames():
game_name = str(record[1])
game_id = str(record[2])
status = str(record[3])
rowdata = "<tr><td><a href='removegame?dbid=" + db_id + "'>Delete</a></td><td>" + game_name + "</td><td>" + game_id + "</td><td>" + status + "</td></tr>"
rowdata = "<tr><td><a href='removegame?dbid=" + db_id + "'>Delete</a></td><td>" + game_name + "</td><td>" + game_id + "</td><td>" + status + "</td><td><select id=updateSatusSelectObject class=ui-widget onchange=UpdateGameStatus(this.options[this.selectedIndex].value,'" + db_id + "')>"
if(status == "Snatched"):
rowdata = rowdata + "<option>Downloaded</option><option selected=true>Snatched</option><option>Wanted</option>"
elif(status == "Downloaded"):
rowdata = rowdata + "<option selected=true>Downloaded</option><option>Snatched</option><option>Wanted</option>"
elif(status == "Wanted"):
rowdata = rowdata + "<option>Downloaded</option><option>Snatched</option><option selected=true>Wanted</option>"
rowdata = rowdata + "</select></td></tr>"
data = data + rowdata
except:
continue
cursor.close()
return data

def RemoveWiiGameFromDb(db_id):
LogEvent("Removing game")
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "delete from requested_games where WiiGameID='" + db_id + "'"
connection = sqlite3.connect(db_path)
Expand All @@ -145,11 +156,78 @@ def GetRequestedGamesAsArray():
return result

def UpdateStatus(game_id,status):
LogEvent("Update status of game to " + status)
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "update requested_games set status='" + status + "' where WiiGameID='" + game_id + "'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()
return

def ValidateDB():
LogEvent("Checking to make sure database has the correct tables")
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "select name from sqlite_master where type='table'"
logTableExists = False
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
tables = list()
for record in result:
tableName = str(record[0])
if(tableName == 'gamez_log'):
logTableExists = True
cursor.close()
if(logTableExists == False):
LogEvent("Creating table 'gamez_log'")
sql = "create table gamez_log(ID INTEGER NOT NULL PRIMARY KEY UNIQUE,message TEXT(255) NOT NULL,created_date DATE)"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()
return

def AddEventToDB(message):
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
createdDate = datetime.datetime.now()
sql = "INSERT INTO gamez_log (message,created_date) values('" + message + "',datetime())"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()
return

def GetLog():
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT message,created_date FROM gamez_log order by created_date desc"
data = ''
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
for record in result:
try:
message = str(record[0])
created_date = str(record[1])
rowdata = "<tr><td>" + message + "</td><td>" + created_date + "</td></tr>"
data = data + rowdata
except:
continue
cursor.close()
return data

def ClearDBLog():
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
createdDate = datetime.datetime.now()
sql = "delete from gamez_log"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()
return
Binary file modified lib/DBFunctions.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions lib/GameTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import stat
from subprocess import call
from Logger import LogEvent

class GameTasks():

Expand All @@ -18,6 +19,7 @@ def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnz
try:
game_name = str(game[0])
game_id = str(game[1])
LogEvent("Searching for game: " + game_name)
nzbmatrixResult = GameTasks().FindGameOnNZBMatrix(game_name,game_id,nzbmatrixusername,nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort)
except:
error = sys.exc_info()[0]
Expand All @@ -37,6 +39,7 @@ def FindGameOnNZBMatrix(self,game_name,game_id,username,api,sabnzbdApi,sabnzbdHo
nzbID = nzbID.replace(";","")

if(nzbID <> "nothing_found"):
LogEvent("Game found on NZB Matrix")
GameTasks().AddNZBToSab(nzbID,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id)
UpdateStatus(game_id,"Snatched")
return
Expand All @@ -47,6 +50,7 @@ def AddNZBToSab(self,nzbID,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id)
responseObject = urllib.FancyURLopener({}).open(url)
responseObject.read()
responseObject.close()
LogEvent("NZB added to Sabnzbd")
return

def CheckIfPostProcessExistsInSab(self,sabnzbdApi,sabnzbdHost,sabnzbdPort):
Expand All @@ -61,10 +65,12 @@ def CheckIfPostProcessExistsInSab(self,sabnzbdApi,sabnzbdHost,sabnzbdPort):
destPath = os.path.join(scriptDir,"gamezPostProcess.py")

try:
LogEvent("Copying post process script to Sabnzbd scripts folder")
shutil.copyfile(srcPath,destPath)
except:
print 'Error Copying File'
try:
LogEvent("Setting permissions on post process script")
cmd = "chmod +x '" + destPath + "'"
os.system(cmd)
except:
Expand Down
Binary file modified lib/GameTasks.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions lib/Logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import DBFunctions

def LogEvent(message):
DBFunctions.AddEventToDB(message)
return

def ClearLog():
ClearDBLog()
return
Binary file added lib/Logger.pyc
Binary file not shown.
Loading

0 comments on commit edb579c

Please sign in to comment.