folio-migration-tools 1.9.0a3__py3-none-any.whl → 1.9.0a5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,7 @@ from folio_migration_tools.mapping_file_transformation.ref_data_mapping import (
24
24
  RefDataMapping,
25
25
  )
26
26
  from folio_migration_tools.migration_report import MigrationReport
27
+ from folio_migration_tools.task_configuration import AbstractTaskConfiguration
27
28
 
28
29
 
29
30
  class MapperBase:
@@ -42,7 +43,7 @@ class MapperBase:
42
43
  self.start_datetime = datetime.now(timezone.utc)
43
44
  self.folio_client: FolioClient = folio_client
44
45
  self.library_configuration: LibraryConfiguration = library_configuration
45
-
46
+ self.task_configuration: AbstractTaskConfiguration
46
47
  self.mapped_folio_fields: dict = {}
47
48
  self.migration_report: MigrationReport = MigrationReport()
48
49
  self.num_criticalerrors = 0
@@ -267,7 +268,13 @@ class MapperBase:
267
268
  sys.exit(1)
268
269
 
269
270
  def get_id_map_tuple(self, legacy_id: str, folio_record: dict, object_type: FOLIONamespaces):
270
- if object_type == FOLIONamespaces.instances:
271
+ if all(
272
+ [
273
+ object_type == FOLIONamespaces.instances,
274
+ (not getattr(self.task_configuration, "data_import_marc", False)),
275
+ getattr(self.task_configuration, "create_source_records", True),
276
+ ]
277
+ ):
271
278
  return (legacy_id, folio_record["id"], folio_record["hrid"])
272
279
  return (legacy_id, folio_record["id"])
273
280
 
@@ -32,7 +32,7 @@ class MarcFileProcessor:
32
32
  self.created_objects_file = created_objects_file
33
33
  if mapper.task_configuration.create_source_records:
34
34
  self.srs_records_file = open(self.folder_structure.srs_records_path, "w+")
35
- if mapper.task_configuration.data_import_marc:
35
+ if getattr(mapper.task_configuration, "data_import_marc", False):
36
36
  self.data_import_marc_file = open(self.folder_structure.data_import_marc_path, "wb+")
37
37
  self.unique_001s: set = set()
38
38
  self.failed_records_count: int = 0
@@ -87,7 +87,7 @@ class MarcFileProcessor:
87
87
  legacy_ids,
88
88
  self.object_type,
89
89
  )
90
- if self.mapper.task_configuration.data_import_marc:
90
+ if getattr(self.mapper.task_configuration, "data_import_marc", False):
91
91
  self.save_marc_record(
92
92
  marc_record,
93
93
  folio_rec,
@@ -271,7 +271,7 @@ class MarcFileProcessor:
271
271
  if not self.srs_records_file.seek(0):
272
272
  os.remove(self.srs_records_file.name)
273
273
  self.srs_records_file.close()
274
- if self.mapper.task_configuration.data_import_marc:
274
+ if getattr(self.mapper.task_configuration, "data_import_marc", False):
275
275
  self.data_import_marc_file.seek(0)
276
276
  if not self.data_import_marc_file.read(1):
277
277
  os.remove(self.data_import_marc_file.name)
@@ -59,7 +59,7 @@ class BibsRulesMapper(RulesMapperBase):
59
59
  self.instance_relationship_types: dict = {}
60
60
  self.other_mode_of_issuance_id = get_unspecified_mode_of_issuance(self.folio_client)
61
61
  self.create_source_records = all(
62
- [self.task_configuration.create_source_records, (not self.task_configuration.data_import_marc)]
62
+ [self.task_configuration.create_source_records, (not getattr(self.task_configuration, "data_import_marc", False))]
63
63
  )
64
64
  self.data_import_marc = self.task_configuration.data_import_marc
65
65
  self.start = time.time()
@@ -118,7 +118,7 @@ class BibsRulesMapper(RulesMapperBase):
118
118
  bad_tags = set(self.task_configuration.tags_to_delete) # "907"
119
119
  folio_instance = self.perform_initial_preparation(marc_record, legacy_ids)
120
120
  if self.data_import_marc:
121
- self.simple_bib_map(marc_record, folio_instance, ignored_subsequent_fields, legacy_ids)
121
+ self.simple_bib_map(folio_instance, marc_record, ignored_subsequent_fields, legacy_ids)
122
122
  else:
123
123
  for marc_field in marc_record:
124
124
  self.report_marc_stats(marc_field, bad_tags, legacy_ids, ignored_subsequent_fields)
@@ -152,7 +152,13 @@ class BibsRulesMapper(RulesMapperBase):
152
152
  legacy_ids (List[str]): _description_
153
153
  file_def (FileDefinition): _description_
154
154
  """
155
- self.process_marc_field(folio_instnace, marc_record['245'], ignored_subsequent_fields, legacy_ids)
155
+ try:
156
+ self.process_marc_field(folio_instnace, marc_record['245'], ignored_subsequent_fields, legacy_ids)
157
+ except KeyError:
158
+ raise TransformationRecordFailedError(
159
+ legacy_ids,
160
+ "No 245 field in MARC record"
161
+ )
156
162
 
157
163
  def perform_additional_parsing(
158
164
  self,
@@ -642,20 +648,6 @@ class BibsRulesMapper(RulesMapperBase):
642
648
  ) from e
643
649
 
644
650
 
645
- class SimpleBibsRulesMapper(BibsRulesMapper):
646
- def __init__(
647
- self,
648
- folio_client,
649
- library_configuration: LibraryConfiguration,
650
- task_configuration,
651
- ):
652
- super().__init__(
653
- folio_client,
654
- library_configuration,
655
- task_configuration,
656
- )
657
-
658
-
659
651
  def get_unspecified_mode_of_issuance(folio_client: FolioClient):
660
652
  m_o_is = list(folio_client.modes_of_issuance)
661
653
  if not any(m_o_is):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: folio_migration_tools
3
- Version: 1.9.0a3
3
+ Version: 1.9.0a5
4
4
  Summary: A tool allowing you to migrate data from legacy ILS:s (Library systems) into FOLIO LSP
5
5
  Home-page: https://github.com/FOLIO-FSE/folio_migration_tools
6
6
  License: MIT
@@ -11,7 +11,7 @@ folio_migration_tools/helper.py,sha256=KkOkNAGO_fuYqxdLrsbLzCJLQHUrFZG1NzD4RmpQ-
11
11
  folio_migration_tools/holdings_helper.py,sha256=yJpz6aJrKRBiJ1MtT5bs2vXAc88uJuGh2_KDuCySOKc,7559
12
12
  folio_migration_tools/i18n_config.py,sha256=3AH_2b9zTsxE4XTe4isM_zYtPJSlK0ix6eBmV7kAYUM,228
13
13
  folio_migration_tools/library_configuration.py,sha256=60hgGtyvHhRUKXHvqz41-2V5EtUaySMV20JIKk279N0,3636
14
- folio_migration_tools/mapper_base.py,sha256=46eO9wAxGoXZJC3SI7BNh-X7779SKSM8a8KXqdR9S8Y,19942
14
+ folio_migration_tools/mapper_base.py,sha256=dmwsgeolBWjmzaztms5r1_7OG2PlTcp0D74TQCE6cgk,20303
15
15
  folio_migration_tools/mapping_file_transformation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  folio_migration_tools/mapping_file_transformation/courses_mapper.py,sha256=mJQxxeTn1bCYb2zwFYyXJ6EGZpJ0DsmwOY3nED7D_gQ,8091
17
17
  folio_migration_tools/mapping_file_transformation/holdings_mapper.py,sha256=GI9xnN74EsUMAshXKNJ6p9bGPdLtK0PCXqbB3nIxrC8,7207
@@ -28,18 +28,17 @@ folio_migration_tools/marc_rules_transformation/conditions.py,sha256=MnbMThiOZ6I
28
28
  folio_migration_tools/marc_rules_transformation/holdings_statementsparser.py,sha256=lTb5QWEAgwyFHy5vdSK6oDl1Q5v2GnzuV04xWV3p4rc,12401
29
29
  folio_migration_tools/marc_rules_transformation/hrid_handler.py,sha256=lEvtJFWe5FoU372nHqTdnVF76qCKZjWgUJqIpiKUHY0,10026
30
30
  folio_migration_tools/marc_rules_transformation/loc_language_codes.xml,sha256=ztn2_yKws6qySL4oSsZh7sOjxq5bCC1PhAnXJdtgmJ0,382912
31
- folio_migration_tools/marc_rules_transformation/marc_file_processor.py,sha256=vP6u8BDrf3v5q-scIPEINXYUL223cmreAQ8BUr9WCcM,12292
31
+ folio_migration_tools/marc_rules_transformation/marc_file_processor.py,sha256=WkOQRDi7f4PZ5qmVH3Q-1_zdGEKYSvOGC6jixDwDp98,12349
32
32
  folio_migration_tools/marc_rules_transformation/marc_reader_wrapper.py,sha256=9ATjYMRAjy0QcXtmNZaHVhHLJ5hE1WUgOcF6KMJjbgo,5309
33
33
  folio_migration_tools/marc_rules_transformation/rules_mapper_authorities.py,sha256=GFw8j9UtCxnUdLShmPzJa1MpCK8a0NkQIN5C3jyouRs,9604
34
34
  folio_migration_tools/marc_rules_transformation/rules_mapper_base.py,sha256=WWSJgYvF9LeY8vh-BtQi7Fm3J-cowUJKWa0Wk2Ge7fc,39358
35
- folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py,sha256=TpR_APcNzrzftSWr22eWf45GZnJgI44ESQDr7ZnRs5k,28874
35
+ folio_migration_tools/marc_rules_transformation/rules_mapper_bibs.py,sha256=5BHCEAoTmsJLzG9161Y49-DwA_-Jr44XUGX725-dNKE,28755
36
36
  folio_migration_tools/marc_rules_transformation/rules_mapper_holdings.py,sha256=EBxf9Qh5Y0eDOmqYssWfaizxafiXSYDFzWmCuPtdG-8,18226
37
37
  folio_migration_tools/migration_report.py,sha256=BkRspM1hwTBnWeqsHamf7yVEofzLj560Q-9G--O00hw,4258
38
38
  folio_migration_tools/migration_tasks/__init__.py,sha256=ZkbY_yGyB84Ke8OMlYUzyyBj4cxxNrhMTwQlu_GbdDs,211
39
39
  folio_migration_tools/migration_tasks/authority_transformer.py,sha256=AoXg9s-GLO3yEEDCrQV7hc4YVXxwxsdxDdpj1zhHydE,4251
40
40
  folio_migration_tools/migration_tasks/batch_poster.py,sha256=iaWhvxdYli0kgsXLHGmFFBMeVXGpAv9eDg02BagyQ2U,29732
41
41
  folio_migration_tools/migration_tasks/bibs_transformer.py,sha256=XzlPo-0uuugJA4SM80xOlOj5nDK6OMDXFnAYg80hOBc,7791
42
- folio_migration_tools/migration_tasks/bibs_transformer_simple.py,sha256=goXG08zP9JUwt6Gd2FcslA3gBJpezUUP3k2zB67a4xM,7266
43
42
  folio_migration_tools/migration_tasks/courses_migrator.py,sha256=dQerp97P3r7wmxK3Ovg6AriO6K_nTr6vA8RKj_XBEt4,5728
44
43
  folio_migration_tools/migration_tasks/holdings_csv_transformer.py,sha256=Hwr4YjgNIQpi2N-x8eq-mmRpXAyxYylQjpYubm03-ec,19668
45
44
  folio_migration_tools/migration_tasks/holdings_marc_transformer.py,sha256=yN0a8YVNx2P6NswxSylTca0MmNk1shze3PyKXv9JJIw,9547
@@ -61,7 +60,7 @@ folio_migration_tools/transaction_migration/legacy_request.py,sha256=1ulyFzPQw_I
61
60
  folio_migration_tools/transaction_migration/legacy_reserve.py,sha256=rZVtiMBYnt6aI0WxAwPN8fML_MKEUSUYsadCKPTeB4E,1839
62
61
  folio_migration_tools/transaction_migration/transaction_result.py,sha256=cTdCN0BnlI9_ZJB2Z3Fdkl9gpymIi-9mGZsRFlQcmDk,656
63
62
  folio_migration_tools/translations/en.json,sha256=HOVpkb_T-SN_x0NpDp8gyvV1hMLCui3SsG7ByyIv0OU,38669
64
- folio_migration_tools-1.9.0a3.dist-info/LICENSE,sha256=PhIEkitVi3ejgq56tt6sWoJIG_zmv82cjjd_aYPPGdI,1072
65
- folio_migration_tools-1.9.0a3.dist-info/METADATA,sha256=kvLY1YL44A4bSOpnwAoBZ2a5srFhjenC9D1_4ODuCCk,7318
66
- folio_migration_tools-1.9.0a3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
67
- folio_migration_tools-1.9.0a3.dist-info/RECORD,,
63
+ folio_migration_tools-1.9.0a5.dist-info/LICENSE,sha256=PhIEkitVi3ejgq56tt6sWoJIG_zmv82cjjd_aYPPGdI,1072
64
+ folio_migration_tools-1.9.0a5.dist-info/METADATA,sha256=ohkzY98Ct_djuhK-ks9sFehWfuQCsEE42kOOQQeyDR4,7318
65
+ folio_migration_tools-1.9.0a5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
66
+ folio_migration_tools-1.9.0a5.dist-info/RECORD,,
@@ -1,198 +0,0 @@
1
- import logging
2
- from typing import Annotated, List
3
-
4
- import i18n
5
- from folio_uuid.folio_namespaces import FOLIONamespaces
6
- from pydantic import Field
7
-
8
- from folio_migration_tools.helper import Helper
9
- from folio_migration_tools.library_configuration import (
10
- FileDefinition,
11
- HridHandling,
12
- IlsFlavour,
13
- LibraryConfiguration,
14
- )
15
- from folio_migration_tools.marc_rules_transformation.marc_file_processor import (
16
- MarcFileProcessor,
17
- )
18
- from folio_migration_tools.marc_rules_transformation.rules_mapper_bibs import (
19
- SimpleBibsRulesMapper,
20
- )
21
- from folio_migration_tools.migration_tasks.migration_task_base import MigrationTaskBase
22
- from folio_migration_tools.task_configuration import AbstractTaskConfiguration
23
-
24
-
25
- class BibsTransformer(MigrationTaskBase):
26
- class TaskConfiguration(AbstractTaskConfiguration):
27
- name: Annotated[
28
- str,
29
- Field(
30
- description=(
31
- "Name of this migration task. The name is being used to call the specific "
32
- "task, and to distinguish tasks of similar types"
33
- )
34
- ),
35
- ]
36
- migration_task_type: Annotated[
37
- str,
38
- Field(
39
- title="Migration task type",
40
- description=("The type of migration task you want to perform."),
41
- ),
42
- ]
43
- files: Annotated[
44
- List[FileDefinition],
45
- Field(
46
- title="Source files",
47
- description=("List of MARC21 files with bibliographic records."),
48
- ),
49
- ]
50
- ils_flavour: Annotated[
51
- IlsFlavour,
52
- Field(
53
- title="ILS flavour", description="The type of ILS you are migrating records from."
54
- ),
55
- ]
56
- custom_bib_id_field: Annotated[
57
- str,
58
- Field(
59
- title="Custom BIB ID field",
60
- description=(
61
- 'A string representing a MARC field with optional subfield indicated by a "$" '
62
- '(eg. "991$a") from which to draw legacy Bib ID. Use this in combination '
63
- 'with `ilsFlavour: "custom"`. Defaults to "001", and is ignored for all other '
64
- "ilsFlavours."
65
- ),
66
- ),
67
- ] = "001"
68
- add_administrative_notes_with_legacy_ids: Annotated[
69
- bool,
70
- Field(
71
- title="Add administrative notes with legacy IDs",
72
- description=(
73
- "If set to true, an Administrative note will be added to the records "
74
- "containing the legacy ID. Use this in order to protect the values from "
75
- "getting overwritten by overlays,"
76
- ),
77
- ),
78
- ] = True
79
- tags_to_delete: Annotated[
80
- List[str],
81
- Field(
82
- title="Tags to delete from MARC record",
83
- description=(
84
- "Tags in the incoming MARC authority that the process should remove "
85
- "before adding them into FOLIO. These tags will be used in the "
86
- "transformation before getting removed."
87
- ),
88
- ),
89
- ] = []
90
- create_source_records: Annotated[
91
- bool,
92
- Field(
93
- title="Create source records",
94
- description=(
95
- "Controls wheter or not to retain the MARC records in "
96
- "Source Record Storage."
97
- ),
98
- ),
99
- ] = True
100
- parse_cataloged_date: Annotated[
101
- bool,
102
- Field(
103
- title="Parse cataloged date",
104
- description=(
105
- "Parse fields mapped to catalogedDate into a FOLIO accepted date string using "
106
- "dateutil.parser. Verify results carefully when using"
107
- ),
108
- ),
109
- ] = False
110
- hrid_handling: Annotated[
111
- HridHandling,
112
- Field(
113
- title="HRID Handling",
114
- description=(
115
- "Setting to default will make FOLIO generate HRIDs and move the existing "
116
- "001:s into a 035, concatenated with the 003. Choosing preserve001 means "
117
- "the 001:s will remain in place, and that they will also become the HRIDs"
118
- ),
119
- ),
120
- ] = HridHandling.default
121
- reset_hrid_settings: Annotated[
122
- bool,
123
- Field(
124
- title="Reset HRID settings",
125
- description=(
126
- "Setting to true means the task will "
127
- "reset the HRID counters for this particular record type"
128
- ),
129
- ),
130
- ] = False
131
- update_hrid_settings: Annotated[
132
- bool,
133
- Field(
134
- title="Update HRID settings",
135
- description="At the end of the run, update FOLIO with the HRID settings",
136
- ),
137
- ] = True
138
- deactivate035_from001: Annotated[
139
- bool,
140
- Field(
141
- title="Create 035 from 001 and 003",
142
- description=(
143
- "This deactivates the FOLIO default functionality of moving the previous 001 "
144
- "into a 035, prefixed with the value from 003"
145
- ),
146
- ),
147
- ] = False
148
-
149
- @staticmethod
150
- def get_object_type() -> FOLIONamespaces:
151
- return FOLIONamespaces.instances
152
-
153
- def __init__(
154
- self,
155
- task_config: TaskConfiguration,
156
- library_config: LibraryConfiguration,
157
- folio_client,
158
- use_logging: bool = True,
159
- ):
160
- super().__init__(library_config, task_config, folio_client, use_logging)
161
- self.processor: MarcFileProcessor
162
- self.check_source_files(
163
- self.folder_structure.legacy_records_folder, self.task_configuration.files
164
- )
165
- self.mapper = SimpleBibsRulesMapper(self.folio_client, library_config, self.task_configuration)
166
- self.bib_ids: set = set()
167
- if (
168
- self.task_configuration.reset_hrid_settings
169
- and self.task_configuration.update_hrid_settings
170
- ):
171
- self.mapper.hrid_handler.reset_instance_hrid_counter()
172
- logging.info("Init done")
173
-
174
- def do_work(self):
175
- self.do_work_marc_transformer()
176
-
177
- def wrap_up(self):
178
- logging.info("Done. Transformer wrapping up...")
179
- self.extradata_writer.flush()
180
- self.processor.wrap_up()
181
- with open(self.folder_structure.migration_reports_file, "w+") as report_file:
182
- self.mapper.migration_report.write_migration_report(
183
- i18n.t("Bibliographic records transformation report"),
184
- report_file,
185
- self.start_datetime,
186
- )
187
- Helper.print_mapping_report(
188
- report_file,
189
- self.mapper.parsed_records,
190
- self.mapper.mapped_folio_fields,
191
- self.mapper.mapped_legacy_fields,
192
- )
193
-
194
- logging.info(
195
- "Done. Transformation report written to %s",
196
- self.folder_structure.migration_reports_file.name,
197
- )
198
- self.clean_out_empty_logs()