[acceptance-tests] Convert Ruby script to Python
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 19 Oct 2015 14:02:46 +0000 (16:02 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 19 Oct 2015 15:14:47 +0000 (17:14 +0200)
Most of the other scripts in the repo use Python and we decided to converge on that one.

acceptance-tests/Makefile.am
acceptance-tests/SUBMODULES.json
acceptance-tests/versions.mk
acceptance-tests/versions.py [new file with mode: 0755]
acceptance-tests/versions.rb [deleted file]

index 187ecce99c0c3dc8775d9a922e7d278ec84501c0..4e75d485aaca2be2e4dc5a3882184c945e6f3beb 100644 (file)
@@ -5,7 +5,7 @@ MSTESTSUITE_PATH=$(TOP)/../ms-test-suite
 
 include versions.mk
 
-EXTRA_DISTFILES=README.md SUBMODULES.json versions.mk versions.rb
+EXTRA_DISTFILES=README.md SUBMODULES.json versions.mk versions.py
 
 check: check-roslyn check-coreclr check-ms-test-suite
 
index 9aa4494fab23a0699e48d3cc9e430bb8289462c0..088dd65cef6f2194fe85aeb774a82b1ef6e8c758 100644 (file)
@@ -1,26 +1,26 @@
 [
   {
-    "name": "roslyn",
-    "directory": "roslyn",
-    "url": "git://github.com/dotnet/roslyn.git",
-    "branch": "master",
-    "remote-branch": "origin/master",
-    "rev": "2e68ae5e6ec51762296c681aadf57a6f33f2f34f"
-  },
+    "name": "roslyn", 
+    "url": "git://github.com/dotnet/roslyn.git", 
+    "rev": "2e68ae5e6ec51762296c681aadf57a6f33f2f34f", 
+    "remote-branch": "origin/master", 
+    "branch": "master", 
+    "directory": "roslyn"
+  }, 
   {
-    "name": "coreclr",
-    "directory": "coreclr",
-    "url": "git://github.com/dotnet/coreclr.git",
-    "branch": "master",
-    "remote-branch": "origin/master",
-    "rev": "b9920ebea8d8d77b65d0ca10ffdb840f0cd36f06"
-  },
+    "name": "coreclr", 
+    "url": "git://github.com/dotnet/coreclr.git", 
+    "rev": "b9920ebea8d8d77b65d0ca10ffdb840f0cd36f06", 
+    "remote-branch": "origin/master", 
+    "branch": "master", 
+    "directory": "coreclr"
+  }, 
   {
-    "name": "ms-test-suite",
-    "directory": "ms-test-suite",
-    "url": "git@github.com:xamarin/ms-test-suite.git",
-    "branch": "master",
-    "remote-branch": "origin/master",
-    "rev": "4caab98ae449836c2aaacb9748fe0c796b71517f"
+    "name": "ms-test-suite", 
+    "url": "git@github.com:xamarin/ms-test-suite.git", 
+    "rev": "4caab98ae449836c2aaacb9748fe0c796b71517f", 
+    "remote-branch": "origin/master", 
+    "branch": "master", 
+    "directory": "ms-test-suite"
   }
 ]
\ No newline at end of file
index 3d869cf156aaf1ac23bf6dbcf1a5cf0d739d4e57..3a16bce02d7a29507db6f070073467254b260be3 100644 (file)
@@ -7,11 +7,11 @@ CONFIG=SUBMODULES.json
 
 define ValidateVersionTemplate
 #$(eval REPOSITORY_$(2):=$(shell test -z $(3) && echo $(1) || echo "$(3)"))
-#$(eval DIRECTORY_$(2):=$(shell ruby versions.rb get-dir $(1)))
+#$(eval DIRECTORY_$(2):=$(shell python versions.py get-dir $(1)))
 #$(eval DIRECTORY_$(2):=$(shell test -z $(DIRECTORY_$(2)) && echo $(1) || echo $(DIRECTORY_$(2))))
-#$(eval MODULE_$(2):=$(shell ruby versions.rb get-url $(1)))
-#$(eval NEEDED_$(2)_VERSION:=$(shell ruby versions.rb get-rev $(1)))
-#$(eval $(2)_BRANCH_AND_REMOTE:=$(shell ruby versions.rb get-remote-branch $(1)))
+#$(eval MODULE_$(2):=$(shell python versions.py get-url $(1)))
+#$(eval NEEDED_$(2)_VERSION:=$(shell python versions.py get-rev $(1)))
+#$(eval $(2)_BRANCH_AND_REMOTE:=$(shell python versions.py get-remote-branch $(1)))
 
 #$(eval $(2)_VERSION:=$$$$(shell cd $($(2)_PATH) 2>/dev/null && git rev-parse HEAD ))
 
@@ -108,21 +108,21 @@ reset:
 __bump-version-%:
        @if [ "$(REV)" = "" ]; then echo "Usage: make bump-version-$* REV=<ref>"; exit 1; fi
        @if [ "$(COMMIT)" = "1" ]; then git pull; fi
-       ruby versions.rb set-rev $* $(REV)
+       python versions.py set-rev $* $(REV)
        @if [ "$(COMMIT)" = "1" ]; then echo "Bump $* to pick up $(REV)." | git commit -F - $(CONFIG); fi
 
 __bump-branch-%:
        @if [ "$(BRANCH)" = "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
        @if [ "$(REMOTE_BRANCH)" == "" ]; then echo "Usage: make bump-branch-$* BRANCH=<branch> REMOTE_BRANCH=<remote branch>"; exit 1; fi
        @if [ "$(COMMIT)" = "1" ]; then git pull; fi
-       ruby versions.rb set-branch $* $(BRANCH)
-       ruby versions.rb set-remote-branch $* $(REMOTE_BRANCH)
+       python versions.py set-branch $* $(BRANCH)
+       python versions.py set-remote-branch $* $(REMOTE_BRANCH)
        @if [ "$(COMMIT)" = "1" ]; then echo "Bump $* to switch to $(BRANCH) $(REMOTE BRANCH)." | git commit -F - $(CONFIG); fi
 
 __bump-current-version-%:
        @if [ "$(COMMIT)" = "1" ]; then git pull; fi
        REV=$(shell cd $(TOP)/../$* && git log -1 --pretty=format:%H); \
-       ruby versions.rb set-rev $* $$REV; \
+       python versions.py set-rev $* $$REV; \
        if [ "$(COMMIT)" = "1" ]; then echo "Bump $* to pick up $$REV:" | git commit -F - $(CONFIG); fi
 
 # Bump the given submodule to the revision given by the REV make variable
diff --git a/acceptance-tests/versions.py b/acceptance-tests/versions.py
new file mode 100755 (executable)
index 0000000..5fff4f1
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+import sys
+import json
+
+def find_module(submodules, name):
+    for item in submodules:
+        if item["name"] == name:
+            return item
+
+    print "Not found"
+    sys.exit(1)
+
+
+if len(sys.argv) < 2:
+    print "Usage: versions.py <command>"
+    sys.exit(1)
+
+CONFIG_FILE = "SUBMODULES.json"
+command = sys.argv[1]
+
+submodules = json.load(open(CONFIG_FILE))
+
+if command == "get-rev":
+    mod = find_module(submodules, sys.argv[2])
+    print mod["rev"]
+elif command == "get-url":
+    mod = find_module(submodules, sys.argv[2])
+    print mod["url"]
+elif command == "get-dir":
+    mod = find_module(submodules, sys.argv[2])
+    print mod["directory"]
+elif command == "get-remote-branch":
+    mod = find_module(submodules, sys.argv[2])
+    print mod["remote-branch"]
+elif command == "set-rev":
+    mod = find_module(submodules, sys.argv[2])
+    mod["rev"] = sys.argv[3]
+    json.dump(submodules, open(CONFIG_FILE, "w"), indent = 2)
+elif command == "set-branch":
+    mod = find_module(submodules, sys.argv[2])
+    mod["branch"] = sys.argv[3]
+    json.dump(submodules, open(CONFIG_FILE, "w"), indent = 2)
+elif command == "set-remote-branch":
+    mod = find_module(submodules, sys.argv[2])
+    mod["remote-branch"] = sys.argv[3]
+    json.dump(submodules, open(CONFIG_FILE, "w"), indent = 2)
+elif command == "cat":
+    print json.dumps(submodules, indent = 2)
+else:
+    print "Unknown command "" + command + ""."
+    sys.exit(1)
diff --git a/acceptance-tests/versions.rb b/acceptance-tests/versions.rb
deleted file mode 100755 (executable)
index ff43d73..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'optparse'
-require 'json'
-
-def find_module(submodules, name)
-  mod = submodules.find { |m| m['name'] == name }
-  if mod == nil
-    # FIXME:
-    puts "Not found"
-    exit 1
-  end
-  return mod
-end
-  
-if ARGV.length < 1 then
-  puts "Usage: versions.rb <command>"
-  exit(1)
-end
-
-command = ARGV[0]
-
-submodules = JSON.parse(File.read("SUBMODULES.json"))
-
-case command
-when "get-rev"
-  mod = find_module(submodules, ARGV[1])
-  puts mod['rev']
-when "get-url"
-  mod = find_module(submodules, ARGV[1])
-  puts mod['url']
-when "get-dir"
-  mod = find_module(submodules, ARGV[1])
-  puts mod['directory']
-when "get-remote-branch"
-  mod = find_module(submodules, ARGV[1])
-  puts mod['remote-branch']
-when "set-rev"
-  mod = find_module(submodules, ARGV[1])
-  mod['rev'] = ARGV[2]
-  f = File.new("SUBMODULES.json", "w")
-  f.write(JSON.pretty_generate(submodules))
-  f.close()
-when "set-branch"
-  mod = find_module(submodules, ARGV[1])
-  mod['branch'] = ARGV[2]
-  f = File.new("SUBMODULES.json", "w")
-  f.write(JSON.pretty_generate(submodules))
-  f.close()
-when "set-remote-branch"
-  mod = find_module(submodules, ARGV[1])
-  mod['remote-branch'] = ARGV[2]
-  f = File.new("SUBMODULES.json", "w")
-  f.write(JSON.pretty_generate(submodules))
-  f.close()
-when "cat"
-  puts JSON.pretty_generate(submodules)
-else
-  puts "Unknown command '#{command}'."
-  exit 1
-end