home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / prnt / cups.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  5.8 KB  |  185 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import os
  5. import os.path as os
  6. import gzip
  7. import re
  8. import time
  9. import urllib
  10. import tempfile
  11. import glob
  12. from base.g import *
  13. import cupsext
  14. mfg_pat = re.compile('\\*\\s*Manufacturer:\\s*\\".*?(.*?)\\"', re.IGNORECASE)
  15. model_pat = re.compile('\\*\\s*Product:\\s*\\"\\(.*?(.*?)\\)\\"', re.IGNORECASE)
  16. IPP_PRINTER_STATE_IDLE = 3
  17. IPP_PRINTER_STATE_PROCESSING = 4
  18. IPP_PRINTER_STATE_STOPPED = 5
  19.  
  20. def restartCUPS():
  21.     os.system('killall -HUP cupsd')
  22.  
  23.  
  24. def getPPDPath(addtional_paths = []):
  25.     search_paths = [
  26.         prop.ppd_search_path.split(';')] + addtional_paths
  27.     for path in search_paths:
  28.         ppd_path = os.path.join(path, 'cups/model')
  29.         if os.path.exists(ppd_path):
  30.             return ppd_path
  31.             continue
  32.     
  33.  
  34.  
  35. def collectPPDs(ppd_path):
  36.     utils = utils
  37.     import base
  38.     ppds = { }
  39.     for f in utils.walkFiles(ppd_path, recurse = True, abs_paths = True, return_folders = False, pattern = prop.ppd_search_pattern):
  40.         if f.endswith('.gz'):
  41.             g = gzip.open(f, 'r')
  42.         else:
  43.             g = open(f, 'r')
  44.         
  45.         try:
  46.             d = g.read(4096)
  47.         except IOError:
  48.             g.close()
  49.             continue
  50.  
  51.         
  52.         try:
  53.             mfg = mfg_pat.search(d).group(1).lower()
  54.         except ValueError:
  55.             g.close()
  56.             continue
  57.  
  58.         if mfg != 'hp':
  59.             continue
  60.         
  61.         
  62.         try:
  63.             model = model_pat.search(d).group(1).replace(' ', '_')
  64.         except ValueError:
  65.             g.close()
  66.             continue
  67.  
  68.         ppds[model] = f
  69.         g.close()
  70.     
  71.     return ppds
  72.  
  73.  
  74. def downloadPPD(lporg_model_name, driver = 'hpijs', url = prop.ppd_download_url):
  75.     u = urllib.urlopen(url, urllib.urlencode({
  76.         'driver': driver,
  77.         'printer': urllib.quote(lporg_model_name),
  78.         'show': '0' }))
  79.     ppd_file = os.path.join(tempfile.gettempdir(), lporg_model_name + prop.ppd_file_suffix)
  80.     f = file(ppd_file, 'w')
  81.     f.write(u.read())
  82.     f.close()
  83.     return ppd_file
  84.  
  85.  
  86. def getAllowableMIMETypes():
  87.     files = glob.glob('/etc/cups/*.convs')
  88.     allowable_mime_types = []
  89.     for f in files:
  90.         conv_file = file(f, 'r')
  91.         for line in conv_file:
  92.             if not line.startswith('#') and len(line) > 1:
  93.                 
  94.                 try:
  95.                     (source, dest, cost, prog) = line.split()
  96.                 except ValueError:
  97.                     continue
  98.  
  99.                 allowable_mime_types.append(source)
  100.                 continue
  101.         
  102.     
  103.     return allowable_mime_types
  104.  
  105.  
  106. def getDefault():
  107.     return cupsext.getDefault()
  108.  
  109.  
  110. def openPPD(printer):
  111.     return cupsext.openPPD(printer)
  112.  
  113.  
  114. def closePPD():
  115.     return cupsext.closePPD()
  116.  
  117.  
  118. def getPPD(printer):
  119.     return cupsext.getPPD(printer)
  120.  
  121.  
  122. def getPPDOption(option):
  123.     return cupsext.getPPDOption(option)
  124.  
  125.  
  126. def getPPDPageSize():
  127.     return cupsext.getPPDPageSize()
  128.  
  129.  
  130. def getPrinters():
  131.     return cupsext.getPrinters()
  132.  
  133.  
  134. def getJobs(my_job = 0, completed = 0):
  135.     return cupsext.getJobs(my_job, completed)
  136.  
  137.  
  138. def getAllJobs(my_job = 0):
  139.     return cupsext.getJobs(my_job, 0) + cupsext.getJobs(my_job, 1)
  140.  
  141.  
  142. def getVersion():
  143.     return cupsext.getVersion()
  144.  
  145.  
  146. def getServer():
  147.     return cupsext.getServer()
  148.  
  149.  
  150. def cancelJob(jobid, dest = None):
  151.     if dest is not None:
  152.         return cupsext.cancelJob(dest, jobid)
  153.     else:
  154.         jobs = cupsext.getJobs(0, 0)
  155.         for j in jobs:
  156.             if j.id == jobid:
  157.                 return cupsext.cancelJob(j.dest, jobid)
  158.                 continue
  159.         
  160.     return False
  161.  
  162.  
  163. def resetOptions():
  164.     return cupsext.resetOptions()
  165.  
  166.  
  167. def addOption(option):
  168.     return cupsext.addOption(option)
  169.  
  170.  
  171. def printFile(printer, filename, title):
  172.     if os.path.exists(filename):
  173.         return cupsext.printFileWithOptions(printer, filename, title)
  174.     else:
  175.         return -1
  176.  
  177.  
  178. def addPrinter(printer_name, device_uri, location, ppd_file, info):
  179.     return cupsext.addPrinter(printer_name, device_uri, location, ppd_file, info)
  180.  
  181.  
  182. def delPrinter(printer_name):
  183.     return cupsext.delPrinter(printer_name)
  184.  
  185.