Private GIT

Skip to content
Snippets Groups Projects
Commit 91d1af7e authored by Labrys of Knossos's avatar Labrys of Knossos
Browse files

Merge pull request #718 from SickRage/browser

Refactor internal variables
parents c6fd7956 f89a6e3c
Branches
Tags
No related merge requests found
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
# 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 SickRage. If not, see <http://www.gnu.org/licenses/>. # along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import os import os
import string import string
...@@ -43,31 +45,31 @@ def getWinDrives(): ...@@ -43,31 +45,31 @@ def getWinDrives():
def getFileList(path, includeFiles): def getFileList(path, includeFiles):
# prune out directories to protect the user from doing stupid things (already lower case the dir to reduce calls) # 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", hide_list = ['boot', 'bootmgr', 'cache', 'config.msi', 'msocache', 'recovery', '$recycle.bin',
"recycler", "system volume information", "temporary internet files"] # windows specific 'recycler', 'system volume information', 'temporary internet files'] # windows specific
hideList += [".fseventd", ".spotlight", ".trashes", ".vol", "cachedmessages", "caches", "trash"] # osx specific hide_list += ['.fseventd', '.spotlight', '.trashes', '.vol', 'cachedmessages', 'caches', 'trash'] # osx specific
hideList += [".git"] hide_list += ['.git']
fileList = [] file_list = []
for filename in ek(os.listdir, path): for filename in ek(os.listdir, path):
if filename.lower() in hideList: if filename.lower() in hide_list:
continue continue
fullFilename = ek(os.path.join, path, filename) full_filename = ek(os.path.join, path, filename)
isDir = ek(os.path.isdir, fullFilename) is_dir = ek(os.path.isdir, full_filename)
if not includeFiles and not isDir: if not includeFiles and not is_dir:
continue continue
entry = { entry = {
'name': filename, 'name': filename,
'path': fullFilename 'path': full_filename
} }
if not isDir: if not is_dir:
entry['isFile'] = True entry['isFile'] = True
fileList.append(entry) file_list.append(entry)
return fileList return file_list
def foldersAtPath(path, includeParent=False, includeFiles=False): def foldersAtPath(path, includeParent=False, includeFiles=False):
...@@ -88,36 +90,36 @@ def foldersAtPath(path, includeParent=False, includeFiles=False): ...@@ -88,36 +90,36 @@ def foldersAtPath(path, includeParent=False, includeFiles=False):
else: else:
path = ek(os.path.dirname, path) path = ek(os.path.dirname, path)
if path == "": if path == '':
if os.name == 'nt': if os.name == 'nt':
entries = [{'currentPath': 'Root'}] entries = [{'currentPath': 'Root'}]
for letter in getWinDrives(): for letter in getWinDrives():
letterPath = letter + ':\\' letter_path = letter + ':\\'
entries.append({'name': letterPath, 'path': letterPath}) entries.append({'name': letter_path, 'path': letter_path})
return entries return entries
else: else:
path = '/' path = '/'
# fix up the path and find the parent # fix up the path and find the parent
path = ek(os.path.abspath, ek(os.path.normpath, path)) 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 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 == parent_path and os.name == 'nt':
parentPath = "" parent_path = ''
try: try:
fileList = getFileList(path, includeFiles) file_list = getFileList(path, includeFiles)
except OSError as e: except OSError as e:
logger.log(u"Unable to open " + path + ": " + repr(e) + " / " + str(e), logger.WARNING) logger.log('Unable to open %s: %s / %s' % (path, repr(e), str(e)), logger.WARNING)
fileList = getFileList(parentPath, includeFiles) file_list = getFileList(parent_path, includeFiles)
fileList = sorted(fileList, file_list = sorted(file_list,
lambda x, y: cmp(ek(os.path.basename, x['name']).lower(), ek(os.path.basename, y['path']).lower())) lambda x, y: cmp(ek(os.path.basename, x['name']).lower(), ek(os.path.basename, y['path']).lower()))
entries = [{'currentPath': path}] entries = [{'currentPath': path}]
if includeParent and parentPath != path: if includeParent and parent_path != path:
entries.append({'name': "..", 'path': parentPath}) entries.append({'name': '..', 'path': parent_path})
entries.extend(fileList) entries.extend(file_list)
return entries return entries
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment