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 OptionParser
  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. try:
  21. for client in open('/etc/dsh/group/' + group, 'r'):
  22. client = client.strip()
  23. if client.strip != '' and client[0] != '#':
  24. clients.append (client)
  25. except IOError:
  26. raise IOError('Il gruppo dsh \'%s\' non esiste, nessun client trovato!' %
  27. group)
  28. return clients
  29.  
  30. def IsAlive(client):
  31. """
  32. Ritorna True se il client è acceso e risponde ai ping
  33. """
  34. alive = subprocess.call(["fping", client], stdout = subprocess.PIPE,
  35. stderr = subprocess.PIPE)
  36. return (alive == 0)
  37.  
  38. def LoadClientData(client):
  39. """
  40. Carica i dati relativi a quel determinato client. Questi
  41. sono nella forma di un dizionario con gli oggetti time e
  42. Valori True o False
  43. """
  44. data = {}
  45. try:
  46. f = open(database_directory + client, 'r')
  47. except IOError:
  48. return data
  49. for line in f:
  50. if ":" in line:
  51. (time, alive) = line.split(":")
  52. alive = ("True" in alive)
  53. data[float(time)] = alive
  54. f.close()
  55. return data
  56.  
  57. def DumpClientData(client, data):
  58. """
  59. Salva i dati relativi ad un client, eliminando quelli troppo
  60. vecchi
  61. """
  62. data = dict (filter(lambda i: (i[0] > time.time() - max_time),
  63. data.items()))
  64. f = open(database_directory + client, 'w')
  65. f.write ("\n".join( map(lambda i: ":".join(map(str, i)), data.items())))
  66. f.close()
  67.  
  68. def UpdateClientsData(client, alive):
  69. """
  70. Aggiorna i dati relativi al client inserendo l'informazione
  71. che in questo momento è acceso.
  72. """
  73. data = LoadClientData(client)
  74. data[float(time.time())] = alive
  75. DumpClientData(client, data)
  76.  
  77. def PrintStats(client):
  78. """
  79. Stampa le statistiche sul client prescelto
  80. """
  81. data = LoadClientData(client)
  82. d = data.items()
  83. d.sort()
  84. ss = 0
  85. old_time = d[0][0]
  86.  
  87. # Un piccolo integrale sul tempo della funzione
  88. # up(client)
  89. for (time_entry, up) in d[1:]:
  90. if up:
  91. ss += (time_entry - old_time)
  92. old_time = time_entry
  93. ss = ss / (d[-1:][0][0] - d[0][0])
  94.  
  95. uptime = 100.0 * ss
  96. print "Client: %s" % client
  97. print "Uptime: %3.2f %% " % uptime
  98. print "----------------------------------------------------"
  99.  
  100.  
  101.  
  102. if __name__ == "__main__":
  103.  
  104. parser = OptionParser()
  105. parser.add_option("-c", "--check", dest="check",
  106. help = "Check if clients are up and update database",
  107. action = "store_true", default=False)
  108. parser.add_option("-s", "--stats", dest="stats",
  109. help = "Print stats about collected informations",
  110. action = "store_true", default = False)
  111.  
  112. (options, args) = parser.parse_args()
  113.  
  114. if options.check:
  115. for client in LoadClients():
  116. UpdateClientsData(client, IsAlive(client))
  117.  
  118. if options.stats:
  119. try:
  120. for client in LoadClients():
  121. PrintStats(client)
  122. except Exception, e:
  123. print "Errore durante l'esecuzione!\n ==> %s" % e