@@ -1535,6 +1535,7 @@ def load_terms_from_file(
15351535 self ,
15361536 glossary_name : str ,
15371537 filename : str ,
1538+ file_path : str = os .environ .get ("EGERIA_GLOSSARY_PATH" , None ),
15381539 upsert : bool = True ,
15391540 verbose : bool = True ,
15401541 ) -> List [dict ] | None :
@@ -1544,6 +1545,9 @@ def load_terms_from_file(
15441545 ----------
15451546 glossary_name : str
15461547 Name of the glossary to import terms into.
1548+ file_path: str, default is EGERIA_GLOSSARY_PATH if specified or None
1549+ If EGERIA_GLOSSARY_PATH environment variable is set, then it will be used in forming the
1550+ prepended to the filename parameter to form the full path to the file.
15471551 filename: str
15481552 Path to the file to import terms from. File is assumed to be in CSV format. The path
15491553 is relative to where the python method is being called from.
@@ -1609,16 +1613,25 @@ def load_terms_from_file(
16091613 "Version Identifier" ,
16101614 "Status" ,
16111615 }
1616+
1617+ if file_path :
1618+ full_file_path = os .path .join (file_path , filename )
1619+ else :
1620+ full_file_path = filename
1621+
1622+ if not os .path .isfile (full_file_path ):
1623+ raise FileNotFoundError (
1624+ f"Did not find file with path { file_path } and name { filename } "
1625+ )
16121626 # process file
1613- with open (filename , mode = "r" ) as file :
1627+ with open (full_file_path , mode = "r" ) as file :
16141628 # Create a CSV reader object
16151629 csv_reader = csv .DictReader (file )
16161630 headers = csv_reader .fieldnames
16171631 term_info = []
16181632 # check that the column headers are known
16191633 if all (header in term_properties for header in headers ) is False :
16201634 raise InvalidParameterException ("Invalid headers in CSV File" )
1621- sys .exit (1 )
16221635
16231636 # process each row and validate values
16241637 for row in csv_reader :
@@ -1759,7 +1772,10 @@ def load_terms_from_file(
17591772 return
17601773
17611774 async def _async_export_glossary_to_csv (
1762- self , glossary_guid : str , target_file : str
1775+ self ,
1776+ glossary_guid : str ,
1777+ target_file : str ,
1778+ file_path : str = os .environ .get ("EGERIA_GLOSSARY_PATH" , None ),
17631779 ) -> int :
17641780 """Export all the terms in a glossary to a CSV file. Async version
17651781
@@ -1769,6 +1785,9 @@ async def _async_export_glossary_to_csv(
17691785 Identity of the glossary to export.
17701786 target_file: str
17711787 Complete file name with path and extension to export to.
1788+ file_path: str, default is EGERIA_GLOSSARY_PATH if specified or None
1789+ If EGERIA_GLOSSARY_PATH environment variable is set, then it will be used in forming the
1790+ prepended to the filename parameter to form the full path to the file.
17721791
17731792 Returns:
17741793 int: Number of rows exported.
@@ -1787,8 +1806,12 @@ async def _async_export_glossary_to_csv(
17871806 "Version Identifier" ,
17881807 "Status" ,
17891808 ]
1809+ if file_path :
1810+ full_file_path = os .path .join (file_path , target_file )
1811+ else :
1812+ full_file_path = target_file
17901813
1791- with open (target_file , mode = "w" ) as file :
1814+ with open (full_file_path , mode = "w" ) as file :
17921815 csv_writer = csv .DictWriter (file , fieldnames = header )
17931816 csv_writer .writeheader ()
17941817 count = 0
@@ -1822,7 +1845,12 @@ async def _async_export_glossary_to_csv(
18221845 count += 1
18231846 return count
18241847
1825- def export_glossary_to_csv (self , glossary_guid : str , target_file : str ) -> int :
1848+ def export_glossary_to_csv (
1849+ self ,
1850+ glossary_guid : str ,
1851+ target_file : str ,
1852+ file_path : str = os .environ .get ("EGERIA_GLOSSARY_PATH" , None ),
1853+ ) -> int :
18261854 """Export all the terms in a glossary to a CSV file.
18271855
18281856 Parameters:
@@ -1831,14 +1859,17 @@ def export_glossary_to_csv(self, glossary_guid: str, target_file: str) -> int:
18311859 Identity of the glossary to export.
18321860 target_file: str
18331861 Complete file name with path and extension to export to.
1862+ file_path: str, default is EGERIA_GLOSSARY_PATH if specified or None
1863+ If EGERIA_GLOSSARY_PATH environment variable is set, then it will be used in forming the
1864+ prepended to the filename parameter to form the full path to the file.
18341865
18351866 Returns:
18361867 int: Number of rows exported.
18371868 """
18381869
18391870 loop = asyncio .get_event_loop ()
18401871 response = loop .run_until_complete (
1841- self ._async_export_glossary_to_csv (glossary_guid , target_file )
1872+ self ._async_export_glossary_to_csv (glossary_guid , target_file , file_path )
18421873 )
18431874
18441875 return response
0 commit comments