Add check for existence of src and dst file
This commit is contained in:
parent
f267efa66b
commit
f58ea58bd6
21
copy-cert.py
21
copy-cert.py
|
@ -19,6 +19,9 @@ http_pool = urllib3.PoolManager()
|
|||
class InvalidConfigException(Exception):
|
||||
pass
|
||||
|
||||
class FileNotExistsException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class CopyEntry:
|
||||
def __init__(self, d: Dict):
|
||||
|
@ -46,15 +49,21 @@ class Config:
|
|||
self.certs.append(CertEntry(cert_d))
|
||||
|
||||
def copyFile(src: str, dst: str):
|
||||
src_mtime = os.path.getmtime(src)
|
||||
dst_mtime = os.path.getmtime(dst)
|
||||
if not os.path.exists(src):
|
||||
raise FileNotExistsException('Src file not exists: {}'.format(src))
|
||||
|
||||
if src_mtime > dst_mtime:
|
||||
if not os.path.exists(os.path.dirname(dst)):
|
||||
raise FileNotExistsException('Direcotyr of dst not exists: {}'.format(dst))
|
||||
|
||||
is_dst_exists = os.path.exists(dst)
|
||||
src_mtime = os.path.getmtime(src)
|
||||
dst_mtime = os.path.getmtime(dst) if is_dst_exists else 0
|
||||
|
||||
if is_dst_exists and src_mtime < dst_mtime:
|
||||
logger.info('Skipping file: {} --> {}'.format(src, dst))
|
||||
else:
|
||||
logger.info('Copying file: {} --> {}'.format(src, dst))
|
||||
shutil.copyfile(src, dst)
|
||||
else:
|
||||
logger.info('Skipping file: {} --> {}'.format(src, dst))
|
||||
|
||||
|
||||
def copyCert(entry: CertEntry):
|
||||
copyFile(entry.priv.src, entry.priv.dst)
|
||||
|
|
Loading…
Reference in a new issue