diff options
author | Frederick Muriuki Muriithi | 2024-06-20 09:27:03 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-06-20 09:27:03 -0500 |
commit | 3059c46b2d14f7f1002de8ab476adcfa520b0b35 (patch) | |
tree | 5888caf6b6798e0348adfee016c56211d6e2d6c1 | |
parent | ca3b9fe366f8d541a57f6361c122cfa372788d2c (diff) | |
download | gn-uploader-3059c46b2d14f7f1002de8ab476adcfa520b0b35.tar.gz |
Check for special files that might share names/extensions
Check for special files and hidden files that might be inadvertently
added to the zip bundle by the operating system in use that might
share names and/or extensions with the main bundle files.
-rw-r--r-- | r_qtl/r_qtl2.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index 87491d0..0a96e7c 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -17,11 +17,26 @@ FILE_TYPES = ( "geno", "founder_geno", "pheno", "covar", "phenocovar", "gmap", "pmap", "phenose") + +def __special_file__(filename): + """ + Check whether the file is special in some ways, e.g. MacOSX seems to include + files in a directory `__MACOSX` that share parts of the name, and extensions + with the main files in the bundle. + """ + is_macosx_special_file = filename.startswith("__MACOSX") + is_nix_hidden_file = Path(filename).name.startswith(".") + + return (is_macosx_special_file or is_nix_hidden_file) + + def control_data(zfile: ZipFile) -> dict: """Retrieve the control file from the zip file info.""" files = tuple(filename for filename in zfile.namelist() - if (filename.endswith(".yaml") or filename.endswith(".json"))) + if (not __special_file__(filename) + and (filename.endswith(".yaml") + or filename.endswith(".json")))) num_files = len(files) if num_files == 0: raise InvalidFormat("Expected a json or yaml control file.") |