1 # SPDX-License-Identifier: GPL-2.0+
5 class CSVCollection(dict):
8 source_column_name = 'Sources / Destinations'
11 This class is a dictionary representation of the collection of sheets that
12 exist in a given .ODS file.
14 def __init__(self, pattern, skip_commented_lines=True, strip_lines=True):
15 super(CSVCollection, self).__init__()
16 self.pattern = pattern
17 C = '#' if skip_commented_lines else 'blahblahblah'
20 strip = lambda s:s.strip()
25 key = self.source_column_name
26 for fname in glob.glob(pattern):
27 with open(fname) as F:
28 dR = csv.DictReader(F, delimiter=self.delimiter,
29 quotechar=self.quotechar)
30 name = os.path.basename(fname).partition('.')[0]
32 r[key]:{f:strip(c) for f,c in r.items()
33 if f != key and f[:1] not in ['', C] and
34 strip(c)[:1] not in ['', C]}
35 for r in dR if r[key][:1] not in ['', C]
37 # now, go back through and eliminate all empty dictionaries
38 D = {k:v for k,v in D.items() if v}