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. gobject.signal_new("auth_failed", Backend, gobject.SIGNAL_RUN_FIRST, None, ())
  20. gobject.signal_new('io_error', Backend, gobject.SIGNAL_RUN_FIRST, None, ())
  21.  
  22. def send_print(self, printer, username, password, page_per_page, filename, page_range, copies, orientation, sides):
  23. # Get printer name
  24. print "Selected printer: %s" % printer
  25.  
  26. # Get connection
  27. try:
  28. client = paramiko.SSHClient()
  29. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  30. except:
  31. raise PrintingError('Impossibili inizializzare paramiko')
  32.  
  33. try:
  34. client.connect('ssh.dm.unipi.it',
  35. port=22,
  36. username=username,
  37. password=password)
  38. except paramiko.AuthenticationException, e:
  39. self.emit('auth_failed')
  40. return
  41.  
  42. t = client.get_transport()
  43. sftp = paramiko.SFTPClient.from_transport(t)
  44.  
  45. print "Printing %s" % filename
  46.  
  47. # Questo è inevitabile.. :)
  48. cmd = "lpr -P%s " % printer
  49.  
  50. # Numero di pagine
  51. try:
  52. copies = int(float(copies))
  53. except ValueError:
  54. copies = 1
  55. if copies is not 1:
  56. cmd = cmd + "-# %s " % copies
  57.  
  58.  
  59. cmd_opts = ""
  60.  
  61. ## Pagine logiche per pagine
  62. if not page_per_page == 1:
  63. cmd_opts += "-o number-up=%s " % str(page_per_page)
  64.  
  65. ## Da a
  66. if not page_range == None:
  67. cmd_opts += "-o page-ranges=%s " % page_range
  68.  
  69. ## Orientazione (se è vuoto è verticale)
  70. if not orientation == "":
  71. cmd_opts += "-o %s " % orientation
  72.  
  73. ## Long edge, short edge ed amici vari
  74. cmd_opts += "-o sides=%s " % sides
  75.  
  76. ## Se ci sono opzioni dai il -o e specificale
  77. if not cmd_opts == "":
  78. cmd = cmd + "%s" % cmd_opts + " /tmp/drprint_tmp_%s" % username
  79.  
  80. attr = sftp.put(filename, "/tmp/drprint_tmp_%s" % username)
  81. print "File trasferito, dimensione: %d bytes" % attr.st_size
  82.  
  83. # Aspettiamo che il trasferimento avvenga, appena trovo
  84. # un metodo serio per farlo rimuovo questo time.sleep()
  85.  
  86. chan = t.open_session()
  87.  
  88. # Diamo il comando sul canale
  89. print "Eseguo %s" % cmd
  90. chan.exec_command(cmd)
  91.  
  92. exit_status = chan.recv_exit_status()
  93. chan.close()
  94. if exit_status == 0:
  95. sftp.remove("/tmp/drprint_tmp_%s" % username)
  96.  
  97. print "Printed %s on %s (exit status = %d)" % (filename, printer, exit_status)
  98. if exit_status != 0:
  99. raise PrintingError('Il comando <b>lpr</b> non e\' andato a buon fine (Exit status = %d)' % exit_status)