create per-project subdirs, so that one product can be in multiple projects

Change-Id: I48ddf7be1fb034fc7f51a5bc4ee311159f15d562
diff --git a/buildcollector.py b/buildcollector.py
index 7091197..8d84cfa 100644
--- a/buildcollector.py
+++ b/buildcollector.py
@@ -147,6 +147,7 @@
     """
     Write JSON file out to a path, creating directories in path as needed
     """
+    logger.debug("writing JSON file: %s", path)
 
     # create directory if it doesn't already exist
     parent_dir = os.path.dirname(path)
@@ -357,8 +358,9 @@
 
     product_data["groups"] = groups
 
-    product_filename = "%s/%s.json" % (
+    product_filename = "%s/%s/%s.json" % (
         product_dir,
+        product_doc["onf_project"],
         clean_name(product_doc["product_name"]),
     )
 
diff --git a/siterender.py b/siterender.py
index 315f8df..3ce209c 100644
--- a/siterender.py
+++ b/siterender.py
@@ -205,31 +205,34 @@
     # init list of projects
     projects = {}
 
-    # list of products
-    prodfiles = os.listdir(args.product_dir)
+    # list of projects
+    projdirs = os.listdir(args.product_dir)
 
-    for prodfile in prodfiles:
+    for projdir in projdirs:
+        prodfiles = os.listdir("%s/%s" % (args.product_dir, projdir))
 
-        # load product, and set buildtime
-        logger.debug("loading file file: '%s'", prodfile)
-        product = json_file_load("%s/%s" % (args.product_dir, prodfile))
-        product.update({"buildtime": buildtime})
+        for prodfile in prodfiles:
 
-        projname = product["onf_project"]
+            # load product, and set buildtime
+            logger.debug("loading file file: '%s'", prodfile)
+            product = json_file_load("%s/%s/%s" % (args.product_dir, projdir, prodfile))
+            product.update({"buildtime": buildtime})
 
-        # build product filename, write out template
-        site_prod_filename = "%s/%s/%s/index.html" % (
-            args.site_dir,
-            projname,
-            clean_name(product["product_name"]),
-        )
-        render_to_file(j2env, product, "product.html", site_prod_filename)
+            projname = product["onf_project"]
 
-        # product to project list
-        if projname not in projects:
-            projects[projname] = [product]
-        else:
-            projects[projname].append(product)
+            # build product filename, write out template
+            site_prod_filename = "%s/%s/%s/index.html" % (
+                args.site_dir,
+                projname,
+                clean_name(product["product_name"]),
+            )
+            render_to_file(j2env, product, "product.html", site_prod_filename)
+
+            # product to project list
+            if projname not in projects:
+                projects[projname] = [product]
+            else:
+                projects[projname].append(product)
 
     # list of projects
     for projname in sorted(projects.keys()):