home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import os
- import os.path as os
- import gzip
- import re
- import time
- import urllib
- import tempfile
- import glob
- from base.g import *
- import cupsext
- mfg_pat = re.compile('\\*\\s*Manufacturer:\\s*\\".*?(.*?)\\"', re.IGNORECASE)
- model_pat = re.compile('\\*\\s*Product:\\s*\\"\\(.*?(.*?)\\)\\"', re.IGNORECASE)
- IPP_PRINTER_STATE_IDLE = 3
- IPP_PRINTER_STATE_PROCESSING = 4
- IPP_PRINTER_STATE_STOPPED = 5
-
- def restartCUPS():
- os.system('killall -HUP cupsd')
-
-
- def getPPDPath(addtional_paths = []):
- search_paths = [
- prop.ppd_search_path.split(';')] + addtional_paths
- for path in search_paths:
- ppd_path = os.path.join(path, 'cups/model')
- if os.path.exists(ppd_path):
- return ppd_path
- continue
-
-
-
- def collectPPDs(ppd_path):
- utils = utils
- import base
- ppds = { }
- for f in utils.walkFiles(ppd_path, recurse = True, abs_paths = True, return_folders = False, pattern = prop.ppd_search_pattern):
- if f.endswith('.gz'):
- g = gzip.open(f, 'r')
- else:
- g = open(f, 'r')
-
- try:
- d = g.read(4096)
- except IOError:
- g.close()
- continue
-
-
- try:
- mfg = mfg_pat.search(d).group(1).lower()
- except ValueError:
- g.close()
- continue
-
- if mfg != 'hp':
- continue
-
-
- try:
- model = model_pat.search(d).group(1).replace(' ', '_')
- except ValueError:
- g.close()
- continue
-
- ppds[model] = f
- g.close()
-
- return ppds
-
-
- def downloadPPD(lporg_model_name, driver = 'hpijs', url = prop.ppd_download_url):
- u = urllib.urlopen(url, urllib.urlencode({
- 'driver': driver,
- 'printer': urllib.quote(lporg_model_name),
- 'show': '0' }))
- ppd_file = os.path.join(tempfile.gettempdir(), lporg_model_name + prop.ppd_file_suffix)
- f = file(ppd_file, 'w')
- f.write(u.read())
- f.close()
- return ppd_file
-
-
- def getAllowableMIMETypes():
- files = glob.glob('/etc/cups/*.convs')
- allowable_mime_types = []
- for f in files:
- conv_file = file(f, 'r')
- for line in conv_file:
- if not line.startswith('#') and len(line) > 1:
-
- try:
- (source, dest, cost, prog) = line.split()
- except ValueError:
- continue
-
- allowable_mime_types.append(source)
- continue
-
-
- return allowable_mime_types
-
-
- def getDefault():
- return cupsext.getDefault()
-
-
- def openPPD(printer):
- return cupsext.openPPD(printer)
-
-
- def closePPD():
- return cupsext.closePPD()
-
-
- def getPPD(printer):
- return cupsext.getPPD(printer)
-
-
- def getPPDOption(option):
- return cupsext.getPPDOption(option)
-
-
- def getPPDPageSize():
- return cupsext.getPPDPageSize()
-
-
- def getPrinters():
- return cupsext.getPrinters()
-
-
- def getJobs(my_job = 0, completed = 0):
- return cupsext.getJobs(my_job, completed)
-
-
- def getAllJobs(my_job = 0):
- return cupsext.getJobs(my_job, 0) + cupsext.getJobs(my_job, 1)
-
-
- def getVersion():
- return cupsext.getVersion()
-
-
- def getServer():
- return cupsext.getServer()
-
-
- def cancelJob(jobid, dest = None):
- if dest is not None:
- return cupsext.cancelJob(dest, jobid)
- else:
- jobs = cupsext.getJobs(0, 0)
- for j in jobs:
- if j.id == jobid:
- return cupsext.cancelJob(j.dest, jobid)
- continue
-
- return False
-
-
- def resetOptions():
- return cupsext.resetOptions()
-
-
- def addOption(option):
- return cupsext.addOption(option)
-
-
- def printFile(printer, filename, title):
- if os.path.exists(filename):
- return cupsext.printFileWithOptions(printer, filename, title)
- else:
- return -1
-
-
- def addPrinter(printer_name, device_uri, location, ppd_file, info):
- return cupsext.addPrinter(printer_name, device_uri, location, ppd_file, info)
-
-
- def delPrinter(printer_name):
- return cupsext.delPrinter(printer_name)
-
-