Debian Codegraph @

src/plugins/fd/kubernetes-backend/baculak8s/jobs/listing_job.py

raw
1 # -*- coding: UTF-8 -*-
2 # Bacula(R) - The Network Backup Solution
3 #
4 # Copyright (C) 2000-2022 Kern Sibbald
5 #
6 # The original author of Bacula is Kern Sibbald, with contributions
7 # from many others, a complete list can be found in the file AUTHORS.
8 #
9 # You may use this file and others of this release according to the
10 # license defined in the LICENSE file, which includes the Affero General
11 # Public License, v3.0 ("AGPLv3") and some additional permissions and
12 # terms pursuant to its AGPLv3 Section 7.
13 #
14 # This notice must be preserved when any source code is
15 # conveyed and/or propagated.
16 #
17 # Bacula(R) is a registered trademark of Kern Sibbald.
18
19 import logging
20
21 from baculak8s.io.default_io import DefaultIO
22 from baculak8s.jobs.job import Job
23 from baculak8s.util.respbody import parse_json_descr
24
25 LISTING_START = "ListingStart"
26 LISTING_EMPTY_RESULT = "Listing returned an empty result"
27 LISTING_ERROR_RESPONSE = "Listing returned error response: {}"
28
29
30 class ListingJob(Job):
31 """
32 Job that contains the business logic
33 related to the listing mode of the Backend.
34 It depends upon a Plugin Class implementation
35 that retrieves listing data from the Plugins Data Source
36 """
37
38 def __init__(self, plugin, params):
39 super().__init__(plugin, DefaultIO(), params)
40
41 def execute(self):
42 self._start(LISTING_START)
43 self.execution_loop()
44 self._io.send_eod()
45
46 def execution_loop(self):
47 self.__listing_loop()
48
49 def __listing_loop(self):
50 found_any = False
51 file_info_list = self._plugin.list_in_path(self._params["listing"])
52 if isinstance(file_info_list, dict) and 'error' in file_info_list:
53 logging.warning(file_info_list)
54 self._io.send_warning(LISTING_ERROR_RESPONSE.format(parse_json_descr(file_info_list)))
55 else:
56 for file_info in file_info_list:
57 found_any = True
58 self._io.send_file_info(file_info_list.get(file_info).get('fi'))
59
60 if not found_any:
61 self._io.send_warning(LISTING_EMPTY_RESULT)