autotest: fix warning about deprecated distutils.dir_utils.copy_tree

This commit is contained in:
Peter Barker 2022-11-24 11:10:32 +11:00 committed by Randy Mackay
parent 8e30685896
commit 89061930ac

View File

@ -10,6 +10,11 @@ from __future__ import print_function
import atexit import atexit
import fnmatch import fnmatch
import copy import copy
try:
import distutils.dir_util
except ImportError:
# we copy with this with try/except in copy_tree, below
pass
import glob import glob
import optparse import optparse
import os import os
@ -20,7 +25,6 @@ import subprocess
import sys import sys
import time import time
import traceback import traceback
from distutils.dir_util import copy_tree
import rover import rover
import arducopter import arducopter
@ -661,6 +665,13 @@ class TestResults(object):
f.write(badge) f.write(badge)
def copy_tree(f, t, dirs_exist_ok=False):
try:
distutils.dir_util.copy_tree(f, t)
except Exception:
shutil.copytree(f, t, dirs_exist_ok=dirs_exist_ok)
def write_webresults(results_to_write): def write_webresults(results_to_write):
"""Write webpage results.""" """Write webpage results."""
t = mavtemplate.MAVTemplate() t = mavtemplate.MAVTemplate()
@ -671,7 +682,7 @@ def write_webresults(results_to_write):
f.close() f.close()
for f in glob.glob(util.reltopdir('Tools/autotest/web/*.png')): for f in glob.glob(util.reltopdir('Tools/autotest/web/*.png')):
shutil.copy(f, buildlogs_path(os.path.basename(f))) shutil.copy(f, buildlogs_path(os.path.basename(f)))
copy_tree(util.reltopdir("Tools/autotest/web/css"), buildlogs_path("css")) copy_tree(util.reltopdir("Tools/autotest/web/css"), buildlogs_path("css"), dirs_exist_ok=True)
results_to_write.generate_badge() results_to_write.generate_badge()