From 40e4fb0a6a563e38e19a7da81ba78609e1d35f7b Mon Sep 17 00:00:00 2001
From: Pieter Donker <donker@astron.nl>
Date: Tue, 25 Jul 2017 15:00:39 +0000
Subject: [PATCH] Task #893: now default help, and documentation of one or more
 peripheral and system

---
 tools/oneclick/prestudy/YAML/args_demo.py     |  7 ++-
 .../prestudy/YAML/args_documentation.py       | 57 ++++++++++++-------
 .../prestudy/YAML/uniboard_rom_system_info.py |  5 +-
 3 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/tools/oneclick/prestudy/YAML/args_demo.py b/tools/oneclick/prestudy/YAML/args_demo.py
index 8fea23933f..e146f26ed7 100755
--- a/tools/oneclick/prestudy/YAML/args_demo.py
+++ b/tools/oneclick/prestudy/YAML/args_demo.py
@@ -78,14 +78,17 @@ if __name__ == "__main__":
 
     # Parse command line arguments
     parser = argparse.ArgumentParser(description="""
-    =Args demo=\r
+    =Args demo= 
     system and peripheral config command line parser arguments
     """)
     parser.add_argument('-p','--peripheral', nargs='*', default=[], help="peripheral names separated by spaces")
     parser.add_argument('-s','--system', nargs='*', default=[], help="system names separated by spaces")
     parser.add_argument('-v','--verbosity', default='INFO', help="verbosity level can be [ERROR | WARNING | INFO | DEBUG]")
     args = parser.parse_args()
-        
+
+    if not args.peripheral and not args.system:
+        parser.print_help()
+
     unit_logger.set_stdout_log_level(args.verbosity)
     logger.debug("Used arguments: {}".format(args))
 
diff --git a/tools/oneclick/prestudy/YAML/args_documentation.py b/tools/oneclick/prestudy/YAML/args_documentation.py
index 4d92dc1d0e..3d400f495c 100755
--- a/tools/oneclick/prestudy/YAML/args_documentation.py
+++ b/tools/oneclick/prestudy/YAML/args_documentation.py
@@ -34,6 +34,7 @@ import argparse
 import subprocess
 import traceback
 import yaml
+import time
 from subprocess import CalledProcessError
 from pylatex import Document, Section, Subsection, Command, Package, Tabular, MultiColumn, MultiRow, SmallText, LargeText
 from pylatex.utils import italic, bold, NoEscape, verbatim, escape_latex
@@ -45,27 +46,42 @@ import common as cm
 def main():
     try:
         for systemname in args.system:
-            system_filename = "./systems/{}.system.yaml".format(systemname)
-            config = yaml.load(open(system_filename, "r"))
-            name = config['system_name']
-            documentation = Documentation(name)
-            system = System(system_filename)
-            documentation.add(config['system_name'], system)
-            documentation.generate_pdf()
+            try:
+                system_filename = "./systems/{}.system.yaml".format(systemname)
+                config = yaml.load(open(system_filename, "r"))
+                name = config['system_name']
+                documentation = Documentation(name)
+                system = System(system_filename)
+                documentation.add(config['system_name'], system)
+                documentation.generate_pdf()
+                del documentation
+                del system
+                time.sleep(1.0)
+            except CalledProcessError:
+                pass
         
         for peripheralname in args.peripheral:
-            peripheral_filename = "./peripherals/{}.peripheral.yaml".format(peripheralname)    
-            config = yaml.load(open(peripheral_filename, "r"))
-            name = config['hdl_library_name']
-            documentation = Documentation(name)
-            peripheral = Peripheral(peripheral_filename)
-            peripheral.eval_peripheral()
-            documentation.add(config['hdl_library_name'], peripheral)
-            documentation.generate_pdf()
+            try:
+                peripheral_filename = "./peripherals/{}.peripheral.yaml".format(peripheralname)    
+                logger.info("Load peripheral(s) from '%s'", peripheral_filename)
+                config = yaml.load(open(peripheral_filename, "r"))
+                name = config['hdl_library_name']
+                for peripheral_config in config['peripherals']:
+                    peripheral = Peripheral(peripheral_config)
+                    logger.info("  read peripheral '%s'" % peripheral.component_name())
+                    peripheral.eval_peripheral()
+                    documentation = Documentation(name)
+                    peripheral.eval_peripheral()
+                    documentation.add(config['hdl_library_name'], peripheral)
+                    documentation.generate_pdf()
+                del documentation
+                del system
+                time.sleep(1.0)
+            except CalledProcessError:
+                pass    
+
     except IOError:
         logger.error("config file '{}' does not exist".format(filename))
-    except CalledProcessError:
-        pass
 
 class Documentation(object):
     """ make documentation for system or peripheral(s)
@@ -121,7 +137,7 @@ class Documentation(object):
 
     def add_peripheral(self, header, data):
         """ add a peripheral to the document """
-        self.add_section(data.get_name(), data.get_description() )
+        self.add_section(data.name(), data.get_description() )
 
     def add_system(self, header, data):
         """ add a system to the document """
@@ -309,7 +325,10 @@ if __name__ == "__main__":
     parser.add_argument('-p','--peripheral', nargs='*', default=[], help="peripheral names separated by spaces")
     parser.add_argument('-v','--verbosity', default='INFO', help="verbosity level can be [ERROR | WARNING | INFO | DEBUG]")
     args = parser.parse_args()
-        
+
+    if not args.peripheral and not args.system:
+        parser.print_help()
+
     unit_logger.set_stdout_log_level(args.verbosity)
     logger.debug("Used arguments: {}".format(args))
 
diff --git a/tools/oneclick/prestudy/YAML/uniboard_rom_system_info.py b/tools/oneclick/prestudy/YAML/uniboard_rom_system_info.py
index 7a533fb612..cf81589bb3 100644
--- a/tools/oneclick/prestudy/YAML/uniboard_rom_system_info.py
+++ b/tools/oneclick/prestudy/YAML/uniboard_rom_system_info.py
@@ -412,7 +412,10 @@ if __name__ == "__main__":
     parser.add_argument('-q','--qsys', action='store_true', default=False, help="Use start address from QSYS reg file")
     parser.add_argument('-v','--verbosity', default='INFO', help="verbosity = [INFO | DEBUG]")
     args = parser.parse_args()
-        
+
+    if not args.peripheral and not args.system:
+        parser.print_help()
+
     unit_logger.set_stdout_log_level(args.verbosity)
     logger.debug("Used arguments: {}".format(args))
 
-- 
GitLab