summaryrefslogtreecommitdiff
path: root/ACE/bin/sets-manager.py
blob: 271e6006decf298bcc872539ce899430f9094c16 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python

""" This script implements branching and tagging in the DOC group
repository, and automates the process of creating sets. """

import os

def parse_args ():
    from optparse import OptionParser

    parser = OptionParser ("usage: %prog [options] name")
    parser.add_option ("-A", "--ACE", dest="project", action="store_const",
                       help="Branch/tag only ACE", default=None, const="ace")
    parser.add_option ("-T", "--TAO", dest="project", action="store_const",
                       help="Branch/tag ACE and TAO", default=None, const="tao")
    parser.add_option ("-C", "--CIAO", dest="project", action="store_const",
                       help="Branch/tag ACE, TAO, and CIAO", default=None, const="ciao")
    parser.add_option ("-t", "--tag", dest="action",
                       help="Create a tag", action="store_true", default=None)
    parser.add_option ("-b", "--branch", dest="action", action="store_false",
                       help="Create a branch", default=None)
    parser.add_option ("-v", "--verbose", dest="verbose", action="store_true",
                       help="Print out verbose debugging output", default=False)
    parser.add_option ("-s", "--svn", dest="svn", default="svn",
                       help="Full path to svn binary, if not in path")
    parser.add_option ("-r", "--repo", dest="repo",
                       default="https://svn.dre.vanderbilt.edu/DOC/Middleware/",
                       help="Repository to use, defaults to s.d.v.e/DOC/Middleware.")
    parser.add_option ("--src", dest="source", default="trunk/",
                       help="Path in repository from which to branch, defaults to trunk")
    parser.add_option ("--dest", dest="dest", default="",
                       help="Specifies a subdirectory of branches or tags in which " +
                       "to place the new branch/tag. dest must already exist.")
    parser.add_option ("-n", dest="take_action", action="store_false", default=True,
                       help="Take no action")
    (opts, args) = parser.parse_args ()

    if len(args) != 1:
        parser.error ("must specify exactly one branch or tag name")

    if opts.action is None:
        parser.error ("must specify either a branch or tag action")

    if opts.project is None:
        parser.error ("must specity a project to branch")

    return (opts, args)

def execute (command):
    from os import system

    if opts.verbose:
        print "executing " + command
    if opts.take_action and os.system (command) != 0:
        raise Exception ("Command failed: " + command)

def svn_copy (source, dest):
    command = " ".join ([opts.svn,
                         "copy",
                         '-m "branching/tagging"',
                         source,
                         dest])
    execute (command)

def svn_propset (path, prop, value):
    command = " ".join ([opts.svn,
                        "propset",
                        prop,
                        "'" + value + "'",
                        path])
    execute (command)

def svn_mkdir (path):
    command = " ".join ([opts.svn,
                         "mkdir",
                         '-m "branching/tagging"',
                         path])
    execute (command)

def svn_mkdir_local (path):
    command = " ".join ([opts.svn,
                        "mkdir",
                        path])
    execute (command)

def get_head_revision (url):
    command = " ".join ([opts.svn,
                         "info",
                         url])

    import re
    lineregex = re.compile ("Last Changed Rev: (\d+)")

    for line in os.popen (command).readlines ():
        match = lineregex.match (line)
        if (match is not None):
            return int(match.group (1))

    print "ERROR: Unable to find current MPC head revision"
    raise Exception

def branch_ACE ():
    # Perform branching
    destination = opts.repo + opts.dest
    svn_copy (opts.repo + opts.source + "/ACE",
              destination + "modules/ACE")

    # pin MPC revision
    # Need local copy of the ACE directory to to the propset
#    execute ("svn up -N " + opts.repo + path + "/modules/ACE sets_manager_temp/module_ACE")
    execute ("svn up -N sets_manager_temp/modules/ACE")
    mpc_rev = get_head_revision ("svn://svn.dre.vanderbilt.edu/DOC/MPC/trunk")

    svn_propset ("sets_manager_temp/modules/ACE",
                 "svn:externals",
                 "%s\t-r %d %s" % ("MPC",
                                   mpc_rev,
                                   "svn://svn.dre.vanderbilt.edu/DOC/MPC/trunk"))

    #Create the set
    svn_mkdir_local ("sets_manager_temp/sets/ACE")
    svn_propset ("sets_manager_temp/sets/ACE",
                 "svn:externals",
                 "%s\t%s" % ("ACE_wrappers",
                             destination + "modules/ACE"))

def branch_TAO ():
    branch_ACE ()

    # Perform branching
    destination = opts.repo + opts.dest
    svn_copy (opts.repo + opts.source + "/TAO",
              destination + "modules/TAO")

    #Create the set
    svn_mkdir_local ("sets_manager_temp/sets/ACE+TAO")
    svn_propset ("sets_manager_temp/sets/ACE+TAO",
                 "svn:externals",
                 "%s\t%s\n%s\t%s" % ("ACE_wrappers",
                                     destination + "modules/ACE",
                                     "ACE_wrappers/TAO",
                                     destination + "modules/TAO"))

def branch_CIAO ():
    branch_TAO ()

    #Perform branching
    destination = opts.repo + opts.dest
    svn_copy (opts.repo + opts.source + "/CIAO",
              destination + "modules/CIAO")

    # Create the set
    svn_mkdir_local ("sets_manager_temp/sets/ACE+TAO+CIAO")
    svn_propset ("sets_manager_temp/sets/ACE+TAO+CIAO",
                 "svn:externals",
                 "%s\t%s\n%s\t%s\n%s\t%s" %
                 ("ACE_wrappers",
                  destination + "modules/ACE",
                  "ACE_wrappers/TAO",
                  destination + "modules/TAO",
                  "ACE_wrappers/TAO/CIAO",
                  destination + "modules/CIAO"))

def main (opts, args):
    # Lets make opts global
    globals ()['opts'] = opts

    path = str ()
    if opts.action:
        # True for tag
        path = "tags/"
    else: # Branch
        path = "branches/"

    path += "%s/%s" % (opts.dest, args[0])
    # Make branch/tag directory
    svn_mkdir (opts.repo + path)

    execute ("svn co " + opts.repo + path + " sets_manager_temp")

    # Make modules and sets subdirectory
    svn_mkdir_local ("sets_manager_temp/modules")
    svn_mkdir_local ("sets_manager_temp/sets")

    # commit the new directories
    execute ('svn commit -m "branching/tagging" sets_manager_temp')

    # opts.dest should now be set to path, all of the branching
    # functions assume dest now points to the branch/tag in which
    # the copies should be places
    opts.dest = path + '/'

    {'ace': branch_ACE,
     'tao': branch_TAO,
     'ciao': branch_CIAO}[opts.project] ()

    # Commit the sets directory
    execute ('svn commit -m "branching/tagging" sets_manager_temp')

    # remove the sets directory
    for root, dirs, files in os.walk ('sets_manager_temp', False):
        for name in files:
            os.remove (os.path.join (root, name))
        for name in dirs:
            os.rmdir (os.path.join (root, name))

if __name__ == "__main__":
    opts, args = parse_args ()
    main (opts, args)