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.  
  39. t = client.get_transport()
  40. sftp = paramiko.SFTPClient.from_transport(t)
  41.  
  42. print "Printing %s" % filename
  43.  
  44. # Questo è inevitabile.. :)
  45. cmd = "lpr -P%s " % printer
  46.  
  47. # Numero di pagine
  48. try:
  49. copies = int(float(copies))
  50. except ValueError:
  51. copies = 1
  52. if copies is not 1:
  53. cmd = cmd + "-# %s " % copies
  54.  
  55.  
  56. cmd_opts = ""
  57.  
  58. ## Pagine logiche per pagine
  59. if not page_per_page == 1:
  60. cmd_opts += "-o number-up=%s " % str(page_per_page)
  61.  
  62. ## Da a
  63. if not page_range == None:
  64. cmd_opts += "-o page-ranges=%s " % page_range
  65.  
  66. ## Orientazione (se è vuoto è verticale)
  67. if not orientation == "":
  68. cmd_opts += "-o %s " % orientation
  69.  
  70. ## Long edge, short edge ed amici vari
  71. cmd_opts += "-o sides=%s " % sides
  72.  
  73. ## Se ci sono opzioni dai il -o e specificale
  74. if not cmd_opts == "":
  75. cmd = cmd + "%s" % cmd_opts + " /tmp/drprint_tmp_%s" % username
  76.  
  77. try:
  78. attr = sftp.put(filename, "/tmp/drprint_tmp_%s" % username)
  79. except OSError:
  80. raise PrintingError('Errore nel trasferimento del file')
  81. else:
  82. print "File trasferito, dimensione: %d bytes" % attr.st_size
  83.  
  84. # Apriamo la sessione.
  85. chan = t.open_session()
  86.  
  87. # Diamo il comando sul canale
  88. print "Eseguo %s" % cmd
  89. chan.exec_command(cmd)
  90.  
  91. exit_status = chan.recv_exit_status()
  92. chan.close()
  93. if exit_status == 0:
  94. sftp.remove("/tmp/drprint_tmp_%s" % username)
  95.  
  96. print "Printed %s on %s (exit status = %d)" % (filename, printer, exit_status)
  97. if exit_status != 0:
  98. raise PrintingError('Il comando <b>lpr</b> non e\' andato a buon fine (Exit status = %d)' % exit_status)