[29] | 1 | import string |
---|
| 2 | |
---|
| 3 | import os |
---|
| 4 | |
---|
| 5 | class failure_exception: |
---|
| 6 | def __init__( self, rc ): |
---|
| 7 | self.rc_ = rc |
---|
| 8 | |
---|
| 9 | def __str__( self ): |
---|
| 10 | return "rc: %d" % self.rc_ |
---|
| 11 | |
---|
| 12 | def system( commands ): |
---|
| 13 | if os.path.exists( "tmp.cmd" ): |
---|
| 14 | os.chmod( "tmp.cmd", 0777 ) |
---|
| 15 | os.unlink( "tmp.cmd" ) |
---|
| 16 | |
---|
| 17 | f = open( "tmp.cmd", "w" ) |
---|
| 18 | f.write( string.join( commands, "\n" ) ) |
---|
| 19 | f.close() |
---|
| 20 | rc = os.system( "tmp.cmd" ) |
---|
| 21 | os.chmod( "tmp.cmd", 0777 ) |
---|
| 22 | os.unlink( "tmp.cmd" ) |
---|
| 23 | return rc |
---|
| 24 | |
---|
| 25 | def checked_system( commands, valid_return_codes = [ 0 ] ): |
---|
| 26 | rc = system( commands ) |
---|
| 27 | if rc not in [ 0 ] + valid_return_codes: raise failure_exception( rc ) |
---|
| 28 | return rc |
---|
| 29 | |
---|
| 30 | class step_controller: |
---|
| 31 | def __init__( self, start_step ): |
---|
| 32 | self.current_step_ = None; |
---|
| 33 | self.skip_to_step_ = start_step |
---|
| 34 | |
---|
| 35 | def start_step( self, step_name, start_message ): |
---|
| 36 | self.current_step_ = step_name |
---|
| 37 | if self.is_skipping( step_name ): |
---|
| 38 | print "[%s] Skipping." % step_name |
---|
| 39 | return 0 |
---|
| 40 | else: |
---|
| 41 | self.skip_to_step_ = "" |
---|
| 42 | print "[%s] %s" % ( step_name, start_message ) |
---|
| 43 | return 1 |
---|
| 44 | |
---|
| 45 | def finish_step( self, step_name ): |
---|
| 46 | print "[%s] Finished" % step_name |
---|
| 47 | |
---|
| 48 | def is_skipping( self, step_name = None ): |
---|
| 49 | if step_name is None: step_name = self.current_step_ |
---|
| 50 | return self.skip_to_step_ != "" and self.skip_to_step_ != step_name |
---|
| 51 | |
---|
| 52 | |
---|