From 1c11df5e5742104418d6a2e5580263e599a8dea7 Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Wed, 4 May 2016 11:37:26 +0000
Subject: [PATCH] Added get_lib_names_from_lib_dicts(), check_library_names()
 and command line options --run, --lib.

---
 tools/oneclick/base/hdl_config.py | 38 +++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/tools/oneclick/base/hdl_config.py b/tools/oneclick/base/hdl_config.py
index dacffcfdb8..c01e9a8f6a 100644
--- a/tools/oneclick/base/hdl_config.py
+++ b/tools/oneclick/base/hdl_config.py
@@ -50,7 +50,6 @@
 import common as cm
 import common_dict_file
 import sys
-import os
 import os.path
 import shutil
 from distutils.dir_util import copy_tree
@@ -118,6 +117,15 @@ class HdlConfig:
             self.lib_names = self.libs.get_key_values('hdl_lib_name')
             
 
+    def check_library_names(self, check_lib_names, lib_names=None):
+        """Check that HDL library names exists, if not then exit with Error message."""
+        if lib_names==None:
+            lib_names=self.lib_names
+        for check_lib_name in cm.listify(check_lib_names):
+            if check_lib_name not in cm.listify(lib_names):
+                sys.exit('Error : Unknown HDL library name %s found with check_lib_name()' % check_lib_name)
+            
+            
     def get_used_libs(self, build_type, lib_dict, arg_include_ip_libs=[]):
         """Get the list of used HDL libraries from the lib_dict. Which libraries are actually used depends on the build_type:
            
@@ -263,6 +271,13 @@ class HdlConfig:
             lib_dict = self.libs.dicts[self.lib_names.index(lib_name)]
             lib_dicts.append(lib_dict)
         return lib_dicts
+
+        
+    def get_lib_names_from_lib_dicts(self, lib_dicts=None):
+        """Get list the HDL libraries lib_names from list of HDL libraries lib_dicts and preseve the library order.
+        """
+        lib_names = self.libs.get_key_values('hdl_lib_name', lib_dicts)
+        return lib_names
         
 
     def get_tool_build_dir(self, build_type):
@@ -387,13 +402,24 @@ class HdlParseArgs:
     def __init__(self, toolsetSelect):
         # Parse command line arguments
         argparser = argparse.ArgumentParser(description='HDL config command line parser arguments')
-        argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False)
-        argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False)
+        argparser.add_argument('-t','--toolset', required=False, help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0])
+        argparser.add_argument('-l','--lib', default=None, required=False, help='library names separated by commas')
+        argparser.add_argument('-r','--run', required=False, action='store_true', default=False, help='run command')
+        argparser.add_argument('-v','--verbosity', required=False, type=int, default=0, help='verbosity >= 0 for more info')
         args = vars(argparser.parse_args())
     
+        # Keep the argparser for external access of e.g. print_help
+        self.argparser = argparser
+        
         # Keep arguments in class record
         self.toolset = args['toolset']
         
+        self.lib_names = []
+        if args['lib']!=None:
+            self.lib_names = args['lib'].split(',')
+        
+        self.run = args['run']
+        
         if self.toolset not in toolsetSelect:
             print 'Toolset %s is not supported' % self.toolset
             print 'Hint: give argument -h for possible options'
@@ -415,7 +441,7 @@ if __name__ == '__main__':
     
     # Parse command line arguments
     hdl_args = HdlParseArgs(toolsetSelect=['unb1', 'unb2', 'unb2a'])
-        
+    
     # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
     hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=hdl_args.toolFileName)
     
@@ -478,6 +504,10 @@ if __name__ == '__main__':
             print ''
             print 'derive_lib_order for %s of %s = \n' % (build_type, top_lib), hdl.derive_lib_order(build_type, top_lib)
     
+        print ''
+        print 'Help: use -h'
+        hdl_args.argparser.print_help()
+        
     if mode==1:
         key = 'build_dir'
         new_value = '$HDL_BUILD_DIR'
-- 
GitLab