6 def find_module(submodules
, name
):
7 for item
in submodules
:
8 if item
["name"] == name
:
16 print "Usage: versions.py <command>"
19 CONFIG_FILE
= "SUBMODULES.json"
22 submodules
= json
.load(open(CONFIG_FILE
))
24 if command
== "get-rev":
25 mod
= find_module(submodules
, sys
.argv
[2])
27 elif command
== "get-url":
28 mod
= find_module(submodules
, sys
.argv
[2])
30 elif command
== "get-dir":
31 mod
= find_module(submodules
, sys
.argv
[2])
32 print mod
["directory"]
33 elif command
== "get-remote-branch":
34 mod
= find_module(submodules
, sys
.argv
[2])
35 print mod
["remote-branch"]
36 elif command
== "set-rev":
37 mod
= find_module(submodules
, sys
.argv
[2])
38 mod
["rev"] = sys
.argv
[3]
39 json
.dump(submodules
, open(CONFIG_FILE
, "w"), indent
= 2)
40 elif command
== "set-branch":
41 mod
= find_module(submodules
, sys
.argv
[2])
42 mod
["branch"] = sys
.argv
[3]
43 json
.dump(submodules
, open(CONFIG_FILE
, "w"), indent
= 2)
44 elif command
== "set-remote-branch":
45 mod
= find_module(submodules
, sys
.argv
[2])
46 mod
["remote-branch"] = sys
.argv
[3]
47 json
.dump(submodules
, open(CONFIG_FILE
, "w"), indent
= 2)
48 elif command
== "cat":
49 print json
.dumps(submodules
, indent
= 2)
51 print "Unknown command "" + command + ""."