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. # -*- coding: utf-8 -*-
  2. ## Some useful function to help DrPrint to
  3.  
  4. import paramiko, gobject, select, time, re
  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.  
  15. class Backend(gobject.GObject):
  16.  
  17. def __init__(self):
  18. super(Backend, self).__init__()
  19.  
  20. def get_queue(self, printer, remote_host, username, password):
  21. """
  22. Obtain the queue of jobs on selected printer. It opens an SSH
  23. connection to the server and parse lpq -Pprinter output
  24. """
  25.  
  26. try:
  27. client = paramiko.SSHClient()
  28. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  29. except:
  30. raise RuntimeError('Impossibile inizializzare paramiko')
  31.  
  32. try:
  33. client.connect(remote_host,
  34. port = 22,
  35. username = username,
  36. password = password)
  37. except:
  38. raise RuntimeError('Impossibile connettersi a %s' % remote_host)
  39.  
  40. stdin, stdout, stderr = client.exec_command("lpq -P%s" % printer)
  41. output = stdout.read()
  42.  
  43. # Parse output
  44. jobs = []
  45. for line in re.findall(r"(\d+)\w*\s+(\w+)\s+(\d+)\s+(.+)\s+(\d+) bytes",
  46. output):
  47. job = {
  48. 'position': int(line[0]),
  49. 'user': line[1],
  50. 'id': line[2],
  51. 'filename': line[3].strip(),
  52. 'size': line[4]
  53. }
  54. jobs.append(job)
  55. return jobs
  56.  
  57.  
  58.  
  59.  
  60. def send_print(self, printer, username, password, page_per_page,
  61. filename, page_range, copies, orientation, sides, remote_host):
  62.  
  63. # Get printer name
  64. print "Selected printer: %s" % printer
  65.  
  66. # Get connection
  67. try:
  68. client = paramiko.SSHClient()
  69. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  70. except:
  71. raise PrintingError('Impossibili inizializzare paramiko')
  72.  
  73. try:
  74. client.connect(remote_host,
  75. port=22,
  76. username=username,
  77. password=password)
  78. except paramiko.AuthenticationException, e:
  79. raise PrintingError('Autenticazione fallita')
  80. except Exception, e:
  81. raise PrintingError('Connessione fallita (%s)' % e)
  82.  
  83. t = client.get_transport()
  84. sftp = paramiko.SFTPClient.from_transport(t)
  85.  
  86. print "Printing %s" % filename
  87.  
  88. # Questo è inevitabile.. :)
  89. cmd = "lpr -P%s " % printer
  90.  
  91. # Numero di pagine
  92. try:
  93. copies = int(float(copies))
  94. except ValueError:
  95. copies = 1
  96. if copies is not 1:
  97. cmd = cmd + "-# %s " % copies
  98.  
  99.  
  100. cmd_opts = ""
  101.  
  102. ## Pagine logiche per pagine
  103. if not page_per_page == 1:
  104. cmd_opts += "-o number-up=%s " % str(page_per_page)
  105.  
  106. ## Da a
  107. if not page_range == None:
  108. cmd_opts += "-o page-ranges=%s " % page_range
  109.  
  110. ## Orientazione (se è vuoto è verticale)
  111. if not orientation == "":
  112. cmd_opts += "-o %s " % orientation
  113.  
  114. ## Long edge, short edge ed amici vari
  115. cmd_opts += "-o sides=%s " % sides
  116.  
  117. ## Se ci sono opzioni dai il -o e specificale
  118. if not cmd_opts == "":
  119. cmd = cmd + "%s" % cmd_opts + " /tmp/drprint_tmp_%s" % username
  120.  
  121. try:
  122. attr = sftp.put(filename, "/tmp/drprint_tmp_%s" % username)
  123. except OSError:
  124. raise PrintingError('Errore nel trasferimento del file')
  125. else:
  126. print "File trasferito, dimensione: %d bytes" % attr.st_size
  127.  
  128. # Apriamo la sessione.
  129. chan = t.open_session()
  130.  
  131. # Diamo il comando sul canale
  132. print "Eseguo %s" % cmd
  133. chan.exec_command(cmd)
  134.  
  135. exit_status = chan.recv_exit_status()
  136. chan.close()
  137. if exit_status == 0:
  138. sftp.remove("/tmp/drprint_tmp_%s" % username)
  139.  
  140. print "Printed %s on %s (exit status = %d)" % (filename, printer, exit_status)
  141. if exit_status != 0:
  142. raise PrintingError('Il comando <b>lpr</b> non e\' andato a buon fine (Exit status = %d)' % exit_status)