From 52cd294c2f1d06dddbd6ff613b11f8bc43066038 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Wed, 3 Jul 2024 15:21:28 +0300 Subject: Return a "-1" if the turtle directory does not exist. * scripts/index-genenetwork (hash_rdf_graph): Remove check for the turtle directory. (is_data_modified): Ditto. (create_xapian_index): Ditto. Signed-off-by: Munyoki Kilyungi --- scripts/index-genenetwork | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/index-genenetwork b/scripts/index-genenetwork index de3edb0..c13c933 100755 --- a/scripts/index-genenetwork +++ b/scripts/index-genenetwork @@ -241,6 +241,8 @@ def build_rdf_cache(sparql_uri: str, query: str, remove_common_words: bool = Fal def hash_rdf_graph(ttl_dir: pathlib.Path) -> str: + if not ttl_dir.exists(): + return "-1" ttl_hash = hashlib.new("md5") for ttl_file in ttl_dir.glob("*.ttl"): with open(ttl_file, encoding="utf-8") as f_: @@ -528,10 +530,7 @@ def is_data_modified(xapian_directory: str, # Return a zero exit status code when the data has changed; # otherwise exit with a 1 exit status code. generif = pathlib.Path("/var/lib/data/generif-metadata.ttl") - generif_checksum = "-1" - if generif.exists(): - generif_checksum = hash_rdf_graph(generif) - if (db.get_metadata("generif-checksum").decode() == generif_checksum and + if (db.get_metadata("generif-checksum").decode() == hash_rdf_graph(generif) and db.get_metadata("checksums").decode() == checksums): sys.exit(1) sys.exit(0) @@ -586,9 +585,9 @@ def create_xapian_index(xapian_directory: str, sql_uri: str, db.set_metadata("tables", " ".join(tables)) db.set_metadata("checksums", " ".join(checksums)) logging.info("Writing generif checksums into index") - generif = pathlib.Path("/var/lib/data/generif-metadata.ttl") - if generif.exists(): - db.set_metadata("generif-checksum", hash_rdf_graph(generif).encode()) + db.set_metadata( + "generif-checksum", + hash_rdf_graph(pathlib.Path("/var/lib/data/generif-metadata.ttl")).encode()) for child in combined_index.iterdir(): shutil.move(child, xapian_directory) logging.info("Index built") -- cgit v1.2.3