aboutsummaryrefslogtreecommitdiff
path: root/quality_control/file_utils.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-07-18 18:47:11 +0300
committerFrederick Muriuki Muriithi2022-07-19 05:10:32 +0300
commitc52570a4069abb6b8953e486adb326392ce6714c (patch)
tree260ebe385a1c9b8a1782765fa3072f59bfa3555b /quality_control/file_utils.py
parent044184ef28a091519b7632d582387c26bf1543ea (diff)
downloadgn-uploader-c52570a4069abb6b8953e486adb326392ce6714c.tar.gz
Implement data insertion (averages/means)
* quality_control/file_utils.py (new file): extract common file utilities. * quality_control/parsing.py (refactor): extract common file utilities. * scripts/insert_data.py: Implement data insertion for averages/means
Diffstat (limited to 'quality_control/file_utils.py')
-rw-r--r--quality_control/file_utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/quality_control/file_utils.py b/quality_control/file_utils.py
new file mode 100644
index 0000000..fdce1e1
--- /dev/null
+++ b/quality_control/file_utils.py
@@ -0,0 +1,13 @@
+"Common file utilities"
+from typing import Union
+from pathlib import Path
+from io import TextIOWrapper
+from zipfile import ZipFile, is_zipfile
+
+def open_file(filepath: Union[str, Path]) -> Union[ZipFile, TextIOWrapper]:
+ "Transparently open both TSV and ZIP files"
+ if not is_zipfile(filepath):
+ return open(filepath, encoding="utf-8")
+
+ with ZipFile(filepath, "r") as zfile:
+ return zfile.open(zfile.infolist()[0], "r")