Changeset 1917 for pykota

Show
Ignore:
Timestamp:
11/15/04 16:54:03 (20 years ago)
Author:
jalet
Message:

Continued integration of Matt's patch for banners

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r1911 r1917  
    2222# 
    2323# $Log$ 
     24# Revision 1.139  2004/11/15 15:54:03  jalet 
     25# Continued integration of Matt's patch for banners 
     26# 
    2427# Revision 1.138  2004/11/12 23:46:44  jalet 
    2528# Heavy work on pkbanner. Not finished yet though, but mostly works. 
     
    513516import md5 
    514517import ConfigParser 
     518import popen2 
     519import cStringIO 
    515520 
    516521from mx import DateTime 
     
    12091214            self.logdebug("Executing post-hook [%s]" % posthook) 
    12101215            os.system(posthook) 
     1216 
     1217    def genBanner(self, bannerfileorcommand) : 
     1218        """Reads a banner or generates one through an external command. 
     1219         
     1220           Returns the banner's content in a format which MUST be accepted 
     1221           by the printer. 
     1222        """ 
     1223        banner = "" # no banner by default 
     1224        if bannerfileorcommand : 
     1225            if (os.access(bannerfileorcommand, os.X_OK)) : 
     1226                self.logdebug("Launching %s to generate a banner." % bannerfileorcommand) 
     1227                child = popen2.Popen3(bannerfileorcommand, capturestderr=1) 
     1228                child.tochild.close() 
     1229                child.childerr.close() 
     1230                banner = child.fromchild.read() 
     1231                child.fromchild.close() 
     1232                status = child.wait() 
     1233                if os.WIFEXITED(status) : 
     1234                    status = os.WEXITSTATUS(status) 
     1235                self.printInfo(_("Banner generator %s exit code is %s") % (bannerfileorcommand, str(status))) 
     1236            else : 
     1237                self.logdebug("Using %s as the banner." % bannerfileorcommand) 
     1238                try : 
     1239                    fh = open(bannerfileorcommand, 'r') 
     1240                except IOError, msg :     
     1241                    self.printInfo("Impossible to open %s : %s" % (bannerfileorcommand, msg), "error") 
     1242                else :     
     1243                    banner = fh.read() 
     1244                    fh.close() 
     1245        return cStringIO.StringIO(banner) 
     1246     
     1247    def startingBanner(self, printername) : 
     1248        """Retrieves a starting banner for current printer and returns its content.""" 
     1249        self.logdebug("Retrieving starting banner...") 
     1250        return self.genBanner(self.config.getStartingBanner(printername)) 
     1251     
     1252    def endingBanner(self, printername) : 
     1253        """Retrieves an ending banner for current printer and returns its content.""" 
     1254        self.logdebug("Retrieving ending banner...") 
     1255        return self.genBanner(self.config.getEndingBanner(printername)) 
    12111256         
    12121257    def printInfo(self, message, level="info") :