forked from opencast/helper-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·94 lines (70 loc) · 3.03 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
""" This module contains the main method. """
import logging
import sys
import os
sys.path.append(os.path.join(os.path.abspath('..'), "lib"))
from input.check_recovery_start import check_recovery_start
from input.parse_args import parse_args
from recover.find_media_packages import find_media_packages
from args.url_builder import DEFAULT_TENANT, URLBuilder
from data_handling.errors import MediaPackageError
from data_handling.parse_manifest import parse_manifest_from_filesystem
from import_mp.import_mp import import_mp
from rest_requests.request_error import RequestError
def main():
"""
Parse the arguments, get media packages for recovery and check these for correctness before attempting to recover
them.
"""
# parse arguments
opencast, https, digest_login, backup, media_packages, tenant, workflow_id, last_version, rsync_history_path, \
ignore_errors = parse_args()
logging.basicConfig(filename='errors.log', level=logging.ERROR, filemode="w")
# print info
if not tenant:
print("No tenant provided, using default tenant.")
tenant = DEFAULT_TENANT
if not rsync_history_path:
print("No path to rsync history provided.")
if last_version:
print("Always using last version of media packages.")
if ignore_errors:
print("Ignoring media package errors")
# init
url_builder = URLBuilder(opencast, https)
base_url = url_builder.get_base_url(tenant)
# get paths to media packages to be recovered
mps_to_recover = find_media_packages(backup, tenant, last_version, rsync_history_path, media_packages)
if not mps_to_recover:
__abort_script("There are no media packages that can be recovered.")
# check if these should be recovered
start_recovery = check_recovery_start(mps_to_recover, media_packages)
if not start_recovery:
__abort_script("Okay, not recovering anything.")
# start recovery
print("Starting recovery process.")
for mp in mps_to_recover:
try:
# parse manifest
mp = parse_manifest_from_filesystem(mp, ignore_errors)
workflow = import_mp(mp.series_id, mp.tracks, mp.catalogs, mp.attachments, base_url, digest_login,
workflow_id, {}, ignore_errors)
print("Recovered media package {} (new id: {}) and started workflow {} with id {}.".
format(mp.id, workflow.mp_id, workflow.template, workflow.id))
except MediaPackageError as e:
print("Media package {} could not be recovered: {}".format(mp.id, str(e)))
except RequestError as e:
print("Media package {} could not be recovered: {}".format(mp.id, e.error))
except Exception as e:
print("Media package {} could not be recovered: {}".format(mp.id, str(e)))
print("Finished.")
def __abort_script(message):
print(message)
sys.exit()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("\nAborting script.")
sys.exit(0)