X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/3febddec12dfe05fea5f388274a991f8faecab48..39d32bba6ecbc88f6d6865e8467d750ba6f20c20:/lib/python/Tools/Directories.py diff --git a/lib/python/Tools/Directories.py b/lib/python/Tools/Directories.py index 8a35f1da..b2e43a49 100644 --- a/lib/python/Tools/Directories.py +++ b/lib/python/Tools/Directories.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from os import path as os_path, mkdir, rmdir, system, walk, stat as os_stat, listdir, readlink, makedirs, error as os_error, symlink +from os import path as os_path, mkdir, rmdir, system, walk, stat as os_stat, listdir, readlink, makedirs, error as os_error, symlink, access, F_OK, R_OK, W_OK from stat import S_IMODE from re import compile @@ -126,6 +126,9 @@ def resolveFilename(scope, base = "", path_prefix = None): def pathExists(path): return os_path.exists(path) +def isMount(path): + return os_path.ismount(path) + def createDir(path, makeParents = False): try: if makeParents: @@ -148,13 +151,13 @@ def removeDir(path): return ret def fileExists(f, mode='r'): - try: - file = open(f, mode) - except IOError: - exists = 0 + if mode == 'r': + acc_mode = R_OK + elif mode == 'w': + acc_mode = W_OK else: - exists = 1 - return exists + acc_mode = F_OK + return access(f, acc_mode) def getRecordingFilename(basename, dirname = None): # filter out non-allowed characters @@ -164,12 +167,12 @@ def getRecordingFilename(basename, dirname = None): basename = basename.replace('\xc2\x86', '').replace('\xc2\x87', '') for c in basename: - if c in non_allowed_characters: + if c in non_allowed_characters or ord(c) < 32: c = "_" filename += c if dirname is not None: - filename = ''.join([dirname, filename]) + filename = ''.join((dirname, filename)) i = 0 while True: