From 327b05574f0dc1b1046c72401256ce5afd3e3247 Mon Sep 17 00:00:00 2001
From: Marcel Telka <marcel@telka.sk>
Date: Tue, 02 Apr 2024 11:21:42 +0200
Subject: [PATCH] python/PyNUTClient: update to 2.8.2

---
 tools/gen-components |  104 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 86 insertions(+), 18 deletions(-)

diff --git a/tools/gen-components b/tools/gen-components
index 36d8273..19ee8d9 100755
--- a/tools/gen-components
+++ b/tools/gen-components
@@ -19,11 +19,11 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2012, Oracle and/or it's affiliates.  All rights reserved.
+# Copyright (c) 2012, 2013, Oracle and/or it's affiliates.  All rights reserved.
 #
 #
-# gen_components.py
-# A simple program to generate (on stdout) the component.html web page 
+# gen_components
+# A simple script to generate (on stdout), the component.html web page 
 # found at: http://userland.us.oracle.com/components.html
 #
 
@@ -33,7 +33,13 @@
 
 debug = False
 
-# Hashtable of RE's / RM's keyed by component path.
+# TPNO string to search for in each .p5m file.
+TPNO_str = "com.oracle.info.tpno"
+
+# Hashtable of components with TPNOs keyed by component name.
+comp_TPNOs = {}
+
+# Hashtable of RE's, RM's and Teams keyed by component path.
 owners = {}
 
 # Initial HTML for the generated web page.
@@ -82,8 +88,10 @@
     <th>Package(s)</th>
     <th>ARC Case(s)</th>
     <th>License(s)</th>
+    <th>TPNO</th>
     <th>RE</th>
     <th>RM</th>
+    <th>Team</th>
 </tr>
 </thead>
 <tbody>
@@ -98,7 +106,7 @@
 </html>
 """
 
-# Return a hashtable of RE's / RM's keyed by component path.
+# Return a hashtable of RE's, RM's and Teams keyed by component path.
 def read_owners(owners_file):
     if debug:
         print >> sys.stderr, "Reading %s" % owners_file
@@ -113,10 +121,59 @@
     owners = {}
     for line in lines:
         line = line[:-1]
-        component, re, rm = line.split("|")
-        owners[component] = [ re, rm ]
+        component, re, rm, team = line.split("|")
+        owners[component] = [ re, rm, team ]
 
     return owners
+
+# Return a hashtable of components with TPNOs keyed by component name.
+def find_TPNOs(workspace):
+    comp_TPNOs = {}
+    for directory, _, files in os.walk(workspace + "/components"):
+        for filename in files:
+            if filename.endswith(".p5m"):
+                pathname = os.path.join(directory, filename)
+                fin = open(pathname, 'r')
+                lines = fin.readlines()
+                fin.close()
+
+                for line in lines:
+                    line = line.replace("\n", "")
+                    n = line.find(TPNO_str)
+                    if n != -1:
+                        tpno_str = line[n:].split("=")[1]
+                        try:
+                            # Check that the TPNO is a valid number.
+                            tpno = int(tpno_str)
+                            if debug:
+                                print >> sys.stderr, "TPNO: %s: %s" % \
+                                    (directory, tpno_str)
+                            comp_TPNOs[directory] = tpno_str
+                        except:
+                            # Check to see if line end in a "\" character in
+                            # which case, it's an attribute rather than an
+                            # set name action, so extract it a different way.
+                            try:
+                                n += len(TPNO_str)+1
+                                tpno_str = line[n:].split()[0]
+                                # Check that the TPNO is a valid number.
+                                tpno = int(tpno_str)
+                                if debug:
+                                    print >> sys.stderr, "TPNO: %s: %s" % \
+                                        (directory, tpno_str)
+
+                                # If it's an attribute, there might be more
+                                # than one TPNO for this component.
+                                if directory in comp_TPNOs:
+                                    entry = comp_TPNOs[directory]
+                                    tpno_str = "%s,%s" % (entry, tpno_str)
+
+                                comp_TPNOs[directory] = tpno_str
+                            except:
+                                print >> sys.stderr, \
+                                    "Unable to read TPNO: %s" % pathname
+
+    return(comp_TPNOs)
 
 # Return a sorted list of the directories containing one or more .p5m files.
 def find_p5m_dirs(workspace):
@@ -132,9 +189,9 @@
 def write_preamble():
     print preamble
 
-# Return the RE / RM for this component.
-def get_re_and_rm(p5m_dir):
-    re_and_rm = [ "Unknown", "Unknown" ]
+# Return the RE,  RM and Team for this component.
+def get_owner(p5m_dir):
+    result = [ "Unknown", "Unknown", "Unknown" ]
     component_path = ""
     started = False
     tokens = p5m_dir.split("/")
@@ -145,12 +202,12 @@
             started = True
     component_path = component_path[:-1]
     if component_path in owners:
-        re_and_rm = owners[component_path]
+        result = owners[component_path]
     if debug:
         print >> sys.stderr, "Component path: ", component_path,
-        print >> sys.stderr, "RE / RM: ", re_and_rm
+        print >> sys.stderr, "RE, RM, Team: ", result
     
-    return re_and_rm
+    return result
 
 # Generate an HTML table entry for all the information for the component
 # in the given directory. This generates a file called 'component-report'
@@ -159,11 +216,21 @@
     if debug:
         print >> sys.stderr, "Processing %s" % component_dir
 
-    re, rm = get_re_and_rm(component_dir)
+    try:
+        tpno = comp_TPNOs[component_dir]
+    except:
+        tpno = ""
+
+    re, rm, team = get_owner(component_dir)
     makefiles = "-f Makefile -f %s/make-rules/component-report" % workspace
     targets = "clean component-hook"
-    cmd = "cd %s; RESPONSIBLE_ENGINEER='%s' RESPONSIBLE_MANAGER='%s' gmake COMPONENT_HOOK='gmake %s component-report' %s" % \
-        (component_dir, re, rm, makefiles, targets)
+    template = "cd %s; "
+    template += "TPNO='%s' "
+    template += "RESPONSIBLE_ENGINEER='%s' "
+    template += "RESPONSIBLE_MANAGER='%s' "
+    template += "TEAM='%s' "
+    template += "gmake COMPONENT_HOOK='gmake %s component-report' %s"
+    cmd = template % (component_dir, tpno, re, rm, team, makefiles, targets)
 
     if debug:
         print >> sys.stderr, "gen_reports: command: `%s`" % cmd
@@ -193,7 +260,7 @@
     print  >> sys.stderr, \
 """
 Usage: 
-      update_man_pages.py [OPTION...]
+      gen-components [OPTION...]
 
 -d, --debug
       Turn on debugging
@@ -210,7 +277,7 @@
 
 if __name__ == "__main__":
     workspace = os.getenv('WS_TOP')
-    owners_file = "/net/userland.us.oracle.com/gates/private/RM-RE-list.txt"
+    owners_file = "/net/userland.us.oracle.com/gates/private/RE-RM-list.txt"
 
     try:
         opts, args = getopt.getopt(sys.argv[1:], "do:w:",
@@ -231,6 +298,7 @@
  
     owners = read_owners(owners_file)
     write_preamble()
+    comp_TPNOs = find_TPNOs(workspace)
     p5m_dirs = find_p5m_dirs(workspace)
     for p5m_dir in p5m_dirs:
         gen_reports(workspace, p5m_dir)

--
Gitblit v1.9.3