summaryrefslogtreecommitdiff
path: root/tools/release/utils.py
blob: c72ab2d91fa7d6e7941ec7e77b0056bb527820f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import string

import os

class failure_exception:
    def __init__( self, rc ):
        self.rc_ = rc

    def __str__( self ):
        return "rc: %d" % self.rc_

def system( commands ):
    if os.path.exists( "tmp.cmd" ):
        os.chmod( "tmp.cmd", 0777 )
        os.unlink( "tmp.cmd" )

    f = open( "tmp.cmd", "w" )
    f.write( string.join( commands, "\n" ) )
    f.close()
    rc = os.system( "tmp.cmd" )
    os.chmod( "tmp.cmd", 0777 )
    os.unlink( "tmp.cmd" )
    return rc

def checked_system( commands, valid_return_codes = [ 0 ] ):
    rc = system( commands ) 
    if rc not in [ 0 ] + valid_return_codes: raise failure_exception( rc )
    return rc

class step_controller:
    def __init__( self, start_step ):
        self.current_step_ = None;
        self.skip_to_step_ = start_step

    def start_step( self, step_name, start_message ):
        self.current_step_ = step_name
        if self.is_skipping( step_name ):
            print "[%s] Skipping." % step_name
            return 0
        else:
            self.skip_to_step_ = ""
            print "[%s] %s" % ( step_name, start_message )
            return 1

    def finish_step( self, step_name ):
        print "[%s] Finished" % step_name

    def is_skipping( self, step_name = None ):
        if step_name is None: step_name = self.current_step_
        return self.skip_to_step_ != "" and self.skip_to_step_ != step_name