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. ## Some useful function to help DrPrint to
  2. # -*- coding: utf-8 -*-
  3.  
  4. import paramiko, gobject, select, time
  5.  
  6. class PrintingError(Exception):
  7.  
  8. def __init__(self, value):
  9. self.value = value
  10.  
  11. def __str__(self):
  12. return repr(self.value)
  13.  
  14. class Backend(gobject.GObject):
  15.  
  16. def __init__(self):
  17. super(Backend, self).__init__()
  18.  
  19.  
  20. def send_print(self, printer, username, password, page_per_page, filename, page_range, copies, orientation, sides):
  21. # Get printer name
  22. print "Selected printer: %s" % printer
  23.  
  24. # Get connection
  25. try:
  26. client = paramiko.SSHClient()
  27. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  28. except:
  29. raise PrintingError('Impossibili inizializzare paramiko')
  30.  
  31. try:
  32. client.connect('ssh.dm.unipi.it',
  33. port=22,
  34. username=username,
  35. password=password)
  36. except paramiko.AuthenticationException, e:
  37. raise PrintingError('Autenticazione fallita')
  38. except Exception, e:
  39. raise PrintingError('Connessione fallita (%s)' % e)
  40.  
  41. t = client.get_transport()
  42. sftp = paramiko.SFTPClient.from_transport(t)
  43.  
  44. print "Printing %s" % filename
  45.  
  46. # Questo è inevitabile.. :)
  47. cmd = "lpr -P%s " % printer
  48.  
  49. # Numero di pagine
  50. try:
  51. copies = int(float(copies))
  52. except ValueError:
  53. copies = 1
  54. if copies is not 1:
  55. cmd = cmd + "-# %s " % copies
  56.  
  57.  
  58. cmd_opts = ""
  59.  
  60. ## Pagine logiche per pagine
  61. if not page_per_page == 1:
  62. cmd_opts += "-o number-up=%s " % str(page_per_page)
  63.  
  64. ## Da a
  65. if not page_range == None:
  66. cmd_opts += "-o page-ranges=%s " % page_range
  67.  
  68. ## Orientazione (se è vuoto è verticale)
  69. if not orientation == "":
  70. cmd_opts += "-o %s " % orientation
  71.  
  72. ## Long edge, short edge ed amici vari
  73. cmd_opts += "-o sides=%s " % sides
  74.  
  75. ## Se ci sono opzioni dai il -o e specificale
  76. if not cmd_opts == "":
  77. cmd = cmd + "%s" % cmd_opts + " /tmp/drprint_tmp_%s" % username
  78.  
  79. try:
  80. attr = sftp.put(filename, "/tmp/drprint_tmp_%s" % username)
  81. except OSError:
  82. raise PrintingError('Errore nel trasferimento del file')
  83. else:
  84. print "File trasferito, dimensione: %d bytes" % attr.st_size
  85.  
  86. # Apriamo la sessione.
  87. chan = t.open_session()
  88.  
  89. # Diamo il comando sul canale
  90. print "Eseguo %s" % cmd
  91. chan.exec_command(cmd)
  92.  
  93. exit_status = chan.recv_exit_status()
  94. chan.close()
  95. if exit_status == 0:
  96. sftp.remove("/tmp/drprint_tmp_%s" % username)
  97.  
  98. print "Printed %s on %s (exit status = %d)" % (filename, printer, exit_status)
  99. if exit_status != 0:
  100. raise PrintingError('Il comando <b>lpr</b> non e\' andato a buon fine (Exit status = %d)' % exit_status)