def rmdirtree(path): """ Elimina un directorio y su contenido @param path: ruta a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if path.lower().startswith("smb://"): for raiz, subcarpetas, ficheros in samba.walk(path, topdown=False): for f in ficheros: samba.remove(join(decode(raiz), decode(f))) for s in subcarpetas: samba.rmdir(join(decode(raiz), decode(s))) samba.rmdir(path) else: import shutil shutil.rmtree(path, ignore_errors=True) except: logger.error("ERROR al eliminar el directorio: %s" % path) logger.error(traceback.format_exc()) platformtools.dialog_notification("Error al eliminar el directorio", path) return False else: return not exists(path)
def remove(path, silent=False, vfs=True): """ Elimina un archivo @param path: ruta del fichero a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if xbmc_vfs and vfs: return bool(xbmcvfs.delete(path)) elif path.lower().startswith("smb://"): samba.remove(path) else: os.remove(path) except: logger.error("ERROR al eliminar el archivo: %s" % path) if not silent: logger.error(traceback.format_exc()) platformtools.dialog_notification("Error al eliminar el archivo", path) return False else: return True
def rmdirtree(path): """ Elimina un directorio y su contenido @param path: ruta a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if path.lower().startswith("smb://"): for raiz, subcarpetas, ficheros in samba.walk(path, topdown=False): for f in ficheros: samba.remove(join(decode(raiz),decode(f))) for s in subcarpetas: samba.rmdir(join(decode(raiz),decode(s))) samba.rmdir(path) else: import shutil shutil.rmtree(path, ignore_errors=True) except: logger.error("ERROR al eliminar el directorio: %s" %(path)) logger.error(traceback.format_exc()) platformtools.dialog_notification("Error al eliminar el directorio", path) return False else: return not exists(path)
def remove(path, silent=False, vfs=True, su=False): """ Elimina un archivo, con alternativa de usar SU @param path: ruta del fichero a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if xbmc_vfs and vfs: result = bool(xbmcvfs.delete(path)) # Si el borrado no ha funcionado y se especificado su=True, se intenta el comando RM vía SU del sistema from platformcode import config if not result and su and config.is_rooted(silent=True) == 'rooted': error_cmd = True for subcmd in ['-c', '-0']: for cmdtype in [['rm', path], ['rm %s' % path]]: command = ['su', subcmd] + cmdtype output_cmd, error_cmd = config.su_command( command, silent=silent) if not error_cmd: break if not error_cmd: result = True break else: logger.error('Sin PERMISOS ROOT: %s' % str(command)) result = False return result elif path.lower().startswith("smb://"): samba.remove(path) else: os.remove(path) except: logger.error("ERROR al eliminar el archivo: %s" % path) if not silent: logger.error(traceback.format_exc()) return False else: return True
def remove(path): """ Elimina un archivo @param path: ruta del fichero a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if path.lower().startswith("smb://"): samba.remove(path) else: os.remove(path) except: logger.error("ERROR al eliminar el archivo: %s" %(path)) logger.error(traceback.format_exc()) platformtools.dialog_notification("Error al eliminar el archivo", path) return False else: return True
def remove(path): """ Elimina un archivo @param path: ruta del fichero a eliminar @type path: str @rtype: bool @return: devuelve False en caso de error """ path = encode(path) try: if path.lower().startswith("smb://"): samba.remove(path) else: os.remove(path) except: logger.error("ERROR al eliminar el archivo: %s" % path) logger.error(traceback.format_exc()) platformtools.dialog_notification("Errore rimozione file", path) return False else: return True
def rmdirtree(path, silent=False, vfs=True): """ Delete a directory and its contents @param path: path to remove @type path: str @rtype: bool @return: returns False on error """ path = encode(path) try: if xbmc_vfs and vfs: if not exists(path): return True if not path.endswith('/') and not path.endswith('\\'): path = join(path, ' ').rstrip() for raiz, subcarpetas, ficheros in walk(path, topdown=False): for f in ficheros: xbmcvfs.delete(join(raiz, f)) for s in subcarpetas: xbmcvfs.rmdir(join(raiz, s)) xbmcvfs.rmdir(path) elif path.lower().startswith("smb://"): for raiz, subcarpetas, ficheros in samba.walk(path, topdown=False): for f in ficheros: samba.remove(join(decode(raiz), decode(f))) for s in subcarpetas: samba.rmdir(join(decode(raiz), decode(s))) samba.rmdir(path) else: import shutil shutil.rmtree(path, ignore_errors=True) except: logger.error("ERROR deleting directory: %s" % path) if not silent: logger.error(traceback.format_exc()) platformtools.dialog_notification("ERROR deleting directory", path) return False else: return not exists(path)
def remove(path, silent=False, vfs=True): """ Delete a file @param path: path of the file to delete @type path: str @rtype: bool @return: returns False on error """ path = encode(path) try: if xbmc_vfs and vfs: return bool(xbmcvfs.delete(path)) elif path.lower().startswith("smb://"): samba.remove(path) else: os.remove(path) except: logger.error("ERROR deleting file: %s" % path) if not silent: logger.error(traceback.format_exc()) platformtools.dialog_notification("ERROR deleting file", path) return False else: return True