folio-data-import 0.1.0__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.
Potentially problematic release.
This version of folio-data-import might be problematic. Click here for more details.
- folio_data_import-0.1.0.dist-info/LICENSE +21 -0
- folio_data_import-0.1.0.dist-info/METADATA +63 -0
- folio_data_import-0.1.0.dist-info/RECORD +9 -0
- folio_data_import-0.1.0.dist-info/WHEEL +4 -0
- folio_data_import-0.1.0.dist-info/entry_points.txt +5 -0
- src/folio_data_import/MARCDataImport.py +528 -0
- src/folio_data_import/UserImport.py +724 -0
- src/folio_data_import/__init__.py +0 -0
- src/folio_data_import/__main__.py +109 -0
|
File without changes
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
import glob
|
|
4
|
+
from getpass import getpass
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import folioclient
|
|
8
|
+
import inquirer
|
|
9
|
+
|
|
10
|
+
from folio_data_import.MARCDataImport import MARCImportJob
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def main():
|
|
14
|
+
parser = argparse.ArgumentParser()
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"--record-type", type=str, help="The record type to import", default="MARC21"
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument("--gateway_url", type=str, help="The FOLIO API Gateway URL")
|
|
19
|
+
parser.add_argument("--tenant_id", type=str, help="The FOLIO tenant ID")
|
|
20
|
+
parser.add_argument("--username", type=str, help="The FOLIO username")
|
|
21
|
+
parser.add_argument("--password", type=str, help="The FOLIO password", default="")
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--marc_file_path",
|
|
24
|
+
type=str,
|
|
25
|
+
help="The MARC file (or file glob, using shell globbing syntax) to import",
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"--import_profile_name",
|
|
29
|
+
type=str,
|
|
30
|
+
help="The name of the data import job profile to use",
|
|
31
|
+
default="",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--batch_size",
|
|
35
|
+
type=int,
|
|
36
|
+
help="The number of source records to include in a record batch sent to FOLIO.",
|
|
37
|
+
default=10,
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"--batch_delay",
|
|
41
|
+
type=float,
|
|
42
|
+
help="The number of seconds to wait between record batches.",
|
|
43
|
+
default=0.0,
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--consolidate",
|
|
47
|
+
action="store_true",
|
|
48
|
+
help="Consolidate records into a single job. Default is to create a new job for each MARC file.",
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--no-progress",
|
|
52
|
+
action="store_true",
|
|
53
|
+
help="Disable progress bars (eg. for running in a CI environment)",
|
|
54
|
+
)
|
|
55
|
+
args = parser.parse_args()
|
|
56
|
+
if not args.password:
|
|
57
|
+
args.password = getpass("Enter FOLIO password: ")
|
|
58
|
+
folio_client = folioclient.FolioClient(
|
|
59
|
+
args.gateway_url, args.tenant_id, args.username, args.password
|
|
60
|
+
)
|
|
61
|
+
if not args.import_profile_name:
|
|
62
|
+
import_profiles = folio_client.folio_get(
|
|
63
|
+
"/data-import-profiles/jobProfiles",
|
|
64
|
+
"jobProfiles",
|
|
65
|
+
query_params={"limit": "1000"},
|
|
66
|
+
)
|
|
67
|
+
import_profile_names = [
|
|
68
|
+
profile["name"]
|
|
69
|
+
for profile in import_profiles
|
|
70
|
+
if args.record_type.lower() in profile["dataType"].lower()
|
|
71
|
+
]
|
|
72
|
+
questions = [
|
|
73
|
+
inquirer.List(
|
|
74
|
+
"import_profile_name",
|
|
75
|
+
message="Select an import profile",
|
|
76
|
+
choices=import_profile_names,
|
|
77
|
+
)
|
|
78
|
+
]
|
|
79
|
+
answers = inquirer.prompt(questions)
|
|
80
|
+
args.import_profile_name = answers["import_profile_name"]
|
|
81
|
+
|
|
82
|
+
if args.record_type.lower() == "marc21":
|
|
83
|
+
marc_files = [Path(x) for x in glob.glob(args.marc_file_path, root_dir="./")]
|
|
84
|
+
print(marc_files)
|
|
85
|
+
try:
|
|
86
|
+
await MARCImportJob(
|
|
87
|
+
folio_client,
|
|
88
|
+
marc_files,
|
|
89
|
+
args.import_profile_name,
|
|
90
|
+
batch_size=args.batch_size,
|
|
91
|
+
batch_delay=args.batch_delay,
|
|
92
|
+
consolidate=bool(args.consolidate),
|
|
93
|
+
no_progress=bool(args.no_progress),
|
|
94
|
+
).do_work()
|
|
95
|
+
except Exception as e:
|
|
96
|
+
print("Error importing files: " + str(e))
|
|
97
|
+
raise
|
|
98
|
+
elif args.record_type.lower() == "users":
|
|
99
|
+
print("User import not yet implemented. Run UserImport.py directly or use folio-user-import CLI.")
|
|
100
|
+
else:
|
|
101
|
+
print("Record type not supported. Supported types are: MARC21")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def sync_main():
|
|
105
|
+
asyncio.run(main())
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
asyncio.run(main())
|