Browse Source

Merge branch 'python3' of lcmstaff/whoall into master

Port to python3
simonepirota 4 years ago
parent
commit
394a0e1eca
2 changed files with 26 additions and 24 deletions
  1. 1 0
      lcm_w
  2. 25 24
      whoall

+ 1 - 0
lcm_w

@@ -1,4 +1,5 @@
 #!/bin/bash
+# In the current LCM cluster this file is symlinked by /usr/local/bin/lcm_w, which is used by inetd on port 79
 
 who | awk '{ print $1,$2 }'
 

+ 25 - 24
whoall

@@ -1,11 +1,11 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 # - *- coding: utf- 8 - *-
 #
 # Python whoall: parallel, multi-threaded version
 # First author: jacopogh - nov 2006
 # Modified and updated by admins & 150 over time
 #
-# Last modified: May 2019 - nicolopalazzini
+# Last modified: January 2020 - matteobonamassa
 
 
 from time import time
@@ -39,13 +39,13 @@ parser.add_argument('-f', '--full', action='store_true', dest='full',
                     help='display all nodes including empty, \
                     unreachable and unavailable')
 parser.add_argument('-m', '--math', action='store_true', dest='math',
-                    help='only Mathematica hosts ')
+                    help='only display Mathematica hosts ')
 parser.add_argument('-n', action='store_true', dest='n',
                     help='not display the progressbar and colors')
 parser.add_argument('-N', action='store_true', dest='N',
                     help='also display number of logs')
 parser.add_argument('-v', '--version', action='version',
-                    version='%(prog)s 2.2', help='print program version')
+                    version='%(prog)s 3.0', help='print program version')
 
 # Parse arguments
 args = parser.parse_args()
@@ -115,7 +115,7 @@ class Node(Thread):
         # Read data
         lista=''
         reachable=0
-        try: lista = self.conn.read_until("EOF",1)
+        try: lista = self.conn.read_until(b"EOF",1)
         except EOFError: reachable=1
         del self.conn
 
@@ -130,7 +130,7 @@ class Node(Thread):
 
         # Local-remote-god user check
         for x in righe:
-            fields = x.split()
+            fields = x.decode('utf-8').split()
 
             if "tty" in fields[1]:
                 if fields[0] in gods:
@@ -220,10 +220,10 @@ class Node(Thread):
                 strchuck += str(item) +' '
 
         # Print out hostname and connected users
-        print ' ' + self.qualifiedname() + ' '*(15-len(self.qualifiedname())) \
+        print(' ' + self.qualifiedname() + ' '*(15-len(self.qualifiedname())) \
                 + red + strlgod + normal + pink + strrgod + normal + green \
                 + strlocal + normal + blue + strremote + normal \
-                + turquoise + strchuck + normal
+                + turquoise + strchuck + normal)
 ### end class Node
 
 
@@ -335,7 +335,7 @@ for node in nodes:
 
 # Used for progressbar
 index = 0
-print ' Querying ' + str(num) + ' hosts...'
+print(' Querying ' + str(num) + ' hosts...')
 
 # Rejoin them when their work is done
 # NB a progress bar does not make much sense if join is not asynchronous (blue)
@@ -352,7 +352,7 @@ for node in nodes:
 
 if progressbar:
     # Newline
-    print '\n Done... (%(t).3f s)' % {'t': (time() - start)}
+    print('\n Done... (%(t).3f s)' % {'t': (time() - start)})
 
 if args.full or args.math or args.cuda:
 # Save down/unreachable/unavailable nodes to separate lists
@@ -382,37 +382,38 @@ cudanodes = [ node for node in nodes if node.location == 'CUDA' ]
 
 # Print out
 if len(lcm1nodes):
-    print splitters['LCM1']
+    print(splitters['LCM1'])
     for node in lcm1nodes:
         node.printlist()
 if len(lcm2nodes):
-    print splitters['LCM2']
+    print(splitters['LCM2'])
     for node in lcm2nodes:
         node.printlist()
 if len(cudanodes):
-    print splitters['CUDA']
+    print(splitters['CUDA'])
     for node in cudanodes:
         node.printlist()
 
+print("")
+
 # Some final output
-if progressbar > 0:
-    print
-    print 'Legenda: ' + green + 'utente locale '+ normal \
+if progressbar:
+    print('Legenda: ' + green + 'utente locale '+ normal \
           + blue + 'utente remoto ' + normal + red + 'admin locale ' + normal \
-          + pink + 'admin remoto ' + normal + turquoise + 'nirvana' + normal
+          + pink + 'admin remoto ' + normal + turquoise + 'nirvana' + normal)
     # FIXME I don't think we need this. Cuda nodes have their own section
     # print "         I nodi contrassegnati con [C] sono i nodi CUDA."
     if args.math:
-        print "         I nodi contrassegnati con [M4] hanno Mathematica 4.0"
-        print "         I nodi contrassegnati con [M5] hanno Mathematica 5.2"
-    print
+        print("         I nodi contrassegnati con [M4] hanno Mathematica 4.0")
+        print("         I nodi contrassegnati con [M5] hanno Mathematica 5.2")
+    print("")
 
 # Only in full mode
 if args.full or args.math or args.cuda:
-    print red+'Empty: '+normal+emptylist
-    print red+'Timeout: '+normal+timeoutlist
-    print red+'Unreachable: '+normal+downlist
-    print red+'Unavailable: '+normal+unavlist
+    print(red+'Empty: '+normal+emptylist)
+    print(red+'Timeout: '+normal+timeoutlist)
+    print(red+'Unreachable: '+normal+downlist)
+    print(red+'Unavailable: '+normal+unavlist)
 
 # Exit gracefully
 exit(0)