From f89a6e3c6319280ac9903ed7bd0e6c4c9df63a56 Mon Sep 17 00:00:00 2001 From: labrys <labrys@users.noreply.github.com> Date: Sun, 10 Jan 2016 16:58:35 -0500 Subject: [PATCH] Refactor internal variables Standardize strings --- sickbeard/browser.py | 56 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/sickbeard/browser.py b/sickbeard/browser.py index e4853f460..12559fe4c 100644 --- a/sickbeard/browser.py +++ b/sickbeard/browser.py @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with SickRage. If not, see <http://www.gnu.org/licenses/>. +from __future__ import unicode_literals + import os import string @@ -43,31 +45,31 @@ def getWinDrives(): def getFileList(path, includeFiles): # prune out directories to protect the user from doing stupid things (already lower case the dir to reduce calls) - hideList = ["boot", "bootmgr", "cache", "config.msi", "msocache", "recovery", "$recycle.bin", - "recycler", "system volume information", "temporary internet files"] # windows specific - hideList += [".fseventd", ".spotlight", ".trashes", ".vol", "cachedmessages", "caches", "trash"] # osx specific - hideList += [".git"] + hide_list = ['boot', 'bootmgr', 'cache', 'config.msi', 'msocache', 'recovery', '$recycle.bin', + 'recycler', 'system volume information', 'temporary internet files'] # windows specific + hide_list += ['.fseventd', '.spotlight', '.trashes', '.vol', 'cachedmessages', 'caches', 'trash'] # osx specific + hide_list += ['.git'] - fileList = [] + file_list = [] for filename in ek(os.listdir, path): - if filename.lower() in hideList: + if filename.lower() in hide_list: continue - fullFilename = ek(os.path.join, path, filename) - isDir = ek(os.path.isdir, fullFilename) + full_filename = ek(os.path.join, path, filename) + is_dir = ek(os.path.isdir, full_filename) - if not includeFiles and not isDir: + if not includeFiles and not is_dir: continue entry = { 'name': filename, - 'path': fullFilename + 'path': full_filename } - if not isDir: + if not is_dir: entry['isFile'] = True - fileList.append(entry) + file_list.append(entry) - return fileList + return file_list def foldersAtPath(path, includeParent=False, includeFiles=False): @@ -88,36 +90,36 @@ def foldersAtPath(path, includeParent=False, includeFiles=False): else: path = ek(os.path.dirname, path) - if path == "": + if path == '': if os.name == 'nt': entries = [{'currentPath': 'Root'}] for letter in getWinDrives(): - letterPath = letter + ':\\' - entries.append({'name': letterPath, 'path': letterPath}) + letter_path = letter + ':\\' + entries.append({'name': letter_path, 'path': letter_path}) return entries else: path = '/' # fix up the path and find the parent path = ek(os.path.abspath, ek(os.path.normpath, path)) - parentPath = ek(os.path.dirname, path) + parent_path = ek(os.path.dirname, path) # 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': - parentPath = "" + if path == parent_path and os.name == 'nt': + parent_path = '' try: - fileList = getFileList(path, includeFiles) + file_list = getFileList(path, includeFiles) except OSError as e: - logger.log(u"Unable to open " + path + ": " + repr(e) + " / " + str(e), logger.WARNING) - fileList = getFileList(parentPath, includeFiles) + logger.log('Unable to open %s: %s / %s' % (path, repr(e), str(e)), logger.WARNING) + file_list = getFileList(parent_path, includeFiles) - fileList = sorted(fileList, - lambda x, y: cmp(ek(os.path.basename, x['name']).lower(), ek(os.path.basename, y['path']).lower())) + file_list = sorted(file_list, + lambda x, y: cmp(ek(os.path.basename, x['name']).lower(), ek(os.path.basename, y['path']).lower())) entries = [{'currentPath': path}] - if includeParent and parentPath != path: - entries.append({'name': "..", 'path': parentPath}) - entries.extend(fileList) + if includeParent and parent_path != path: + entries.append({'name': '..', 'path': parent_path}) + entries.extend(file_list) return entries -- GitLab