Aggiunto supporto per altri gruppi.

Leonardo [2010-04-17 10:23]
Aggiunto supporto per altri gruppi.
Filename
phcstats.py
diff --git a/phcstats.py b/phcstats.py
index 651fefc..810687b 100755
--- a/phcstats.py
+++ b/phcstats.py
@@ -4,21 +4,23 @@
 # Monitora se i computer dell'aula studenti sono accesi
 # e restituisce delle statistiche a proposito.

-import subprocess, time
+import subprocess, time, os
 from optparse import OptionParser

 # Qualche variabile globale
 database_directory = '/home/robol/client_stats/' # Il traling slash ci serve
 max_time = 86400 * 10 # 10 giorni
+group = '/etc/dsh/group/all'

-def LoadClients(group = 'all'):
+def LoadClients():
     """
     Ritorna una lista con tutti i client all'interno del
     gruppo group di dsh. Il default è 'all'
     """
+    global group
     clients = []
     try:
-        for client in open('/etc/dsh/group/' + group, 'r'):
+        for client in open(group, 'r'):
             client = client.strip()
             if client.strip != '' and client[0] != '#':
                 clients.append (client)
@@ -108,8 +110,11 @@ if __name__ == "__main__":
     parser.add_option("-s", "--stats", dest="stats",
                       help = "Print stats about collected informations",
                       action = "store_true", default = False)
+    parser.add_option("-g", "--group-file", dest="group_file",
+                      help="The dsh group file to use", default='/etc/dsh/group/all')

     (options, args) = parser.parse_args()
+    group = os.path.expand_user(options.group_file)

     if options.check:
         for client in LoadClients():
ViewGit