|
| 1 | +""" |
| 2 | +The command ran: |
| 3 | +python patch.py syn53170398 syn62069187 syn54082015 |
| 4 | +In leu of lack of unit or integration tests, the above command replicates the |
| 5 | +this is to test 15.5-consortium (syn55146141) and 15.6-consortium (Staging syn62069187) |
| 6 | +that they are the same. |
| 7 | +
|
| 8 | +python compare_patch.py --original_synid syn55146141 --new_synid syn62069187 |
| 9 | +""" |
| 10 | +import argparse |
| 11 | + |
| 12 | +import synapseclient |
| 13 | +import synapseutils as synu |
| 14 | + |
| 15 | + |
| 16 | +def _get_file_dict(syn: synapseclient.Synapse, synid: str): |
| 17 | + """ |
| 18 | + This function generates a dictionary of files from a Synapse ID. |
| 19 | +
|
| 20 | + Args: |
| 21 | + syn (synapseclient.Synapse): A Synapse client object. |
| 22 | + synid (str): The Synapse ID of the files to retrieve. |
| 23 | +
|
| 24 | + Returns: |
| 25 | + dict[str, str]: A dictionary mapping Synapse IDs to file names. |
| 26 | + """ |
| 27 | + all_files = synu.walk(syn, synid) |
| 28 | + file_list = {} |
| 29 | + for _, _, files in all_files: |
| 30 | + files = {name: syn.get(synid, downloadFile=False) for name, synid in files} |
| 31 | + file_list.update(files) |
| 32 | + return file_list |
| 33 | + |
| 34 | + |
| 35 | +def compare_releases(original_synid: str, new_synid: str): |
| 36 | + """ |
| 37 | + This function compares two folders that should have identifical files |
| 38 | + with each file's MD5s |
| 39 | +
|
| 40 | + Args: |
| 41 | + original_synid (str): The Synapse ID of the original release. |
| 42 | + new_synid (str): The Synapse ID of the new release. |
| 43 | +
|
| 44 | + Returns: |
| 45 | + tuple: A tuple containing the original release entity, the new release entity, |
| 46 | + and a list of retracted entities. |
| 47 | + """ |
| 48 | + |
| 49 | + # Log in to Synapse |
| 50 | + syn = synapseclient.login() |
| 51 | + |
| 52 | + # Get the entities for the original and new releases |
| 53 | + # original_ent = syn.get(original_synid) |
| 54 | + # original_files = synu.walk(original_synid) |
| 55 | + original_file_list = _get_file_dict(syn, original_synid) |
| 56 | + # new_ent = syn.get(new_synid) |
| 57 | + # new_files = synu.walk(new_synid) |
| 58 | + new_file_list = _get_file_dict(syn, new_synid) |
| 59 | + |
| 60 | + # Check that the two folders have the same number of files |
| 61 | + print("Number of files in old folder: ", len(original_file_list)) |
| 62 | + print("Number of files in new folder: ", len(new_file_list)) |
| 63 | + for filename in new_file_list.keys(): |
| 64 | + if original_file_list.get(filename) is None: |
| 65 | + print("File not found in old folder: ", filename) |
| 66 | + |
| 67 | + for filename in original_file_list.keys(): |
| 68 | + if new_file_list.get(filename) is None: |
| 69 | + print("File not found in new folder: ", filename) |
| 70 | + else: |
| 71 | + if original_file_list[filename].md5 != new_file_list[filename].md5: |
| 72 | + print("Files are different: ", filename) |
| 73 | + |
| 74 | +def main(): |
| 75 | + parser = argparse.ArgumentParser(description='Compare two Synapse releases.') |
| 76 | + parser.add_argument('--original_synid', type=str, help='The Synapse ID of the original release') |
| 77 | + parser.add_argument('--new_synid', type=str, help='The Synapse ID of the new release') |
| 78 | + |
| 79 | + args = parser.parse_args() |
| 80 | + |
| 81 | + compare_releases(args.original_synid, args.new_synid) |
| 82 | + |
| 83 | +if __name__ == "__main__": |
| 84 | + main() |
0 commit comments