Changeset 583

Show
Ignore:
Timestamp:
03/13/05 17:25:29 (19 years ago)
Author:
jerome
Message:

Better handling of DEVICE_URI

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/tea4cups

    r582 r583  
    254254            sectionbranches = [ (k, v) for (k, v) in self.config.items(printqueuename) if k.startswith("tee_") ] 
    255255        except ConfigParser.NoSectionError, msg :     
    256             self.logInfo("No section for print queue %s : " % (printqueuename, msg), "info") 
     256            self.logInfo("No section for print queue %s : %s" % (printqueuename, msg)) 
    257257            sectionbranches = [] 
    258258        branches = {} 
     
    351351            fulldevice_uri = device_uri[:] 
    352352            device_uri = fulldevice_uri[len(muststartwith):] 
    353             if device_uri.startswith("//") :   
    354                 device_uri = device_uri[2:] 
     353            for i in range(2) : 
     354                if device_uri.startswith("/") :   
     355                    device_uri = device_uri[1:] 
    355356        try : 
    356357            (backend, destination) = device_uri.split(":", 1)  
    357358        except ValueError :     
    358             raise TeeError, "Invalid DEVICE_URI : %s\n" % device_uri 
     359            if not device_uri : 
     360                self.logInfo("Not attached to an existing print queue.") 
     361                backend = "" 
     362            else :     
     363                raise TeeError, "Invalid DEVICE_URI : %s\n" % device_uri 
    359364         
    360365        self.JobId = sys.argv[1].strip() 
     
    375380        self.ClientHost = self.extractJobOriginatingHostName() 
    376381             
     382    def getCupsConfigDirectives(self, directives=[]) : 
     383        """Retrieves some CUPS directives from its configuration file. 
     384         
     385           Returns a mapping with lowercased directives as keys and  
     386           their setting as values. 
     387        """ 
     388        dirvalues = {}  
     389        cupsroot = os.environ.get("CUPS_SERVERROOT", "/etc/cups") 
     390        cupsdconf = os.path.join(cupsroot, "cupsd.conf") 
     391        try : 
     392            conffile = open(cupsdconf, "r") 
     393        except IOError :     
     394            raise TeeError, "Unable to open %s" % cupsdconf 
     395        else :     
     396            for line in conffile.readlines() : 
     397                linecopy = line.strip().lower() 
     398                for di in [d.lower() for d in directives] : 
     399                    if linecopy.startswith("%s " % di) : 
     400                        try : 
     401                            val = line.split()[1] 
     402                        except :     
     403                            pass # ignore errors, we take the last value in any case. 
     404                        else :     
     405                            dirvalues[di] = val 
     406            conffile.close()             
     407        return dirvalues        
     408             
    377409    def extractJobOriginatingHostName(self) :         
    378410        """Extracts the client's hostname or IP address from the CUPS message file for current job.""" 
     411        cupsdconf = self.getCupsConfigDirectives(["RequestRoot"]) 
    379412        requestroot = cupsdconf.get("requestroot", "/var/spool/cups") 
    380413        if (len(self.JobId) < 5) and self.JobId.isdigit() : 
     
    417450    def saveDatasAndCheckSum(self) : 
    418451        """Saves the input datas into a static file.""" 
    419         self.logDebug("Duplicating data stream to %s" % self.DataFile) 
     452        self.logDebug("Duplicating data stream into %s" % self.DataFile) 
    420453        mustclose = 0 
    421454        if self.InputFile is not None :