Changeset 537
- Timestamp:
- 05/08/2008 03:59:31 AM (3 months ago)
- Files:
-
- ape/trunk/ape/commandline.py (modified) (1 diff)
- ape/trunk/ape/__init__.py (modified) (1 diff)
- ape/trunk/ape/util.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ape/trunk/ape/commandline.py
r536 r537 24 24 import os 25 25 import sys 26 import traceback 26 27 from optparse import OptionParser, Option 27 28 import ape 29 from ape.component import Component 28 30 from ape.util import URI, to_boolean 29 31 30 32 31 __all__ = ['bootstrap'] 33 __all__ = ['CommandLine', 'bootstrap'] 34 35 36 class CommandLine(Component): 37 abstract = True 38 39 def run(self): 40 """Command-line applications should override this method.""" 41 raise NotImplementedError 42 43 @classmethod 44 def bootstrap(cls, engine_cls, **kwargs): 45 """Start and run command-line with an Engine.""" 46 47 try: 48 e = bootstrap(engine_cls, **kwargs) 49 self = cls(e) 50 except ape.Error, e: 51 print >> sys.stderr, 'fatal:', str(e) 52 sys.exit(1) 53 54 try: 55 try: 56 self.run() 57 except ape.Error, e: 58 print >> sys.stderr, 'fatal:', str(e) 59 sys.exit(1) 60 except KeyboardInterrupt: 61 print '^C' 62 finally: 63 try: 64 self.e.shutdown() 65 except Exception, e: 66 print >> sys.stderr, 'Engine shutdown failed!' 67 traceback.print_exc() 68 sys.exit(-1) 69 70 sys.exit(0) 32 71 33 72 ape/trunk/ape/__init__.py
r536 r537 12 12 pass 13 13 14 from ape import engine, config, component 14 from ape import engine, config, component, commandline 15 15 from ape.engine import * 16 16 from ape.config import * 17 17 from ape.component import * 18 from ape.commandline import * 18 19 19 20 20 __all__ = engine.__all__ + config.__all__ + component.__all__ 21 __all__ = engine.__all__ + config.__all__ + component.__all__ + commandline.__all__ ape/trunk/ape/util.py
r535 r537 170 170 def __repr__(self): 171 171 return "URI(u'%s')" % unicode(self) 172 173 def __nonzero__(self): 174 return len(str(self)) 172 175 173 176 def __str__(self):
