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