]>
Commit | Line | Data |
---|---|---|
f33494aa JS |
1 | #!/usr/bin/python3 |
2 | ||
3 | import logging | |
4 | import os | |
5 | ||
6 | logger = logging.getLogger("nitsi.settings") | |
7 | ||
8 | class SettingsException(Exception): | |
9 | def __init__(self, message): | |
10 | self.message = message | |
11 | ||
12 | def settings_parse_copy_from(copy_from, path=None): | |
13 | logger.debug("Going to parse the copy_from setting.") | |
14 | ||
15 | # Check if we already get a list: | |
16 | if not isinstance(copy_from, list): | |
17 | copy_from = copy_from.split(" ") | |
18 | ||
19 | tmp = [] | |
20 | for file in copy_from: | |
21 | file = file.strip() | |
22 | # If file is empty we do not want to add it to the list | |
23 | if not file == "": | |
24 | # If we get an absolut path we do nothing | |
25 | # If not we add self.path to get an absolut path | |
26 | if not os.path.isabs(file): | |
27 | if path: | |
28 | file = os.path.normpath(path + "/" + file) | |
29 | else: | |
30 | file = os.path.abspath(file) | |
31 | ||
32 | logger.debug("Checking if '{}' is a valid file or dir".format(file)) | |
33 | # We need to check if file is a valid file or dir | |
34 | if not (os.path.isdir(file) or os.path.isfile(file)): | |
35 | raise SettingsException("'{}' is not a valid file nor a valid directory".format(file)) | |
36 | ||
37 | logger.debug("'{}' will be copied into all images".format(file)) | |
38 | tmp.append(file) | |
39 | ||
40 | return tmp |