Package csb :: Package apps :: Module helloworld
[frames] | no frames]

Source Code for Module csb.apps.helloworld

 1  """ 
 2  This is a CSB HelloWorld dummy application. 
 3  """ 
 4   
 5  import sys 
 6  import csb.apps 
7 8 9 -class ExitCodes(csb.apps.ExitCodes):
10 11 BAD_TEXT = 4
12
13 14 -class AppRunner(csb.apps.AppRunner):
15 16 @property
17 - def target(self):
18 return HelloWorldApp
19
20 - def command_line(self):
21 22 text = "Hello World" 23 24 cmd = csb.apps.ArgHandler(self.program, 'This program prints "Hello World".') 25 26 cmd.add_scalar_option('text', 't', str, 'The text to print', default=text) 27 cmd.add_boolean_option('upper', 'u', 'Print in upper case', default=False) 28 29 return cmd
30
31 - def initapp(self, args):
32 33 app = self.target 34 if len(args.text) < 3: 35 app.exit("Enter at least a few words", code=ExitCodes.BAD_TEXT, usage=True) 36 37 return app(args)
38
39 40 -class HelloWorldApp(csb.apps.Application):
41
42 - def main(self):
43 44 if self.args.upper: 45 text = self.args.text.upper() 46 else: 47 text = self.args.text 48 49 self.log(text) 50 self.log('HW: done.')
51
52 53 -def main():
54 AppRunner(sys.argv).run()
55 56 57 if __name__ == '__main__': 58 main() 59