Changeset 127
- Timestamp:
- 06/16/05 21:08:27 (3 years ago)
- Files:
-
- fwc/trunk/Config.py (modified) (1 diff)
- fwc/trunk/Engine.py (modified) (4 diffs)
- fwc/trunk/fwc (modified) (1 diff)
- fwc/trunk/MANIFEST (added)
- fwc/trunk/README (added)
- fwc/trunk/setup.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fwc/trunk/Config.py
r126 r127 82 82 text = Config.Template(text).safe_substitute(vars) 83 83 return text 84 85 if __name__ == "__main__":86 c = Config()87 c.define('foo-bar', 0, 'The FOO')88 c.define("x-axis", 1, "The X-Axis")89 print c.expand("Alec is ${foo-bar} times cooler")90 c.foo_bar = 1091 print c.expand("Alec is ${foo-bar} times cooler")92 for k in c.keys():93 print c.help(k), ":", c[k]fwc/trunk/Engine.py
r126 r127 2 2 import sys 3 3 import socket 4 import readline 5 import textwrap 4 6 from ConfigParser import RawConfigParser 5 7 from Config import Config … … 37 39 'to' : [], 38 40 } 41 self.existing_input = '' 39 42 40 43 # Currently active firewall … … 299 302 }, 300 303 'quit|exit' : { 304 GROUP : 20000, 301 305 HELP : [ 'quit', 'Exit.' ], 302 306 ACTION : { 303 307 HELP : 'Exit.', 304 308 ACTION : self.quit, 309 }, 310 }, 311 '!\d+' : { 312 VAR : 'index', 313 ACTION : lambda ctx, index: self.__set_history(ctx, index[1:]), 314 }, 315 'history' : { 316 GROUP : 20000, 317 HELP : 'Command history management.', 318 ACTION : { 319 HELP : 'Show history.', 320 ACTION : self.__list_history, 321 }, 322 'clear' : { 323 HELP : 'Clear history.', 324 ACTION : self.__clear_history, 325 }, 326 '\d+' : { 327 VAR : 'index', 328 HELP : ('<index>', 'History item index.'), 329 ACTION : self.__set_history, 305 330 }, 306 331 }, … … 516 541 self._parser = Parser(self.__grammar) 517 542 543 def __list_history(self, ctx): 544 cols = 'COLUMNS' in os.environ and int(os.environ['COLUMNS']) or 80 545 for index in range(1, readline.get_current_history_length() + 1): 546 #cprint('\n'.join(textwrap.wrap("^B%3i:^B %s" % (index, readline.get_history_item(index)), cols, subsequent_indent = ' '))) 547 cprint("^B%3i:^B %s" % (index, readline.get_history_item(index))) 548 549 def __clear_history(self, ctx): 550 readline.clear_history() 551 552 def __set_history(self, ctx, index): 553 try: 554 index = int(index) 555 if index > readline.get_current_history_length(): 556 raise IndexError() 557 self.existing_input = readline.get_history_item(index) 558 except: 559 error("No such history index '%s'" % index) 560 518 561 def __firewall_set(self, ctx, setting, value): 519 562 try: fwc/trunk/fwc
r125 r127 26 26 """ % Engine.version) 27 27 28 try: 29 readline.read_history_file(os.path.expanduser('~/.fwchistory')) 30 except: 31 pass 32 28 33 while True: 29 result = interact(engine._parser, engine.config.prompt) 34 result = interact(engine._parser, engine.config.prompt, engine.existing_input) 35 engine.existing_input = '' 30 36 31 37 if result.state == Result.NOP: 32 38 continue 33 39 elif result.state == Result.ENDOFINPUT: 40 try: 41 readline.write_history_file(os.path.expanduser('~/.fwchistory')) 42 except Exception, e: 43 error(e) 34 44 engine.quit() 35 45 elif result.state == Result.OK:
