Преглед на файлове

replace os.system(cp) with shutil.copyfile

master
myitinos преди 4 години
родител
ревизия
8c1c0081f0
променени са 1 файла, в които са добавени 3 реда и са изтрити 4 реда
  1. +3
    -4
      clone.py

+ 3
- 4
clone.py Целия файл

@ -5,6 +5,7 @@ import logging
import string
import hashlib
import time
import shutil
class Cloner:
@ -34,8 +35,7 @@ class Cloner:
targetFileContent = targetFile.read()
realHash = hashlib.md5(targetFileContent).hexdigest()
if realHash != cloneHashFileContent:
os.system('cp {backup} {real}'.format(
backup=cloneFileName, real=targetFileName))
shutil.copyfile(cloneFileName, targetFileName)
logging.warning(
'{file} failed check, restoring...'.format(file=targetFileName))
else:
@ -43,8 +43,7 @@ class Cloner:
else:
logging.warning(
'{file} is a new file, added to backup dir'.format(file=targetFileName))
os.system('cp {real} {clone}'.format(
real=targetFileName, clone=cloneFileName))
shutil.copyfile(targetFileName, cloneFileName)
with open(cloneHashFileName, 'w') as cloneHashFile, open(targetFileName, 'rb') as targetFile:
targetFileContent = targetFile.read()
cloneHashFile.write(hashlib.md5(targetFileContent).hexdigest())

Зареждане…
Отказ
Запис