|
3 | 3 | """Simple backup application.""" |
4 | 4 |
|
5 | 5 | import os |
6 | | -import time |
7 | 6 | import argparse |
| 7 | +import shutil |
| 8 | +import hashlib |
8 | 9 | from pathlib import Path |
9 | 10 | import tkinter as tk |
10 | 11 | from tkinter import ttk |
11 | 12 | from tkinter import filedialog |
12 | 13 | from PIL import Image, ImageTk |
13 | 14 | import yaml |
14 | | -import shutil |
15 | | -import hashlib |
16 | 15 |
|
17 | 16 | import tk_async_execute as tae |
18 | 17 |
|
@@ -138,7 +137,6 @@ def __init__(self, project: str): |
138 | 137 |
|
139 | 138 | # load project |
140 | 139 | items = self.load_project() |
141 | | - print(f'{items}') |
142 | 140 | for item in items: |
143 | 141 | name = item['name'] |
144 | 142 | itemtype = item['type'] |
@@ -270,42 +268,45 @@ def start_backup(self): |
270 | 268 | path = item['values'][1] |
271 | 269 | items.append({'name': name, 'type': itemtype, 'path': path}) |
272 | 270 | self.progressbar.start() |
273 | | - tae.async_execute(self.do_backup(items, folder), callback=self.finish_backup, wait=False, visible=False) |
| 271 | + tae.async_execute(self.do_backup(items, folder), |
| 272 | + callback=self.finish_backup, wait=False, visible=False) |
274 | 273 |
|
| 274 | + # pylint: disable-next=too-many-locals |
275 | 275 | async def do_backup(self, items, folder): |
276 | 276 | """Performs the actual backup""" |
277 | 277 | # get file list |
278 | 278 | if os.listdir(folder): |
279 | | - print(f'error: folder is not empty') |
| 279 | + print('error: folder is not empty') |
280 | 280 | return |
281 | 281 |
|
282 | 282 | files = [] |
283 | 283 | for item in items: |
284 | 284 | itemtype = item['type'] |
285 | 285 | if itemtype == 'Folder': |
286 | 286 | path = item['path'] |
287 | | - for dir, dname, fnames in os.walk(item['path']): |
288 | | - targetdir = dir[len(os.path.commonpath([path, dir])):] |
| 287 | + for dirname, _, fnames in os.walk(item['path']): |
| 288 | + targetdir = dirname[len(os.path.commonpath([path, dirname])):] |
289 | 289 | if targetdir.startswith('/'): |
290 | 290 | targetdir = targetdir[1:] |
291 | 291 | targetdir = os.path.join(item['name'], targetdir) |
292 | 292 | for fname in fnames: |
293 | | - source = os.path.join(dir, fname) |
| 293 | + source = os.path.join(dirname, fname) |
294 | 294 | target = os.path.join(targetdir, fname) |
295 | 295 | files.append({'source': source, 'target': target}) |
296 | 296 | elif itemtype == 'File': |
297 | 297 | files.append({'source': item['path'], 'target': item['name']}) |
298 | 298 |
|
299 | | - with open(os.path.join(folder, 'checksums.txt'), 'w', newline='\n', encoding='utf-8') as checksum_file: |
| 299 | + with open(os.path.join(folder, 'checksums.txt'), 'w', |
| 300 | + newline='\n', encoding='utf-8') as checksum_file: |
300 | 301 | for file in files: |
301 | 302 | source = file['source'] |
302 | 303 | rel_target = file['target'] |
303 | | - target = os.path.join(folder, rel_target) |
| 304 | + target = os.path.join(folder, rel_target) |
304 | 305 | os.makedirs(os.path.dirname(target), exist_ok=True) |
305 | 306 | shutil.copy2(source, target) |
306 | 307 | with open(target, 'rb') as f: |
307 | 308 | digest = hashlib.file_digest(f, "sha256") |
308 | | - checksum_file.write(f'SHA256 ({rel_target}) = {digest.hexdigest()}\n') |
| 309 | + checksum_file.write(f'SHA256 ({rel_target}) = {digest.hexdigest()}\n') |
309 | 310 |
|
310 | 311 | def on_closing(self): |
311 | 312 | """Saves the project when the application is closed.""" |
|
0 commit comments