(self, filename:str)
| 19 | |
| 20 | |
| 21 | def get_structure(self, filename:str) -> FileContent: |
| 22 | |
| 23 | content = FileContent() |
| 24 | reader = FileReader() |
| 25 | content.filename = Util.get_filename(filename) |
| 26 | if os.path.exists(filename): |
| 27 | |
| 28 | with open(filename, newline='') as fb: |
| 29 | |
| 30 | csv.field_size_limit(sys.maxsize) |
| 31 | csv_content = csv.DictReader(fb, delimiter=self._delimiter, quotechar='"') |
| 32 | content.headers = [column.lower() for column in csv_content.fieldnames] |
| 33 | content.headers.append(Settings.checksum_column) |
| 34 | |
| 35 | for line in csv_content: |
| 36 | row = [] |
| 37 | file_base64 = Util.create_filename(line.values(), content.filename) |
| 38 | |
| 39 | for value in line.values(): |
| 40 | try: |
| 41 | if value is None: |
| 42 | row.append(None) |
| 43 | continue |
| 44 | elif value.lower() in self._char_replacement: |
| 45 | value = self._char_replacement[value.lower()] |
| 46 | |
| 47 | file = reader.get_from_base64(value) |
| 48 | |
| 49 | if file.content is not None: |
| 50 | value = file.content |
| 51 | #file.filename = self._save_file(file.content, file.extension) |
| 52 | file.filename = reader.save_file(file.bytearray, file.extension, file_base64) |
| 53 | row.append(value) |
| 54 | else: |
| 55 | decoded_value = None |
| 56 | if value is not None: |
| 57 | decoded_value = Util.decode(value) |
| 58 | if ImportSetting().isStrict: |
| 59 | decoded_value = Util.remove_invalidchars(decoded_value, ImportSetting().valid_chars) |
| 60 | row.append(decoded_value) |
| 61 | |
| 62 | except Exception as e: |
| 63 | AnsiPrint.print_debug(e) |
| 64 | raise e |
| 65 | |
| 66 | |
| 67 | ## Calculate checksum |
| 68 | hash_value = Hashing.get_md5(''.join(value for value in row if value is not None)) |
| 69 | row.append(hash_value) |
| 70 | content.rows.append(row) |
| 71 | |
| 72 | return content |
no test coverage detected