|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | from backedup import Constants |
| 4 | +from backedup import Backup |
4 | 5 |
|
5 | 6 | import datetime |
| 7 | +import json |
6 | 8 | import logging |
7 | 9 | import os |
8 | | -import shutil |
9 | | - |
10 | 10 |
|
11 | 11 | def main(): |
12 | 12 | logging.basicConfig(filename='backedup.log', level=logging.INFO) |
13 | | - create_backedup_folder() |
14 | | - if not did_backup_today(): |
| 13 | + json_configs = get_config_json_file() |
| 14 | + backup = Backup(json_configs) |
| 15 | + backup.create_backedup_folder() |
| 16 | + if not backup.did_backup_today(): |
15 | 17 | backup_directory = create_backup_directory() |
16 | | - create_backup(backup_directory) |
| 18 | + backup.start_backup(backup_directory) |
17 | 19 | print(Constants.DONE) |
18 | 20 |
|
| 21 | +def get_config_json_file(self): |
| 22 | + """ |
| 23 | + get_config_json_file |
19 | 24 |
|
20 | | -def create_backedup_folder(): |
21 | | - if os.path.isdir(Constants.DEST_FOLDER): |
22 | | - print(Constants.FOLDER_EXIST) |
23 | | - return True |
24 | | - else: |
25 | | - os.mkdir(Constants.DEST_FOLDER) |
26 | | - |
27 | | - |
28 | | -def did_backup_today(): |
29 | | - dest_folder_list = os.listdir(Constants.DEST_FOLDER) |
30 | | - for folder in dest_folder_list: |
31 | | - if str(datetime.date.today()) in folder: |
32 | | - print(Constants.OUTPUT_FOLDER_EXIST) |
33 | | - return True |
34 | | - else: |
35 | | - print(Constants.STARTING_UPDATE) |
36 | | - return False |
37 | | - |
38 | | - |
39 | | -def create_backup(backup_directory): |
40 | | - shutil.copytree(src=Constants.SRC_FOLDER, |
41 | | - dst=backup_directory, |
42 | | - ignore=_logpath) |
43 | | - |
| 25 | + - Gets the config JSON file and returns the output |
| 26 | + """ |
| 27 | + logging.info("Current directory: " + os.getcwd()) |
| 28 | + logging.info("Loading JSON config file.") |
| 29 | + with open(Constants.CONFIG_LOCATION, 'r') as file: |
| 30 | + return json.load(file) |
44 | 31 |
|
45 | 32 | def create_backup_directory(): |
| 33 | + """ |
| 34 | + create_backup_directory |
| 35 | + """ |
46 | 36 | backup_directory = Constants.DEST_FOLDER + \ |
47 | 37 | Constants.NEW_UPDATE_FOLDER + str(datetime.date.today()) |
48 | 38 | if os.path.isdir(backup_directory): |
49 | 39 | print(Constants.OUTPUT_FOLDER_EXIST) |
50 | 40 | return backup_directory |
51 | 41 |
|
52 | | - |
53 | | -def _logpath(path, names): |
54 | | - logging.info('Copying %s' % path) |
55 | | - return [] |
56 | | - |
57 | | - |
58 | 42 | if __name__ == "__main__": |
59 | 43 | main() |
0 commit comments