Aggiunto controllo delle eccezioni.

Leonardo Robol [2010-04-17 10:16]
Aggiunto controllo delle eccezioni.
Filename
phcstats.py
diff --git a/phcstats.py b/phcstats.py
index 6525948..651fefc 100755
--- a/phcstats.py
+++ b/phcstats.py
@@ -17,10 +17,14 @@ def LoadClients(group = 'all'):
     gruppo group di dsh. Il default è 'all'
     """
     clients = []
-    for client in open('/etc/dsh/group/' + group, 'r'):
-        client = client.strip()
-        if client.strip != '' and client[0] != '#':
-            clients.append (client)
+    try:
+        for client in open('/etc/dsh/group/' + group, 'r'):
+            client = client.strip()
+            if client.strip != '' and client[0] != '#':
+                clients.append (client)
+    except IOError:
+        raise IOError('Il gruppo dsh \'%s\' non esiste, nessun client trovato!' %
+                      group)
     return clients

 def IsAlive(client):
@@ -112,5 +116,8 @@ if __name__ == "__main__":
             UpdateClientsData(client, IsAlive(client))

     if options.stats:
-        for client in LoadClients():
-            PrintStats(client)
+        try:
+            for client in LoadClients():
+                PrintStats(client)
+        except Exception, e:
+            print "Errore durante l'esecuzione!\n ==> %s" % e
ViewGit