From 87577448077228e2a3072d272b09db56ca5f5bdb Mon Sep 17 00:00:00 2001
From: Luis Araujo <luis.araujo@collabora.co.uk>
Date: Thu, 29 Nov 2018 00:16:10 +0800
Subject: [PATCH] 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: Luis Araujo <luis.araujo@collabora.co.uk>
---
 renderer/render-test-case | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/renderer/render-test-case b/renderer/render-test-case
index ef0a47c..3748f8a 100755
--- a/renderer/render-test-case
+++ b/renderer/render-test-case
@@ -28,6 +28,22 @@ from argparse import ArgumentParser
 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__:
     cli_parser = ArgumentParser(description="render-test-case")
     cli_parser.add_argument('-d', '--test-case-dir',
@@ -36,7 +52,7 @@ if '__main__' == __name__:
                             help="YAML file or files directory")
     args = cli_parser.parse_args()
 
-    directory = '.'
+    directory = os.getcwd()
     if args.test_case_dir:
         directory = args.test_case_dir
         try:
@@ -60,12 +76,5 @@ if '__main__' == __name__:
         print("Total of test cases processed:", c)
 
     # Copy CSS and images directory
-    cssdir = os.path.join(directory, 'css')
-    if not (os.path.exists(cssdir) and os.path.isdir(cssdir)):
-        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)
+    copy_files(directory, 'css/', "Copying css style to")
+    copy_files(directory, 'images/', "Copying images to")
-- 
GitLab