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