viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Monitora se i computer dell'aula studenti sono accesi
  5. # e restituisce delle statistiche a proposito.
  6.  
  7. import subprocess, time
  8. from optparse import OptionsParser
  9.  
  10. # Qualche variabile globale
  11. database_directory = '/home/robol/client_stats/' # Il traling slash ci serve
  12. max_time = 86400 * 10 # 10 giorni
  13.  
  14. def LoadClients(group = 'all'):
  15. """
  16. Ritorna una lista con tutti i client all'interno del
  17. gruppo group di dsh. Il default è 'all'
  18. """
  19. clients = []
  20. for client in open('/etc/dsh/group/' + group, 'r'):
  21. client = client.strip()
  22. if client.strip != '' and client[0] != '#':
  23. clients.append (client)
  24. return clients
  25.  
  26. def IsAlive(client):
  27. """
  28. Ritorna True se il client è acceso e risponde ai ping
  29. """
  30. alive = subprocess.call(["fping", client])
  31. return (alive == 0)
  32.  
  33. def LoadClientData(client):
  34. """
  35. Carica i dati relativi a quel determinato client. Questi
  36. sono nella forma di un dizionario con gli oggetti time e
  37. Valori True o False
  38. """
  39. data = {}
  40. try:
  41. f = open(database_directory + client, 'r')
  42. except IOError:
  43. return data
  44. for line in f:
  45. (time, alive) = line.split(":")
  46. data[time] = alive
  47. f.close()
  48. return data
  49.  
  50. def DumpClientData(client, data):
  51. """
  52. Salva i dati relativi ad un client, eliminando quelli troppo
  53. vecchi
  54. """
  55. data = dict (filter(lambda i: (i[0] > time.time() - max_time),
  56. data.items()))
  57. f = open(database_directory + client, 'w')
  58. for stat in data.items():
  59. f.write (":".join(map(str, stat)))
  60. f.close()
  61.  
  62. def UpdateClientsData(client, alive):
  63. """
  64. Aggiorna i dati relativi al client inserendo l'informazione
  65. che in questo momento è acceso.
  66. """
  67. data = LoadClientData(client)
  68. data[time.time()] = alive
  69. DumpClientData(client, data)
  70.  
  71. def PrintStats(client):
  72. """
  73. Stampa le statistiche sul client prescelto
  74. """
  75. data = LoadClientData(client)
  76. uptime = len(filter(lambda s: (s==True), data))/ float(len(filter))
  77. print "Uptime: %3.3f (%s)" % (100 * uptime, client)
  78.  
  79.  
  80.  
  81.  
  82. if __name__ == "__main__":
  83.  
  84. parser = OptionParser()
  85. parser.add_option("-c", "--check", dest="check",
  86. help = "Check if clients are up and update database",
  87. action = "store_true", default=True)
  88. parser.add_option("-s", "--stats", dest="stats",
  89. help = "Print stats about collected informations",
  90. action = "store_true", default = False)
  91.  
  92. (options, args) = parser.parse_args()
  93.  
  94. if options.check:
  95. for client in LoadClients():
  96. UpdateClientsData(client, IsAlive(client))
  97.  
  98. if options.stats:
  99. for client in LoadClients():
  100. PrintStats(client)