-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_item.py
77 lines (59 loc) · 2.12 KB
/
remove_item.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3.9
#
# @author Matthias Genzmehr
# @copyright 2024 Universitätsbibliothek Mainz
# @version 1.0
#
import sys
import logging
from logging import FileHandler, Formatter
from folio.connection import Connection
from folio.values.uuid import ItemIDValue
from folio.values.filename import FileName
from folio.exceptions import ArgumentException, ItemIDException, HTTPException, ConnectionException, NotFoundException
try:
if len(sys.argv) < 2: raise ArgumentException("Das Script benötigt eine ItemID als Argument!")
if len(sys.argv) >= 3 and FileName()(sys.argv[2]) :
logFileName = sys.argv[2]
else:
logFileName = "remove.log"
logger = logging.Logger("RemoveItem")
logger.setLevel(logging.INFO)
handler = FileHandler(logFileName)
handler.setLevel(logging.INFO)
handler.setFormatter(Formatter("{asctime} {levelname}: {message}", "%Y-%m-%d %H:%M:%S", style="{"))
logger.addHandler(handler)
try:
id = ItemIDValue()(sys.argv[1])
connection = Connection("connection.ini")
if connection.is_established():
if connection.deleteItem(id):
logEntry = "Das Item mit der ID %s wurde gelöscht!" % (id)
logger.info(logEntry)
print(logEntry)
except ItemIDException as error:
logEntry = "ItemIDException: " + str(error)
logger.error(logEntry)
print(logEntry)
except NotFoundException as error:
logEntry = "NotFoundException: " + str(error)
logger.error(logEntry)
print(logEntry)
except HTTPException as error:
logEntry = "HTTPException: " + str(error)
logger.error(logEntry)
print(logEntry)
except ConnectionException as error:
logEntry = "ConnectionException: " + str(error)
logger.error(logEntry)
print(logEntry)
except BaseException as error:
logEntry = "Something unexpected went wrong! " + str(error)
logger.error(logEntry)
print(logEntry)
finally:
pass
except ArgumentException as error:
print("ArgumentException: " + str(error))
finally:
pass