Private GIT

Skip to content
Snippets Groups Projects
Commit f89a6e3c authored by labrys's avatar labrys
Browse files

Refactor internal variables

Standardize strings
parent c6fd7956
No related branches found
No related tags found
No related merge requests found
......@@ -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,
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment