mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Change webserve code to a logical layout and PEP8
This commit is contained in:
parent
d6bcc32fb8
commit
71d7938fac
5 changed files with 2305 additions and 2389 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
* Add requirements file for pip (port from midgetspy/sick-beard)
|
||||
* Remove unused libraries fuzzywuzzy and pysrt
|
||||
* Change webserve code to a logical layout and PEP8
|
||||
|
||||
[develop changelog]
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@
|
|||
import os
|
||||
import string
|
||||
|
||||
from tornado.httputil import HTTPHeaders
|
||||
from tornado.web import RequestHandler
|
||||
from sickbeard import encodingKludge as ek
|
||||
from sickbeard import logger, webserve
|
||||
from sickbeard import logger
|
||||
|
||||
# use the built-in if it's available (python 2.6), if not use the included library
|
||||
try:
|
||||
|
@ -104,15 +102,4 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
|
|||
entries.append({'name': "..", 'path': parentPath})
|
||||
entries.extend(fileList)
|
||||
|
||||
return entries
|
||||
|
||||
|
||||
class WebFileBrowser(webserve.MainHandler):
|
||||
def index(self, path='', includeFiles=False, *args, **kwargs):
|
||||
self.set_header("Content-Type", "application/json")
|
||||
return json.dumps(foldersAtPath(path, True, bool(int(includeFiles))))
|
||||
|
||||
def complete(self, term, includeFiles=0):
|
||||
self.set_header("Content-Type", "application/json")
|
||||
paths = [entry['path'] for entry in foldersAtPath(os.path.dirname(term), includeFiles=bool(int(includeFiles))) if 'path' in entry]
|
||||
return json.dumps(paths)
|
||||
return entries
|
|
@ -166,40 +166,6 @@ class Api(webserve.BaseHandler):
|
|||
return False, msg, args, kwargs
|
||||
|
||||
|
||||
class ApiBuilder(webserve.MainHandler):
|
||||
def index(self):
|
||||
""" expose the api-builder template """
|
||||
t = webserve.PageTemplate(headers=self.request.headers, file="apiBuilder.tmpl")
|
||||
|
||||
def titler(x):
|
||||
return (remove_article(x), x)[not x or sickbeard.SORT_ARTICLE]
|
||||
|
||||
t.sortedShowList = sorted(sickbeard.showList, lambda x, y: cmp(titler(x.name), titler(y.name)))
|
||||
|
||||
seasonSQLResults = {}
|
||||
episodeSQLResults = {}
|
||||
|
||||
myDB = db.DBConnection(row_type="dict")
|
||||
for curShow in t.sortedShowList:
|
||||
seasonSQLResults[curShow.indexerid] = myDB.select(
|
||||
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? ORDER BY season DESC", [curShow.indexerid])
|
||||
|
||||
for curShow in t.sortedShowList:
|
||||
episodeSQLResults[curShow.indexerid] = myDB.select(
|
||||
"SELECT DISTINCT season,episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC",
|
||||
[curShow.indexerid])
|
||||
|
||||
t.seasonSQLResults = seasonSQLResults
|
||||
t.episodeSQLResults = episodeSQLResults
|
||||
|
||||
if len(sickbeard.API_KEY) == 32:
|
||||
t.apikey = sickbeard.API_KEY
|
||||
else:
|
||||
t.apikey = "api key not generated"
|
||||
|
||||
return webserve._munge(t)
|
||||
|
||||
|
||||
def call_dispatcher(handler, args, kwargs):
|
||||
""" calls the appropriate CMD class
|
||||
looks for a cmd in args and kwargs
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,8 @@
|
|||
import os
|
||||
import socket
|
||||
import time
|
||||
import threading
|
||||
import sys
|
||||
import sickbeard
|
||||
import webserve
|
||||
import browser
|
||||
import webapi
|
||||
|
||||
from sickbeard import logger
|
||||
|
@ -90,7 +87,7 @@ class WebServer(threading.Thread):
|
|||
|
||||
# Main Handler
|
||||
self.app.add_handlers('.*$', [
|
||||
(r'%s/api/builder(/?)(.*)' % self.options['web_root'], webapi.ApiBuilder),
|
||||
(r'%s/api/builder(/?)(.*)' % self.options['web_root'], webserve.ApiBuilder),
|
||||
(r'%s/api(/?.*)' % self.options['web_root'], webapi.Api),
|
||||
(r'%s/config/general(/?.*)' % self.options['web_root'], webserve.ConfigGeneral),
|
||||
(r'%s/config/search(/?.*)' % self.options['web_root'], webserve.ConfigSearch),
|
||||
|
@ -109,7 +106,7 @@ class WebServer(threading.Thread):
|
|||
(r'%s/manage/manageSearches(/?.*)' % self.options['web_root'], webserve.ManageSearches),
|
||||
(r'%s/manage/(/?.*)' % self.options['web_root'], webserve.Manage),
|
||||
(r'%s/ui(/?.*)' % self.options['web_root'], webserve.UI),
|
||||
(r'%s/browser(/?.*)' % self.options['web_root'], browser.WebFileBrowser),
|
||||
(r'%s/browser(/?.*)' % self.options['web_root'], webserve.WebFileBrowser),
|
||||
(r'%s(/?.*)' % self.options['web_root'], webserve.MainHandler),
|
||||
])
|
||||
|
||||
|
|
Loading…
Reference in a new issue