Browse Source

Merge branch 'python3' of lcmstaff/xfreerdpctl into master

Alessandro De Gennaro 4 years ago
parent
commit
425db89bbd
1 changed files with 22 additions and 22 deletions
  1. 22 22
      xfreerdpctl

+ 22 - 22
xfreerdpctl

@@ -1,8 +1,8 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
-##Autore: Nicolo' Palazzini
-##Liberamente ispirato a labcalcoloctl di Elisa Aliverti (all rights reserved)
-##Ultima modifica: Maggio 2019
+## Autore: Nicolo' Palazzini
+## Liberamente ispirato a labcalcoloctl di Elisa Aliverti (all rights reserved)
+## Ultima modifica: Gennaio 2020
 
 from time import time
 start = time()
@@ -22,7 +22,7 @@ parser.add_argument( '-a', '--all', action='store_true', dest='lcm', help='All L
 parser.add_argument( '-n', nargs='+', dest='node', help='Select one or more nodes (at least one)' )
 parser.add_argument( '-1', '--lcm1', action='store_true', dest='lcm1', help='LCM1 nodes are considered' )
 parser.add_argument( '-2', '--lcm2', action='store_true', dest='lcm2', help='LCM2 nodes are considered' )
-parser.add_argument( '-v', '--version', action='version', version='%(prog)s 1.1', help='Print program version' )
+parser.add_argument( '-v', '--version', action='version', version='%(prog)s 2.0', help='Print program version' )
 
 args = parser.parse_args()
 
@@ -65,13 +65,13 @@ class Host(Thread):
             ssh = subprocess.Popen( ["ssh", "%s" % self.hostname, command], shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
             return ssh
         else:
-            print self.hostname + ' is not up.'
+            print(self.hostname + ' is not up.')
             return False
 
     def status(self):
         statuscmd = "ps aux | grep 'xfreerdp' | grep -v grep"
         ssh = self.sshcommand(statuscmd) 
-        result = [ l for l in ssh.stdout.readlines() if '/usr/bin/xfreerdp /cert-ignore /f /v:tolab.fisica.unimi.it' in l ]
+        result = [ l for l in ssh.stdout.readlines() if b'/usr/bin/xfreerdp /cert-ignore /f /v:tolab.fisica.unimi.it' in l ]
 
         if result == []:
             return False
@@ -83,11 +83,11 @@ class Host(Thread):
             if not self.running:
                 startcmd = "startx /usr/bin/xfreerdp /cert-ignore /f /v:tolab.fisica.unimi.it &> /dev/null &"
                 self.sshcommand(startcmd)
-                print 'xfreerdp started on ' + self.hostname
+                print('xfreerdp started on ' + self.hostname)
             else:
-                print 'xfreerdp is already running on ' + self.hostname
+                print('xfreerdp is already running on ' + self.hostname)
         else:
-            print self.hostname + ' is not up.'
+            print(self.hostname + ' is not up.')
 
     def xstop(self):
         if self.up:
@@ -100,11 +100,11 @@ class Host(Thread):
                              pgrep -xf "$PCMDL" && \
                              pkill -9 -xf "$PCMDL"'''
                 self.sshcommand(stopcmd)
-                print 'xfreerdp stopped on ' + self.hostname
+                print('xfreerdp stopped on ' + self.hostname)
             else:
-                print 'xfreerdp is not running on ' + self.hostname
+                print('xfreerdp is not running on ' + self.hostname)
         else:
-            print self.hostname + ' is not up.'
+            print(self.hostname + ' is not up.')
 
 Hosts = [
     Host('abe', 'LCM1'),
@@ -142,8 +142,8 @@ nodes = []
 # Show usage if no arguments
 if len(sys.argv) < 2:
 	parser.print_usage()
-	print "\nSimple tool to handle xfreerdp on LCM nodes."
-	print '\nTry: "xfreerdpctl --help" to display help message.'
+	print("\nSimple tool to handle xfreerdp on LCM nodes.")
+	print('\nTry: "xfreerdpctl --help" to display help message.')
 	sys.exit(1)
 
 # Filter hostlist according to arguments
@@ -164,7 +164,7 @@ down=[]
 
 num=len(nodes)
 index=0
-print ' Querying ' + str(num) + ' hosts...'
+print(' Querying ' + str(num) + ' hosts...')
 for i in nodes:
     # Rejoin them when their work is done
     i.join()
@@ -175,17 +175,17 @@ for i in nodes:
     index += 1
     print_progressbar(index, num)
 # New line after progress bar
-print '\n Done... (%(t).3f s)' % {'t': (time() - start)}
+print('\n Done... (%(t).3f s)' % {'t': (time() - start)})
 
 if args.cmd == 'status':
     if len(running):
-        print "xfreerdp is running on:"
-        for i in running : print '\t',i
+        print("xfreerdp is running on:")
+        for i in running : print('\t',i)
     else:
-        print "xfreerdp is not running"
+        print("xfreerdp is not running")
     if len(down):
-        print "Down nodes:"
-        for i in down :  print '\t',i
+        print("Down nodes:")
+        for i in down :  print('\t',i)
 
 elif args.cmd == 'start':
     for i in nodes: i.xstart()