- Timestamp:
- 06/07/06 23:59:26 (18 years ago)
- Location:
- pykoticon/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r143 r146 99 99 self.frame = frame 100 100 self.debug = options.debug 101 self.cacheduration = options.cache 102 self.cache = {} 101 103 self.printServers = [ socket.gethostbyname(arg) for arg in arguments ] 102 104 if "127.0.0.1" not in self.printServers : … … 110 112 sys.stderr.write("%s\n" % message) 111 113 114 def getAnswerFromCache(self, key) : 115 """Tries to extract a value from the cache and returns it if still valid.""" 116 cacheentry = self.cache.get(key) 117 if cacheentry is not None : 118 (birth, value) = cacheentry 119 if (time.time() - birth) < self.cacheduration : 120 self.logDebug("Cache hit for %s ---> %s" % (str(key), value)) 121 return value # NB : we don't extend the life of this entry 122 else : 123 self.logDebug("Cache expired for %s" % str(key)) 124 else : 125 self.logDebug("Cache miss for %s" % str(key)) 126 return None 127 128 def storeAnswerInCache(self, key, value) : 129 """Stores an entry in the cache.""" 130 self.cache[key] = (time.time(), value) 131 self.logDebug("Cache store for %s ---> %s" % (str(key), value)) 132 133 def export_askDatas(self, labels, varnames, varvalues) : 134 """Asks some textual datas defined by a list of labels, a list of variables' names and a list of variables values in a mapping.""" 135 values = {} 136 for (key, value) in varvalues.items() : 137 values[key] = self.frame.UTF8ToUserCharset(value.data) 138 cachekey = tuple(values.items()) 139 retcode = self.getAnswerFromCache(cachekey) 140 if retcode is None : 141 wx.CallAfter(self.frame.askDatas, [ self.frame.UTF8ToUserCharset(label.data) for label in labels ], \ 142 varnames, \ 143 values) 144 # ugly, isn't it ? 145 while self.frame.dialogAnswer is None : 146 time.sleep(0.1) 147 retcode = self.frame.dialogAnswer 148 for (key, value) in retcode.items() : 149 if key != "isValid" : 150 retcode[key] = xmlrpclib.Binary(self.frame.userCharsetToUTF8(value)) 151 self.frame.dialogAnswer = None # prepare for next call, just in case 152 self.storeAnswerInCache(cachekey, retcode) 153 return retcode 154 112 155 def export_quitApplication(self) : 113 156 """Makes the application quit.""" … … 115 158 wx.CallAfter(self.frame.OnClose, None) 116 159 return True 117 118 def export_askDatas(self, labels, varnames, varvalues) :119 """Asks some textual datas defined by a list of labels, a list of variables' names and a list of variables values in a mapping."""120 values = {}121 for (key, value) in varvalues.items() :122 values[key] = self.frame.UTF8ToUserCharset(value.data)123 wx.CallAfter(self.frame.askDatas, [ self.frame.UTF8ToUserCharset(label.data) for label in labels ], \124 varnames, \125 values)126 # ugly, isn't it ?127 while self.frame.dialogAnswer is None :128 time.sleep(0.1)129 retcode = self.frame.dialogAnswer130 for (key, value) in retcode.items() :131 if key != "isValid" :132 retcode[key] = xmlrpclib.Binary(self.frame.userCharsetToUTF8(value))133 self.frame.dialogAnswer = None # prepare for next call, just in case134 return retcode135 160 136 161 def export_showDialog(self, message, yesno) : … … 252 277 wx.EVT_ICONIZE(self, self.OnIconify) 253 278 wx.EVT_CLOSE(self, self.OnClose) 254 self.Show( True)279 self.Show(False) 255 280 256 281 def getCurrentUserName(self) : … … 448 473 action="store_true", 449 474 dest="version", 450 help=_("show PyKotIcon's version number and exit")) 475 help=_("show PyKotIcon's version number and exit.")) 476 parser.add_option("-c", "--cache", 477 type="int", 478 default=0, 479 dest="cache", 480 help=_("the duration of the cache in seconds to keep input forms' datas in memory. Defaults to 0 second, meaning no cache.")) 451 481 parser.add_option("-d", "--debug", 452 482 action="store_true", 453 483 dest="debug", 454 help=_("activate debug mode "))484 help=_("activate debug mode.")) 455 485 parser.add_option("-p", "--port", 456 486 type="int", 457 487 default=7654, 458 488 dest="port", 459 help=_("the TCP port PyKotIcon will listen to, default is 7654 "))489 help=_("the TCP port PyKotIcon will listen to, default is 7654.")) 460 490 parser.add_option("-q", "--allowquit", 461 491 action="store_true", 462 492 dest="allowquit", 463 help=_("allow the end user to close the application "))493 help=_("allow the end user to close the application.")) 464 494 (options, arguments) = parser.parse_args() 465 495 if options.version : 466 496 print "PyKotIcon v%(__version__)s" % globals() 467 497 else : 468 app = PyKotIconApp() 469 app.postInit(charset, options, arguments) 470 app.MainLoop() 498 if not (1024 <= options.port <= 65535) : 499 sys.stderr.write(_("The TCP port number specified for --port must be between 1024 and 65535.\n")) 500 elif not (0 <= options.cache <= 86400) : 501 sys.stderr.write(_("The duration specified for --cache must be between 0 and 86400 seconds.\n")) 502 else : 503 app = PyKotIconApp() 504 app.postInit(charset, options, arguments) 505 app.MainLoop() 471 506 472 507 -
pykoticon/trunk/NEWS
r142 r146 22 22 PyKotIcon NEWS : 23 23 24 - 1.02 (2006-06-0 6) :24 - 1.02 (2006-06-07) : 25 25 26 - Added the --cache command line option to specify the time in 27 seconds during which input forms' content will be cached. 28 This allows people to avoid retyping their username and 29 password for each print job, for example. 30 26 31 - Now displays an error message when the end user wants to quit 27 32 and it is forbidden. -
pykoticon/trunk/TODO
r142 r146 22 22 TODO, in no particular order : 23 23 24 - Configurable cache for user credentials when username and 25 password are asked. The cache's duration will only be 26 settable from pknotify to avoid some security issues with 27 "smart" students :-) 28 24 - Find something to do :) 25 29 26 ============================================================ 30 27