def testCambioWD(self): """ Testeo del cambio del working directory. :return: void :rtype: None """ if VERBOSE: print_bars_console("Testeo del wd") print "Wd actual: ", self.fm.get_working_directory() b = self.fm.get_working_directory() if is_windows(): self.fm.set_working_directory("C:/") if VERBOSE: print "Wd actual: ", self.fm.get_working_directory() assert self.fm.get_working_directory() == "C:/", FILEMANAGER_ERROR_WD self.fm.restore_wd() if VERBOSE: print "Wd actual: ", self.fm.get_working_directory() assert self.fm.get_working_directory() == b, FILEMANAGER_ERROR_RESTORE_WD self.fm.set_working_directory(DIR_DATA_TEST) if VERBOSE: print "Wd actual: ", self.fm.get_working_directory() assert self.fm.get_working_directory() == DIR_DATA_TEST, FILEMANAGER_ERROR_WD del b
def testOS(self): """ Testea el sistema operativo :return: """ if os.name == "nt": # Se comprueba que el sistema sea Windows si es que os.name es NT assert is_windows() is True, ERROR_GETTING_OS
def _inspect(rootpath, filename, filelist, extracted_folders, depth): """ Inspecciona todos los archivos de un paquete. :param rootpath: Carpeta contenedora :type rootpath: str :param filename: Nombre del archivo a analizar :type filename: str, unicode :param filelist: Lista de archivos actuales a agregar :type filelist: list :param extracted_folders: Lista de carpetas extraídas durante el proceso :type extracted_folders: list :param depth: Profundidad de búsqueda :type depth: int :return: void :rtype: None """ if not is_valid_file(filename): # Si el archivo no es válido return if self._is_folder(rootpath, filename) and is_valid_folder_name(filename): # Si el archivo es una carpeta path_to_inspect = rootpath + filename for filef in os.listdir(path_to_inspect.decode(self._fileEncoding)): _inspect(rootpath + filename + "/", filef, filelist, extracted_folders, depth + 1) elif self._is_zip(rootpath, filename) and self._autoExtract: # Si el archivo es paquete zip newfilename = filename.replace(".zip", "").replace(".ZIP", "") file_already_exists = False do_extract = True try: file_already_exists = newfilename in os.listdir(rootpath.decode(self._fileEncoding)) except: pass if file_already_exists: do_extract = do_extract and self._extractIfFolderAlreadyExists if self._verbose: if do_extract: print _FILEMANAGER_Y_EXTRACT_COMPRSD_FILE.format(newfilename) else: print _FILEMANAGER_NO_EXTRACT_COMPRSD_FILE.format(newfilename) if do_extract: zipfile.ZipFile(rootpath + filename).extractall(rootpath + newfilename + "/") if self._removeOnExtract: os.remove(rootpath + filename) extracted_folders.append(rootpath + newfilename + "/") if is_valid_folder_name(newfilename): _inspect(rootpath, newfilename, filelist, extracted_folders, depth + 1) elif self._is_rar(rootpath, filename) and self._autoExtract: # Si el archivo es paquete rar newfilename = filename.replace(".rar", "").replace(".RAR", "") file_already_exists = False do_extract = True try: file_already_exists = newfilename in os.listdir(rootpath.decode(self._fileEncoding)) except: pass if file_already_exists: do_extract = do_extract and self._extractIfFolderAlreadyExists if self._verbose: if do_extract: print _FILEMANAGER_Y_EXTRACT_COMPRSD_FILE.format(newfilename) else: print _FILEMANAGER_NO_EXTRACT_COMPRSD_FILE.format(newfilename) if do_extract: # Si el sistema operativo huésped es Windows if is_windows(): try: # noinspection PyArgumentEqualDefault rarfile.RarFile(rootpath + filename, 'r', 'utf8').extractall(rootpath + newfilename + "/") except Exception, ex: print "" err.st_error(err.ERROR_RARUNCOMPRESS, True, "rarfile", ex) # Para sistemas basados en POSIX - OSX else: # Para linux y con Archive/pyunpack # try: # os.mkdir(rootpath + newfilename + "/") # except: # pass try: # noinspection PyArgumentEqualDefault rarfile.RarFile(rootpath + filename, 'r', 'utf8').extractall(rootpath + newfilename + "/") # Archive(rootpath + filename).extractall(rootpath + newfilename + "/") # Para linux con Archive/pyunpack except Exception, ex: print "" # err.st_error(err.ERROR_RARUNCOMPRESS, True, "pyunpack", e) # Para linux con Archive/pyunpack err.st_error(err.ERROR_RARUNCOMPRESS_LINUX, True, "rarfile", ex) if self._removeOnExtract: os.remove(rootpath + filename) extracted_folders.append(rootpath + newfilename + "/") if is_valid_folder_name(newfilename): _inspect(rootpath, newfilename, filelist, extracted_folders, depth + 1)
# Importación de librerías if __name__ == '__main__': # noinspection PyUnresolvedReferences from libpath import * # @UnusedWildImport import os # @Reimport import shutil # @UnusedImport import zipfile from bin.configloader import ConfigLoader # @UnresolvedImport import bin.errors as err # @UnresolvedImport @UnusedImport from bin.ostype import is_windows from bin.utils import is_hidden_file_utils, is_folder_utils, append_list_to_list from bin.vartype import VarTypedClass from config import DIR_CONFIG # @UnresolvedImport from data import DIR_UPLOADS # @UnusedImport if is_windows(): # Se define el ejecutable de unrar para Windows from bin.binpath import DIR_BIN try: import bin.rarfile as rarfile # @UnresolvedImport except Exception, e: err.st_error(err.ERROR_RARNOTINSTALLED_WIN, True, "rarfile", e) rarfile.UNRAR_TOOL = DIR_BIN + "unrar.exe" else: # Si no es windows se utiliza la librería patool import bin.rarfile as rarfile # @UnresolvedImport @Reimport # try: # from pyunpack import Archive # @UnusedImport @UnresolvedImport # except Exception, e: # err.st_error(err.ERROR_RARNOTINSTALLED_NOTWIN, True, "pyunpack", e) # Constantes