@@ -81,3 +81,36 @@ def pick_sdf(filename, directory=None):
81
81
return file_path + '.sdf'
82
82
# Couldn't find a suitable SDF file
83
83
return None
84
+
85
+
86
+ def pick_csv (filename , directory = None ):
87
+ """Returns a full path to the chosen CSV file. The supplied file
88
+ is not expected to contain a recognised CSV extension, this is added
89
+ automatically.
90
+ If a file with the extension `.csv.gz` or `.csv` is found the path to it
91
+ (excluding the extension) is returned. If this fails, `None` is returned.
92
+
93
+ :param filename: The CSV file basename, whose path is required.
94
+ :type filename: ``str``
95
+ :param directory: An optional directory.
96
+ If not provided it is calculated automatically.
97
+ :type directory: ``str``
98
+ :return: The full path to the file without extension,
99
+ or None if it does not exist
100
+ :rtype: ``str``
101
+ """
102
+ if directory is None :
103
+ directory = utils .get_undecorated_calling_module ()
104
+ # If the 'cwd' is not '/output' (which indicates we're in a Container)
105
+ # then remove the CWD and the anticipated '/'
106
+ # from the front of the module
107
+ if os .getcwd () not in ['/output' ]:
108
+ directory = directory [len (os .getcwd ()) + 1 :]
109
+
110
+ file_path = os .path .join (directory , filename )
111
+ if os .path .isfile (file_path + '.csv.gz' ):
112
+ return file_path + '.csv.gz'
113
+ elif os .path .isfile (file_path + '.csv' ):
114
+ return file_path + '.csv'
115
+ # Couldn't find a suitable CSV file
116
+ return None
0 commit comments