diff --git a/csv2dict/Csv2Dict.py b/csv2dict/Csv2Dict.py index 1b317b5..64129d0 100644 --- a/csv2dict/Csv2Dict.py +++ b/csv2dict/Csv2Dict.py @@ -25,7 +25,7 @@ class Csv2Dict: - def __init__(self, data_file, sheet, blankout=False): + def __init__(self, data_file, sheet, nx, blankout=False): ''' The Csv2Dict class reads a csv data file, the first line of which contains column names. Succeeding lines represent rows of data. Initially the column names are used as the keys to a list of dicts, one @@ -39,7 +39,8 @@ def __init__(self, data_file, sheet, blankout=False): self.meta_dicts = [] self.blankout = blankout self.sheet = sheet - self.data = None + self.nx = nx + self.data = {} self.meta_dict_properties_template = {} @@ -136,10 +137,9 @@ def get_existing_data(self, filepath, metadata_path): if self.blankout == True: return [] else: - if self.data == None: - nx = utils.Nuxeo() - self.data = nx.get_metadata(path=filepath) - return self.data['properties']['ucldc_schema:{}'.format(metadata_path)] + if self.data.get(filepath, None) == None: + self.data[filepath] = self.nx.get_metadata(path=filepath) + return self.data[filepath]['properties']['ucldc_schema:{}'.format(metadata_path)] def set_list_element(self, metadata_path, row_title, row, n): filepath = row['File path'] diff --git a/csv2dict/meta_from_csv.py b/csv2dict/meta_from_csv.py index 0e2370b..b0ea0bc 100644 --- a/csv2dict/meta_from_csv.py +++ b/csv2dict/meta_from_csv.py @@ -132,7 +132,7 @@ def main(argv): # get and instance of the Csv2Dict class which must be initialized # with the name of an input data (csv) file - csv2dict = Csv2Dict(csv_data_file, blankout=args.blankout, sheet=args.sheet) + csv2dict = Csv2Dict(csv_data_file, blankout=args.blankout, sheet=args.sheet, nx=nx) if csv2dict.status != 0: print('The Csv2Dict constructor reported and error (%d).' % csv2dict.status)