def comp2localchecksum(config, config_filename, md_list, sha_list): """ Creates indexfile list of local files @param config: configparser object """ files2upload = [] files2delete = [] md_checksums = [i[1] for i in md_list] sha_checksums = [i[1] for i in sha_list] config.read(config_filename) source_path = config.get("LocalFolders", "data_dir") upload_file = config.get("LocalFolders", "upload_file") hash_list = [] for (dirpath, dirnames, filenames) in walk(source_path): filenames = [f for f in filenames if not f[0] == "." and not str(f) == ntpath.basename(upload_file)] dirnames[:] = [d for d in dirnames if not d[0] == "."] for file in filenames: file_path = path.join(dirpath, file) # is always an ok os.path.join, local if path.isfile(file_path) and not file_path.endswith("~"): hash_str = checksum.make_hash_string(file_path, "SHA256") hash_str = hash_str.split() if hash_str[1] in sha_checksums: files2delete.append(file_path) else: hash_str = checksum.make_hash_string(file_path, "MD5") hash_str = hash_str.split() if hash_str[1] in md_checksums: files2delete.append(file_path) else: files2upload.append(file_path) hash_str.append(file_path) hash_list.append(hash_str) return files2upload, files2delete
def get_hash_list(config, config_filename): """ Creates indexfile list of local files @param config: configparser object """ config.read(config_filename) if DEBUG: if "dell" in config_filename and myos == "nt": print("all ok on Windows") if "dell" in config_filename and not myos == "nt": print("using a dell.cfg on somthing else then Windows") if "mac" in config_filename and myos == "posix": print("all ok on Mac") if "mac" in config_filename and not myos == "posix": print("using a mac.cfg on something else than OSX/Posix") source_path = config.get("LocalFolders", "data_dir") upload_file = config.get("LocalFolders", "upload_file") hash_list = [] for (dirpath, dirnames, filenames) in walk(source_path): filenames = [ f for f in filenames if not f[0] == "." and not str(f) == ntpath.basename(upload_file) ] # skip >.DS_Store and hidden files. & skip the uploadfile itself dirnames[:] = [d for d in dirnames if not d[0] == "."] # not sure if we need this? if DEBUG: print("filenames on: ", myos) print("==================") print(filenames) for file in filenames: file_path = path.join(dirpath, file) if myos == "nt": # normalise windows separators ---> C:\\DATA\\etc.whatever file_path = ntpath.normpath(file_path) if path.isfile(file_path) and not file_path.endswith("~"): hash_str = checksum.make_hash_string(file_path, "SHA256") hash_str = hash_str.split() hash_str.append(file_path) hash_list.append(hash_str) return hash_list