def removeCustomModule(self, moduleName): try: customCfg = self._customModulesFile content = fileUtils.getFileContent(customCfg) lines = content.splitlines() startIdx = -1 cfgUrl = '' for i in range(0, len(lines)): if lines[i].startswith("title=%s" % moduleName): startIdx = i elif startIdx > -1 and lines[i].startswith("url="): tmp = lines[i][4:] cfgUrl = os.path.join(self._customModulesFolder, tmp) break if os.path.isfile(cfgUrl): os.remove(cfgUrl) os.remove(cfgUrl.replace(".cfg", ".module")) # remove all folder that start with cfg name and a dot baseDir = os.path.dirname(cfgUrl) prefix = os.path.basename(cfgUrl).replace(".cfg", ".") dirs = fileUtils.get_immediate_subdirectories(baseDir) for d in dirs: if d.startswith(prefix): fileUtils.clearDirectory(os.path.join(baseDir, d)) os.removedirs(os.path.join(baseDir, d)) return True except: pass return False
def clearCache(self): cacheDir = common.Paths.cacheDir if not os.path.exists(cacheDir): os.mkdir(cacheDir, 0777) common.log('Cache directory created' + str(cacheDir)) else: fu.clearDirectory(cacheDir) common.log('Cache directory purged')
def clearCache(): cacheDir = Paths.cacheDir if not os.path.exists(cacheDir): os.mkdir(cacheDir, 0777) print('Cache directory created' + str(cacheDir)) else: fu.clearDirectory(cacheDir) print('Cache directory purged')
def clearCache(self): cacheDir = common.Paths.cacheDir if not os.path.exists(cacheDir): os.mkdir(cacheDir, 0777) common.log('Cache directory created' + str(cacheDir)) else: size, within_limit = fu.checkQuota(cacheDir) if not within_limit: fu.clearDirectory(cacheDir) common.log('Cache directory purged') common.log('Cache Usage:' + str(size))
def extract(self, fileOrPath, directory): try: if not directory.endswith(':') and not os.path.exists(directory): os.mkdir(directory) zf = zipfile.ZipFile(fileOrPath) for _, name in enumerate(zf.namelist()): if name.endswith('/'): path = os.path.join(directory, name) if os.path.exists(path): clearDirectory(path) else: os.makedirs(path, 0777) else: outfile = open(os.path.join(directory, name), 'wb') outfile.write(zf.read(name)) outfile.flush() outfile.close() return zf.filelist except: print_exc() return None