44import os
55import sys
66
7- def main (full = False , testdata = False , nexus_def_path = None , def_commit = None ):
7+ def main (full = False , testdata = False , nexus_def_path = None , def_commit = None , store_commit_filename = False ):
88 print (f"Debug: Generating ontology with full={ full } and testdata={ testdata } " )
99 local_dir = os .path .abspath (os .path .dirname (__file__ ))
1010 os .environ ['NEXUS_DEF_PATH' ] = nexus_def_path
@@ -29,7 +29,9 @@ def main(full=False, testdata=False, nexus_def_path=None, def_commit=None):
2929 fullsuffix = ''
3030
3131 # Include the commit hash in the output file name
32- output_file_name = f"NeXusOntology{ fullsuffix } _{ def_commit } .owl"
32+
33+ def_commit_text = f"_{ def_commit } " if store_commit_filename else ""
34+ output_file_name = f"NeXusOntology{ fullsuffix } { def_commit_text } .owl"
3335 output_path = os .path .join (local_dir , f"..{ os .sep } ontology{ os .sep } { output_file_name } " )
3436 onto .save (file = output_path , format = "rdfxml" )
3537
@@ -38,19 +40,24 @@ def main(full=False, testdata=False, nexus_def_path=None, def_commit=None):
3840 local_dir = os .path .abspath (os .path .dirname (__file__ ))
3941 one_up = os .path .join (local_dir , ".." , "definitions" )
4042 two_up = os .path .join (local_dir , ".." , ".." , "definitions" )
41- if os .path .isdir (one_up ):
42- nexus_def_path = one_up
43- elif os .path .isdir (two_up ):
43+ if os .path .isdir (two_up ):
4444 nexus_def_path = two_up
45+ elif os .path .isdir (one_up ):
46+ nexus_def_path = one_up
4547 else :
4648 raise FileNotFoundError ("definitions folder not found one or two directories up from script location." )
47- commit_arg = 1
48- full = len (sys .argv ) > 1 and sys .argv [1 ] == ' full'
49+ commit_arg = 1
50+ full = len (sys .argv ) > 1 and sys .argv [1 ] == " full"
4951 if full :
5052 commit_arg = 2
51- testdata = full and len (sys .argv ) > 2 and sys .argv [2 ] == ' testdata'
53+ testdata = full and len (sys .argv ) > 2 and sys .argv [2 ] == " testdata"
5254 if testdata :
5355 commit_arg = 3
56+ store_commit_filename = (
57+ (testdata and len (sys .argv ) > 3 and sys .argv [3 ] == "store_commit_filename" ) or
58+ (full and not testdata and len (sys .argv ) > 2 and sys .argv [2 ] == "store_commit_filename" ) or
59+ (not full and len (sys .argv ) > 1 and sys .argv [1 ] == "store_commit_filename" )
60+ )
5461 repo = pygit2 .Repository (nexus_def_path )
5562 # Check for provided commit hash argument
5663 if len (sys .argv ) > commit_arg :
@@ -68,4 +75,5 @@ def main(full=False, testdata=False, nexus_def_path=None, def_commit=None):
6875 else :
6976 # Use the current HEAD commit if no version is specified
7077 def_commit = str (repo .head .target )[:7 ]
71- main (full = full , testdata = testdata , nexus_def_path = nexus_def_path , def_commit = def_commit )
78+
79+ main (full = full , testdata = testdata , nexus_def_path = nexus_def_path , def_commit = def_commit , store_commit_filename = store_commit_filename )
0 commit comments