2021-06-08 12:37:10 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import shutil
|
|
|
|
import os
|
2021-07-31 20:49:38 +02:00
|
|
|
from fsfwgen.core import get_console_logger
|
|
|
|
LOGGER = get_console_logger()
|
2021-06-08 12:37:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def copy_file(filename: str, destination: str = "", delete_existing_file: bool = False):
|
2021-07-31 20:49:38 +02:00
|
|
|
if not os.path.exists(filename):
|
|
|
|
LOGGER.warning(f'File {filename} does not exist')
|
|
|
|
return
|
|
|
|
if not os.path.exists(destination):
|
|
|
|
LOGGER.warning(f'Destination directory {destination} does not exist')
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
shutil.copy2(filename, destination)
|
|
|
|
except FileNotFoundError:
|
|
|
|
LOGGER.exception('File not found!')
|
|
|
|
except shutil.SameFileError:
|
|
|
|
LOGGER.exception('Source and destination are the same!')
|
2021-06-08 12:37:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def move_file(file_name: str, destination: str = ""):
|
2021-07-31 20:07:41 +02:00
|
|
|
if not os.path.exists(file_name):
|
|
|
|
print(f'move_file: File {file_name} does not exist')
|
|
|
|
return
|
|
|
|
if not os.path.exists(destination):
|
|
|
|
print(f'move_file: Destination directory {destination} does not exist')
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
shutil.copy2(file_name, destination)
|
|
|
|
os.remove(file_name)
|
|
|
|
return
|
2021-07-31 20:49:38 +02:00
|
|
|
except FileNotFoundError:
|
|
|
|
LOGGER.exception('File not found!')
|
|
|
|
except shutil.SameFileError:
|
|
|
|
LOGGER.exception('Source and destination are the same!')
|