Skip to content
Snippets Groups Projects
Commit 87577448 authored by Luis Araujo's avatar Luis Araujo
Browse files

Add a routine to copy css and images files


This routine will only copy files to the destination directory if
it is not in the current working directory (development dir), and
will properly update the files if they already exist.

It also will take care of creating the destination directory if
it doesn't exist.

Signed-off-by: default avatarLuis Araujo <luis.araujo@collabora.co.uk>
parent 786881af
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,22 @@ from argparse import ArgumentParser ...@@ -28,6 +28,22 @@ from argparse import ArgumentParser
from renderer import generate_test_case from renderer import generate_test_case
def copy_files(directory, dirname, msg):
"""
Only copy files if destination directory (dst_dir) is not in the cwd.
"""
dst_dir = os.path.join(directory, dirname)
if dst_dir != os.path.join(os.getcwd(), dirname):
if not os.path.isdir(dst_dir):
print("Creating directory", dst_dir)
os.mkdir(dst_dir)
print(msg, dst_dir)
files = os.listdir(dirname)
for f in files:
shutil.copy2(os.path.join(dirname, f), dst_dir)
if '__main__' == __name__: if '__main__' == __name__:
cli_parser = ArgumentParser(description="render-test-case") cli_parser = ArgumentParser(description="render-test-case")
cli_parser.add_argument('-d', '--test-case-dir', cli_parser.add_argument('-d', '--test-case-dir',
...@@ -36,7 +52,7 @@ if '__main__' == __name__: ...@@ -36,7 +52,7 @@ if '__main__' == __name__:
help="YAML file or files directory") help="YAML file or files directory")
args = cli_parser.parse_args() args = cli_parser.parse_args()
directory = '.' directory = os.getcwd()
if args.test_case_dir: if args.test_case_dir:
directory = args.test_case_dir directory = args.test_case_dir
try: try:
...@@ -60,12 +76,5 @@ if '__main__' == __name__: ...@@ -60,12 +76,5 @@ if '__main__' == __name__:
print("Total of test cases processed:", c) print("Total of test cases processed:", c)
# Copy CSS and images directory # Copy CSS and images directory
cssdir = os.path.join(directory, 'css') copy_files(directory, 'css/', "Copying css style to")
if not (os.path.exists(cssdir) and os.path.isdir(cssdir)): copy_files(directory, 'images/', "Copying images to")
print("Copying css style to", cssdir)
shutil.copytree('css/', cssdir)
imagesdir = os.path.join(directory, 'images')
if not (os.path.exists(imagesdir) and os.path.isdir(imagesdir)):
print("Copying images to", imagesdir)
shutil.copytree('images/', imagesdir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment