Merge pull request #248 from adam111316/feature/PEP8_browser

Change browser, bs4 parser and classes code to PEP8 standards
This commit is contained in:
adam111316 2015-03-01 10:40:18 +08:00
commit 3844e6bf0f
4 changed files with 39 additions and 35 deletions

View file

@ -21,6 +21,7 @@
* Fix Episode Status Management error popup from coming up when show is selected without expanding * Fix Episode Status Management error popup from coming up when show is selected without expanding
* Add BET network logo * Add BET network logo
* Remove unused force variable from code and PEP8 * Remove unused force variable from code and PEP8
* Change browser, bs4 parser and classes code to PEP8 standards
[develop changelog] [develop changelog]
* Fix traceback error when using the menu item Manage/Update Kodi * Fix traceback error when using the menu item Manage/Update Kodi

View file

@ -11,7 +11,7 @@
# SickGear is distributed in the hope that it will be useful, # SickGear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with SickGear. If not, see <http://www.gnu.org/licenses/>. # along with SickGear. If not, see <http://www.gnu.org/licenses/>.
@ -22,6 +22,7 @@ import string
from sickbeard import encodingKludge as ek from sickbeard import encodingKludge as ek
from sickbeard import logger 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:
import json import json
@ -32,6 +33,7 @@ except ImportError:
if os.name == 'nt': if os.name == 'nt':
from ctypes import windll from ctypes import windll
# adapted from http://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python/827490 # adapted from http://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python/827490
def getWinDrives(): def getWinDrives():
""" Return list of detected drives """ """ Return list of detected drives """
@ -61,11 +63,11 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
else: else:
path = os.path.dirname(path) path = os.path.dirname(path)
if path == "": if path == '':
if os.name == 'nt': if os.name == 'nt':
entries = [{'current_path': 'Root'}] entries = [{'current_path': 'Root'}]
for letter in getWinDrives(): for letter in getWinDrives():
letterPath = letter + ':\\' letterPath = '%s:\\' % letter
entries.append({'name': letterPath, 'path': letterPath}) entries.append({'name': letterPath, 'path': letterPath})
return entries return entries
else: else:
@ -77,21 +79,23 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
# if we're at the root then the next step is the meta-node showing our drive letters # if we're at the root then the next step is the meta-node showing our drive letters
if path == parentPath and os.name == 'nt': if path == parentPath and os.name == 'nt':
parentPath = "" parentPath = ''
try: try:
fileList = [{'name': filename, 'path': ek.ek(os.path.join, path, filename)} for filename in ek.ek(os.listdir, path)] fileList = [{'name': filename, 'path': ek.ek(os.path.join, path, filename)} for filename in
ek.ek(os.listdir, path)]
except OSError, e: except OSError, e:
logger.log(u"Unable to open " + path + ": " + repr(e) + " / " + str(e), logger.WARNING) logger.log(u'Unable to open %s: %r / %s' % (path, e, e), logger.WARNING)
fileList = [{'name': filename, 'path': ek.ek(os.path.join, parentPath, filename)} for filename in ek.ek(os.listdir, parentPath)] fileList = [{'name': filename, 'path': ek.ek(os.path.join, parentPath, filename)} for filename in
ek.ek(os.listdir, parentPath)]
if not includeFiles: if not includeFiles:
fileList = filter(lambda entry: ek.ek(os.path.isdir, entry['path']), fileList) fileList = filter(lambda entry: ek.ek(os.path.isdir, entry['path']), fileList)
# prune out directories to proect the user from doing stupid things (already lower case the dir to reduce calls) # prune out directories to proect the user from doing stupid things (already lower case the dir to reduce calls)
hideList = ["boot", "bootmgr", "cache", "msocache", "recovery", "$recycle.bin", "recycler", hideList = ['boot', 'bootmgr', 'cache', 'msocache', 'recovery', '$recycle.bin', 'recycler',
"system volume information", "temporary internet files"] # windows specific 'system volume information', 'temporary internet files'] # windows specific
hideList += [".fseventd", ".spotlight", ".trashes", ".vol", "cachedmessages", "caches", "trash"] # osx specific hideList += ['.fseventd', '.spotlight', '.trashes', '.vol', 'cachedmessages', 'caches', 'trash'] # osx specific
fileList = filter(lambda entry: entry['name'].lower() not in hideList, fileList) fileList = filter(lambda entry: entry['name'].lower() not in hideList, fileList)
fileList = sorted(fileList, fileList = sorted(fileList,
@ -99,7 +103,7 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
entries = [{'current_path': path}] entries = [{'current_path': path}]
if includeParent and parentPath != path: if includeParent and parentPath != path:
entries.append({'name': "..", 'path': parentPath}) entries.append({'name': '..', 'path': parentPath})
entries.extend(fileList) entries.extend(fileList)
return entries return entries

View file

@ -1,6 +1,6 @@
import sickbeard
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
class BS4Parser: class BS4Parser:
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.soup = BeautifulSoup(*args, **kwargs) self.soup = BeautifulSoup(*args, **kwargs)

View file

@ -17,8 +17,8 @@
# along with SickGear. If not, see <http://www.gnu.org/licenses/>. # along with SickGear. If not, see <http://www.gnu.org/licenses/>.
import re import re
import datetime import datetime
import sickbeard
import sickbeard
from lib.dateutil import parser from lib.dateutil import parser
from sickbeard.common import Quality from sickbeard.common import Quality
@ -35,7 +35,7 @@ class SearchResult:
self.show = None self.show = None
# URL to the NZB/torrent file # URL to the NZB/torrent file
self.url = "" self.url = ''
# used by some providers to store extra info associated with the result # used by some providers to store extra info associated with the result
self.extraInfo = [] self.extraInfo = []
@ -47,58 +47,57 @@ class SearchResult:
self.quality = Quality.UNKNOWN self.quality = Quality.UNKNOWN
# release name # release name
self.name = "" self.name = ''
# size of the release (-1 = n/a) # size of the release (-1 = n/a)
self.size = -1 self.size = -1
# release group # release group
self.release_group = "" self.release_group = ''
# version # version
self.version = -1 self.version = -1
def __str__(self): def __str__(self):
if self.provider == None: if self.provider is None:
return "Invalid provider, unable to print self" return 'Invalid provider, unable to print self'
myString = self.provider.name + " @ " + self.url + "\n" myString = '%s @ %s\n' % (self.provider.name, self.url)
myString += "Extra Info:\n" myString += 'Extra Info:\n'
for extra in self.extraInfo: for extra in self.extraInfo:
myString += " " + extra + "\n" myString += ' %s\n' % extra
myString += 'Episode: %s\n' % self.episodes
myString += "Episode: " + str(self.episodes) + "\n" myString += 'Quality: %s\n' % Quality.qualityStrings[self.quality]
myString += "Quality: " + Quality.qualityStrings[self.quality] + "\n" myString += 'Name: %s\n' % self.name
myString += "Name: " + self.name + "\n" myString += 'Size: %s\n' % str(self.size)
myString += "Size: " + str(self.size) + "\n" myString += 'Release Group: %s\n' % self.release_group
myString += "Release Group: " + str(self.release_group) + "\n"
return myString return myString
def fileName(self): def fileName(self):
return self.episodes[0].prettyName() + "." + self.resultType return self.episodes[0].prettyName() + '.' + self.resultType
class NZBSearchResult(SearchResult): class NZBSearchResult(SearchResult):
""" """
Regular NZB result with an URL to the NZB Regular NZB result with an URL to the NZB
""" """
resultType = "nzb" resultType = 'nzb'
class NZBDataSearchResult(SearchResult): class NZBDataSearchResult(SearchResult):
""" """
NZB result where the actual NZB XML data is stored in the extraInfo NZB result where the actual NZB XML data is stored in the extraInfo
""" """
resultType = "nzbdata" resultType = 'nzbdata'
class TorrentSearchResult(SearchResult): class TorrentSearchResult(SearchResult):
""" """
Torrent result with an URL to the torrent Torrent result with an URL to the torrent
""" """
resultType = "torrent" resultType = 'torrent'
# torrent hash # torrent hash
content = None content = None
@ -138,9 +137,9 @@ class AllShowsListUI:
if searchterm.lower() in name.lower(): if searchterm.lower() in name.lower():
if 'firstaired' not in curShow: if 'firstaired' not in curShow:
curShow['firstaired'] = str(datetime.date.fromordinal(1)) curShow['firstaired'] = str(datetime.date.fromordinal(1))
curShow['firstaired'] = re.sub("([-]0{2}){1,}", "", curShow['firstaired']) curShow['firstaired'] = re.sub('([-]0{2}){1,}', '', curShow['firstaired'])
fixDate = parser.parse(curShow['firstaired'], fuzzy=True).date() fixDate = parser.parse(curShow['firstaired'], fuzzy=True).date()
curShow['firstaired'] = fixDate.strftime("%Y-%m-%d") curShow['firstaired'] = fixDate.strftime('%Y-%m-%d')
if curShow not in searchResults: if curShow not in searchResults:
searchResults += [curShow] searchResults += [curShow]
@ -191,8 +190,8 @@ class Proper:
self.scene_episode = -1 self.scene_episode = -1
def __str__(self): def __str__(self):
return str(self.date) + " " + self.name + " " + str(self.season) + "x" + str(self.episode) + " of " + str( return str(self.date) + ' ' + self.name + ' ' + str(self.season) + 'x' + str(self.episode) + ' of ' + str(
self.indexerid) + " from " + str(sickbeard.indexerApi(self.indexer).name) self.indexerid) + ' from ' + str(sickbeard.indexerApi(self.indexer).name)
class ErrorViewer(): class ErrorViewer():