very simply version
This commit is contained in:
24
game_backuper/file.py
Normal file
24
game_backuper/file.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from collections import namedtuple
|
||||
from os.path import exists, dirname, abspath
|
||||
from os import stat, makedirs
|
||||
from game_backuper.hashl import sha512
|
||||
from shutil import copy2
|
||||
|
||||
|
||||
File = namedtuple('File', ['id', 'file', 'size', 'program', 'hash'])
|
||||
|
||||
|
||||
def copy_file(loc: str, dest: str, name: str, prog: str):
|
||||
d = dirname(abspath(dest))
|
||||
if not exists(d):
|
||||
makedirs(d)
|
||||
r = copy2(loc, dest)
|
||||
print(f'{prog}: Copyed {loc}({name}) -> {r}')
|
||||
|
||||
|
||||
def new_file(loc: str, name: str, prog: str) -> File:
|
||||
if exists(loc):
|
||||
fs = stat(loc).st_size
|
||||
with open(loc, 'rb') as f:
|
||||
hs = sha512(f)
|
||||
return File(None, name, fs, prog, hs)
|
||||
Reference in New Issue
Block a user