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