|
@@ -128,7 +128,7 @@ def create_tlsa_hash(cert):
|
|
|
return hexdigest
|
|
|
|
|
|
|
|
|
-def copy_file(source, destination):
|
|
|
+def copy_file(source, destination, backup=True):
|
|
|
"""
|
|
|
Copies a file from the given source file to
|
|
|
the given destionation and creates a copy of the
|
|
@@ -136,28 +136,31 @@ def copy_file(source, destination):
|
|
|
|
|
|
:param source: source file path
|
|
|
:type source: str
|
|
|
- :param destination: destionation file path
|
|
|
+ :param destination: destination file path
|
|
|
:type destination: str
|
|
|
+ :param backup: whether to take a backup of the destination file before \
|
|
|
+ overwriting it
|
|
|
+ :type backup: bool
|
|
|
:return: success
|
|
|
:rtype: bool
|
|
|
"""
|
|
|
- backup_file = source + ".bak_%s" % datetime.datetime.now().strftime(
|
|
|
+ backup_file = destination + ".bak_%s" % datetime.datetime.now().strftime(
|
|
|
"%Y%m%d%H%M%S")
|
|
|
+ if backup:
|
|
|
+ try:
|
|
|
+ shutil.copy(destination, backup_file)
|
|
|
+ except IOError:
|
|
|
+ LOGGER.error("Creating of backup file for %s failed!", source)
|
|
|
+ return False
|
|
|
try:
|
|
|
- shutil.copy(source, backup_file)
|
|
|
+ shutil.copy(source, destination)
|
|
|
except IOError:
|
|
|
- LOGGER.error("Creating of backup file for %s failed!", source)
|
|
|
- return False
|
|
|
+ LOGGER.error("Copying of file %s to %s failed!",
|
|
|
+ source, destination)
|
|
|
else:
|
|
|
- try:
|
|
|
- shutil.copy(source, destination)
|
|
|
- except IOError:
|
|
|
- LOGGER.error("Copying of file %s to %s failed!",
|
|
|
- source, destination)
|
|
|
- else:
|
|
|
- os.chmod(destination, 0o0644)
|
|
|
- os.chown(destination, 0, 0)
|
|
|
- return True
|
|
|
+ os.chmod(destination, 0o0644)
|
|
|
+ os.chown(destination, 0, 0)
|
|
|
+ return True
|
|
|
|
|
|
|
|
|
def get_tsig_key():
|