crowdin: Add voting

* Since we can't owner-CR+2 on most projects,
  submitting is often not possible directly
* We are still required to vote before merge, so add this as an option
* Change "-s/--submit" to "-g/--gerrit" with options "vote" and "submit"

Change-Id: If8e6fd815d8be64ba5bac4fc79b63f5ac9f210ed
diff --git a/crowdin_sync.py b/crowdin_sync.py
index 00f8110..add45a7 100755
--- a/crowdin_sync.py
+++ b/crowdin_sync.py
@@ -58,7 +58,10 @@
         "--download", action="store_true", help="Download translations from Crowdin"
     )
     parser.add_argument(
-        "-s", "--submit", action="store_true", help="Merge open translation commits"
+        "-g",
+        "--gerrit",
+        choices=["vote", "submit"],
+        help="Vote (CR+1/V+1) on or submit (incl. CR+2/V+1) open translation commits",
     )
     parser.add_argument(
         "-o", "--owner", help="Specify the owner of the commits to submit"
@@ -89,9 +92,12 @@
     default_branch = args.branch
 
     username = utils.get_username(args)
-    if args.submit:
+    if args.gerrit == "submit":
         gerrit.submit(default_branch, username, args.owner)
         sys.exit(0)
+    elif args.gerrit == "vote":
+        gerrit.vote(default_branch, username, args.owner)
+        sys.exit(0)
 
     base_path = utils.get_base_path(default_branch)
     config_dict = utils.get_config_dict(args.config, default_branch)
diff --git a/gerrit.py b/gerrit.py
index 11ae293..5dd796f 100644
--- a/gerrit.py
+++ b/gerrit.py
@@ -51,6 +51,31 @@
         print("Nothing to submit!")
 
 
+def vote(branch, username, owner):
+    commits = 0
+    changes = get_open_changes(branch, username, owner)
+    for change in changes:
+        print(f"Voting on commit {changes[change]}: ", end="")
+        # Add Code-Review +1 and Verified+1 labels
+        cmd = utils.get_gerrit_base_cmd(username) + [
+            "review",
+            "--verified +1",
+            "--code-review +1",  # we often can't self-CR+2 (limited by admin), submitter needs to do that
+            change,
+        ]
+        msg, code = utils.run_subprocess(cmd, True)
+        if code != 0:
+            error_text = msg[1].replace("\n\n", "; ").replace("\n", "")
+            print(f"Failed! -- {error_text}")
+        else:
+            print("Success")
+
+        commits += 1
+
+    if commits == 0:
+        print("Nothing to vote on!")
+
+
 def get_open_changes(branch, username, owner):
     print("Fetching open changes on gerrit")
 
diff --git a/utils.py b/utils.py
index bb73363..760f74e 100644
--- a/utils.py
+++ b/utils.py
@@ -99,7 +99,7 @@
 
 def get_username(args):
     username = args.username
-    if (args.submit or args.download) and username is None:
+    if (args.gerrit or args.download) and username is None:
         # try getting the username from git
         msg, code = run_subprocess(
             ["git", "config", "--get", "review.review.lineageos.org.username"],