Change webserve code to a logical layout and PEP8

This commit is contained in:
Adam 2015-02-23 10:19:25 +08:00
parent d6bcc32fb8
commit 71d7938fac
5 changed files with 2305 additions and 2389 deletions

View file

@ -2,6 +2,7 @@
* Add requirements file for pip (port from midgetspy/sick-beard) * Add requirements file for pip (port from midgetspy/sick-beard)
* Remove unused libraries fuzzywuzzy and pysrt * Remove unused libraries fuzzywuzzy and pysrt
* Change webserve code to a logical layout and PEP8
[develop changelog] [develop changelog]

View file

@ -19,10 +19,8 @@
import os import os
import string import string
from tornado.httputil import HTTPHeaders
from tornado.web import RequestHandler
from sickbeard import encodingKludge as ek 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 # use the built-in if it's available (python 2.6), if not use the included library
try: try:
@ -105,14 +103,3 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
entries.extend(fileList) entries.extend(fileList)
return entries 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)

View file

@ -166,40 +166,6 @@ class Api(webserve.BaseHandler):
return False, msg, args, kwargs 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): def call_dispatcher(handler, args, kwargs):
""" calls the appropriate CMD class """ calls the appropriate CMD class
looks for a cmd in args and kwargs looks for a cmd in args and kwargs

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,8 @@
import os import os
import socket
import time
import threading import threading
import sys import sys
import sickbeard import sickbeard
import webserve import webserve
import browser
import webapi import webapi
from sickbeard import logger from sickbeard import logger
@ -90,7 +87,7 @@ class WebServer(threading.Thread):
# Main Handler # Main Handler
self.app.add_handlers('.*$', [ 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/api(/?.*)' % self.options['web_root'], webapi.Api),
(r'%s/config/general(/?.*)' % self.options['web_root'], webserve.ConfigGeneral), (r'%s/config/general(/?.*)' % self.options['web_root'], webserve.ConfigGeneral),
(r'%s/config/search(/?.*)' % self.options['web_root'], webserve.ConfigSearch), (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/manageSearches(/?.*)' % self.options['web_root'], webserve.ManageSearches),
(r'%s/manage/(/?.*)' % self.options['web_root'], webserve.Manage), (r'%s/manage/(/?.*)' % self.options['web_root'], webserve.Manage),
(r'%s/ui(/?.*)' % self.options['web_root'], webserve.UI), (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), (r'%s(/?.*)' % self.options['web_root'], webserve.MainHandler),
]) ])