def checkPendingImports(self): """Checking Pending Imports""" try: onlyfiles = [f for f in listdir(self.current_import_path) if isfile(join(self.current_import_path, f)) if str( str(f).lower()).endswith("zip") if not str(str(f).lower()).endswith("done.zip")] # SORT FILES BY CREATE DATE onlyfiles.sort(key=lambda fn: os.path.getmtime( os.path.join(self.current_import_path, fn))) if onlyfiles is not None: if len(onlyfiles) <= 0: print " checkPendingImports: No pending zip files to process" return for file in onlyfiles: file_path = join(self.current_import_path, file) file_name = os.path.basename(file_path) file_name_without_ext = os.path.splitext(file_name)[0] try: print " checkPendingImports: Processing file :" + file_path if os.path.isfile(join(self.current_import_path, file_name_without_ext) + "_done.zip"): print join(self.current_import_path, file_name_without_ext) + "_done.zip" + " was found. Deleting it" os.remove(join(self.current_import_path, file_name_without_ext) + "_done.zip") if os.path.exists(join(self.current_import_path, file_name_without_ext)): print join(self.current_import_path, file_name_without_ext) + " was found. Deleting it" shutil.rmtree( join(self.current_import_path, file_name_without_ext)) print "checkPendingImports : Am processing " + file_path folder_path = os.path.normpath( FileUtils.unzipImportFile(file_path)) self.add_records_to_sync(folder_path) # PROCESS DATA try: print "Trying to remove lock file:" + folder_path + ".lock" if os.path.isfile(folder_path + ".lock"): os.remove(folder_path + ".lock") if os.path.isfile(folder_path + ".zip.lock"): os.remove(folder_path + ".zip.lock") except Exception: pass FileUtils.renameFile(file_path, join( self.current_import_path, os.path.splitext(folder_path)[0] + "_done.zip")) print "checkPendingImports: Am done processing " + join(self.current_import_path, os.path.splitext(folder_path)[0] + "_done.zip") except Exception as e_value: # catch *all* exceptions print 'checkPendingImports: File :' + str(file_path) + " was skipped due to error " + str(e_value) new_name = os.path.normpath(join(os.path.dirname( file_path), file_name_without_ext)) + "_failed_as_" + str(e_value).replace(" ", "_") + "_done.zip" FileUtils.renameFile(file_path, new_name) except Exception as e_value: # catch *all* exceptions traceback.print_exc() print 'checkPendingImports:Error in unzipping pending files:' + str(e_value)
def renameInvalidFiles(self): """Rename Invalid Files""" try: onlyfiles = [f for f in listdir(self.current_import_path) if isfile( join(self.current_import_path, f)) if not "done" in str(f).lower() if not str(f).lower().endswith(".lock") if not str(f).lower().endswith(".wip")] if onlyfiles is not None: if len(onlyfiles) <= 0: print " renameInvalidFiles: No invalid files to rename" return for file_rename in onlyfiles: file_path = join(self.current_import_path, file_rename) file_name = os.path.basename(file_path) FileUtils.renameFile(file_path, join(self.current_import_path, os.path.splitext( file_name)[0] + "_failed_as_invalid_file" + "_done" + os.path.splitext(file_name)[1])) except Exception as e_value: # catch *all* exceptions traceback.print_exc() print 'renameInvalidFiles: Error while processing pending files :' + str(e_value)
def appendARFFFilesPerMetadataTypeForDataset(self, directoryForDataset: str, metaTypes: list): classifiers = Properties.classifiersForMLAttributesGeneration.split(',') seperator = os.path.sep for classifier in classifiers: for metadataType in metaTypes: i=1 fileName = directoryForDataset + seperator + classifier + "_" + metadataType + "_candidateAttributesData" + str(i) + '.arff' targetFile = directoryForDataset + seperator + classifier + "_" + metadataType + "_candidateAttributesData" + '0' arffToAppendFrom = fileName while os.path.exists(arffToAppendFrom): MLAttributeManager.addArffFileContentToTargetFile(targetFile, fileName, False) FileUtils.deleteFile(arffToAppendFrom) i += 1 fileName = f'{directoryForDataset}{seperator}{classifier}_{metadataType}_candidateAttributesData{i}.arff' arffToAppendFrom = fileName mainFile = targetFile + '.arff' FileUtils.renameFile(mainFile, directoryForDataset + seperator + classifier + "_" + metadataType + "_candidateAttributesData" + '.arff')
def renameFile(filePath, versionName): projectName = getProjectName() targetFolder = getTargetFolderPath(versionName) fileName = os.path.join("/", projectName + "_v" + versionName + ".apk") ColorPrint.colorPrint("copyTo " + targetFolder + fileName) FileUtils.renameFile(filePath, targetFolder + fileName)