def check_previous_folders(self): curr_dir = os.getcwd() os.chdir(self.config.downloadsDir) found_old_dir = False directories = get_directories_in_dir() dir_dict, dir_key = self.manifest.get_dirname_dict() dir_present = [value[dir_key] for key, value in dir_dict.viewitems()] for directory in directories: # check if is not saved in the CustomManifest if directory not in dir_present: # check if a manifest is present in the directory files = get_files_in_dir(directory) manifest_list = [man for man in files if man.__contains__("manifest")] other_files_list = [others for others in files if not others.__contains__("manifest")] if len(manifest_list) > 0: # there's at least a manifest, so let's try to see if the # directory can be added to the list of dirs by seeing if # one of the files is in the manifest file_found = False for manifest in manifest_list: gdc_man = GDCManifest(os.path.join(directory, manifest)) for uuid, info in gdc_man.get_list_of_files(): filename = info[gdc_man.get_name_header()] filename_no_ext = Compression.get_filename(filename) if filename in other_files_list \ and filename_no_ext in directory: file_found = True uuid_found = uuid meta_found = directory.replace( "_" + filename_no_ext, "") new_info = info new_info[ gdc_man.get_metadata_header()] = meta_found self.manifest.add_dictionary( {uuid_found: new_info}) logging.info("Added dir {0}".format(directory)) break if file_found: found_old_dir = True break os.chdir(curr_dir) if found_old_dir: self.manifest.serialize_manifest()
def get_dir_name(self, uuid): filename = self.content[uuid][self.get_name_header()] filename = Compression.get_filename(filename) metadata = self.content[uuid][self.get_metadata_header()] dir_name = "{0}_{1}".format(metadata, filename) return dir_name