I have a python service which at some point, will copy a directory from one location to another. When the service first runs, it raises an error "[Errno 2] No such file or directory"
reporting the destination as the issue.
[Errno 2] No such file or directory: u'/opt/app/Gemfile.lock'
I'm not expecting the destination to be there, because I haven't copied it yet. Reading the documentation for distutils it says that if a path doesn't exist, it will make it for you.
#! /usr/bin/env python
import distutils.core
import os
files = []
file = {}
file['source'] = "/origin/folder"
file['destination'] = "/destionation/folder"
files.append(file)
def copy_files(files, logger):
for file in files:
if file['source'].startswith('/'):
source = os.path.join(deployment.archive_dir, file['source'][1:])
else:
source = os.path.join(deployment.archive_dir, file['source'])
if os.path.isdir(source):
distutils.dir_util.copy_tree(source, file['destination'])
else:
if not os.path.isdir(file['destination']):
distutils.dir_util.mkpath(file['destination'])
distutils.file_util.copy_file(source, file['destination'])
copy_files(files)
This is the line that is throwing:
distutils.dir_util.copy_tree(source, file['destination'])