# -*- 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
def pathExists(path):
return os_path.exists(path)
-def createDir(path):
+def isMount(path):
+ return os_path.ismount(path)
+
+def createDir(path, makeParents = False):
try:
- mkdir(path)
+ if makeParents:
+ makedirs(path)
+ else:
+ mkdir(path)
except:
ret = 0
else:
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
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: