Index: scripts/nfs/puppetlastgroups
===================================================================
--- scripts/nfs/puppetlastgroups	(revision 336)
+++ scripts/nfs/puppetlastgroups	(revision 337)
@@ -31,9 +31,15 @@
 
 from datetime import datetime, timedelta
 
-total_count=0
+total_certs=0
+total_elements=0
+total_withoutCert=0
+total_studentsLaptopsCerts=0
+total_studentsLaptopsWithoutCerts=0
 all_hosts=[]
 all_certs=[]
+isPrinting=True
+onlyHead=False
 
 def humanize(delta):
     days = delta.days
@@ -78,7 +84,7 @@
 
 # Muestra en pantalla la info de la sincronizacion con codigo de colores
 def printtimes(times):
-    global all_hosts
+    global all_hosts, isPrinting, onlyHead
 
     RED = '\033[91m'
     GREEN = '\033[92m'
@@ -86,13 +92,15 @@
     RESET = '\033[0m'
     for time in reversed(sorted(times, key=lambda x: x[2])):
         all_hosts.append(time[1])
-        if time[2] < timedelta(hours=24):
-            print GREEN, "%10s ago: %s" % (time[0], time[1]), RESET
-        elif time[2] < timedelta(hours=239):
-            print ORANGE, "%10s ago: %s" % (time[0], time[1]), RESET
-        else:
-            print RED, "%10s ago: %s" % (time[0], time[1]), RESET
 
+        if not onlyHead:
+            if time[2] < timedelta(hours=24) and isPrinting:
+                print GREEN, "%10s ago: %s" % (time[0], time[1]), RESET
+            elif time[2] < timedelta(hours=239) and isPrinting:
+                print ORANGE, "%10s ago: %s" % (time[0], time[1]), RESET
+            elif isPrinting:
+                print RED, "%10s ago: %s" % (time[0], time[1]), RESET
+
 def formatList(search):
     from operator import itemgetter, attrgetter
     data=[]
@@ -126,7 +134,7 @@
 # Rutina principal
 def puppetlast(times,search):
     import pdb
-    global total_count
+    global total_certs, total_elements, total_withoutCert, isPrinting
     RED = '\033[91m'
     RESET = '\033[0m'
 
@@ -149,13 +157,16 @@
                         without_cert.append(a)
 
                 if len(times_temp)>1:
-                    print "\n- "+curso+" ("+str(len(alumnos))+" elementos) ("+str(len(times_temp))+" certificados)"
+                    if isPrinting:
+                        print "\n- "+curso+" ("+str(len(alumnos))+" elementos) ("+str(len(times_temp))+" certificados)"
                     if len(without_cert)>1:
                         for w in without_cert:
-                            if w!="":
+                            if w!="" and isPrinting and not onlyHead:
                                 print RED, "Sin certificado: "+w, RESET
 
-                    total_count=total_count+len(times_temp)
+                    total_certs=total_certs+len(times_temp)
+                    total_withoutCert=total_withoutCert+len(without_cert)
+                    total_elements=total_elements+len(alumnos)
                     printtimes(times_temp)
 
 def ldapSearch(baseDN,filter,retrieveAttributes):
@@ -187,27 +198,37 @@
     return { 'onlyInList1':onlyInList1, 'onlyInList2':onlyInList2, 'inTwoLists':inTwoLists }
 
 
-grupo=""
-t=gettimes()
+def printHelp():
+    print "Modo de empleo: puppetlastgroups [OPCION] [AULA]\n"
+    print "	-g			todos los grupos"
+    print "	-g 1ESOA		un grupo concreto"
+    print "	-s			servidores de aula"
+    print "	-p			portatiles de profesores"
+    print "	-w			workstations"
+    print "	-n			no registrados en LDAP"
+    print "	-a			todo"
+    print "	-e			estadisticas"
+    print "	--help		ayuda"
 
-if len (sys.argv)==2:
-    grupo=sys.argv[1]
-    filter="(&(groupType=school_class)(cn="+grupo+"))"
-else:
-    filter="(&(groupType=school_class))"
+def printGroups():
+    global t
+    if len (sys.argv)==3:
+        filter="(&(groupType=school_class)(cn="+sys.argv[2]+"))"
+    else:
+        filter="(&(groupType=school_class))"
 
-search  = ldapSearch("ou=Group",filter,["memberUid"])
+    search  = ldapSearch("ou=Group",filter,["memberUid"])
+    data = formatList(search)
+    puppetlast(t,data)
 
-data = formatList(search)
-puppetlast(t,data)
-
-if grupo=="":
-    # Servidores de aula
+def printLTSPServers():
+    global t
     search  = ldapSearch("cn=ltsp-server-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
     data = formatOtherList(search,"LTSP-Servers")
     puppetlast(t,data)
 
-    # Portatiles de profesores. Debera tener la rama Netgroup->laptop-hosts
+def printWorkstations():
+    global t
     try:
         search  = ldapSearch("cn=workstation-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
         data = formatOtherList(search,"Workstations")
@@ -215,8 +236,9 @@
     except:
         pass
 
-
-    # Portatiles de profesores. Debera tener la rama Netgroup->laptop-hosts
+# Portatiles de profesores. Debera tener la rama Netgroup->laptop-hosts
+def printTeacherLaptops():
+    global t
     try:
         search  = ldapSearch("cn=laptop-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
         data = formatOtherList(search,"Portatiles profesores")
@@ -224,13 +246,86 @@
     except:
         pass
 
-    # Equipos desconocidos
-    cmp=cmpLists(all_hosts, all_certs)
-    list=[]
-    for c in cmp["onlyInList2"]:
-        list.append(c.split(".")[0])
+# Equipos desconocidos
+def printUnknown():
+    global all_certs, all_hosts, t
+
+    comp=cmpLists(all_hosts, all_certs)
+    l=[]
+    for c in comp["onlyInList2"]:
+        l.append(c.split(".")[0])
     unknown=[]
-    unknown.append(("No registrados en LDAP (con certificado)",list))
+    unknown.append(("No registrados en LDAP (con certificado)",l))
     puppetlast(t,unknown)
 
-print "\nTotal certificados: "+str(total_count)
+def printStatistics():
+    global total_certs, total_elements, total_withoutCert, total_studentsLaptopsCerts, studentsLaptopsWithoutCerts
+
+    print "\n############################################################"
+
+    if total_studentsLaptopsCerts!=0:
+        print "\nPortatiles alumnos:"
+        print "   - Total certificados: "+str(total_studentsLaptopsCerts)
+        print "   - Total sin certificado: "+str(total_studentsLaptopsWithoutCerts)
+
+    print "\nTotal certificados: "+str(total_certs)
+    print "Total sin certificado: "+str(total_withoutCert)
+    print "Total elementos: "+str(total_elements)+"\n"
+
+t=gettimes()
+
+if len (sys.argv)<2:
+    printHelp()
+    exit()
+
+if sys.argv[1] == "-g":
+    printGroups()
+    printStatistics()
+
+elif sys.argv[1] == "-s":
+    printLTSPServers()
+    printStatistics()
+
+elif sys.argv[1] == "-w":
+    printWorkstations()
+    printStatistics()
+
+elif sys.argv[1] == "-p":
+    printTeacherLaptops()
+    printStatistics()
+
+elif sys.argv[1] == "-n":
+    isPrinting=False
+    printGroups()
+    printLTSPServers()
+    printWorkstations()
+    printTeacherLaptops()
+    isPrinting=True
+    printUnknown()
+
+elif sys.argv[1] == "-a":
+    printGroups()
+    printLTSPServers()
+    printWorkstations()
+    printTeacherLaptops()
+    printUnknown()
+    printStatistics()
+
+elif sys.argv[1] == "-e":
+    onlyHead=True
+    printGroups()
+    total_studentsLaptopsCerts=total_certs
+    total_studentsLaptopsWithoutCerts=total_withoutCert
+    printLTSPServers()
+    printWorkstations()
+    printTeacherLaptops()
+    printUnknown()
+    printStatistics()
+
+elif sys.argv[1] == "--help":
+    printHelp()
+    exit()
+
+else:
+    printHelp()
+    exit()
