Remove software carpentries logo
[rnaseq-cwl-training.git] / bin / repo_check.py
old mode 100755 (executable)
new mode 100644 (file)
index c2c2cbd..9bf5c59
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 """
 Check repository settings.
 """
@@ -9,7 +7,7 @@ import sys
 import os
 from subprocess import Popen, PIPE
 import re
-from optparse import OptionParser
+from argparse import ArgumentParser
 
 from util import Reporter, require
 
@@ -22,7 +20,7 @@ except ImportError:
 
 
 # Pattern to match Git command-line output for remotes => (user name, project name).
-P_GIT_REMOTE = re.compile(r'upstream\s+[^:]+:([^/]+)/([^.]+)\.git\s+\(fetch\)')
+P_GIT_REMOTE = re.compile(r'upstream\s+(?:https://|git@)github.com[:/]([^/]+)/([^.]+)(\.git)?\s+\(fetch\)')
 
 # Repository URL format string.
 F_REPO_URL = 'https://github.com/{0}/{1}/'
@@ -65,7 +63,7 @@ def main():
 
     args = parse_args()
     reporter = Reporter()
-    repo_url = get_repo_url(args.source_dir, args.repo_url)
+    repo_url = get_repo_url(args.repo_url)
     check_labels(reporter, repo_url)
     reporter.report()
 
@@ -75,24 +73,24 @@ def parse_args():
     Parse command-line arguments.
     """
 
-    parser = OptionParser()
-    parser.add_option('-r', '--repo',
-                      default=None,
-                      dest='repo_url',
-                      help='repository URL')
-    parser.add_option('-s', '--source',
-                      default=os.curdir,
-                      dest='source_dir',
-                      help='source directory')
-
-    args, extras = parser.parse_args()
+    parser = ArgumentParser(description="""Check repository settings.""")
+    parser.add_argument('-r', '--repo',
+                        default=None,
+                        dest='repo_url',
+                        help='repository URL')
+    parser.add_argument('-s', '--source',
+                        default=os.curdir,
+                        dest='source_dir',
+                        help='source directory')
+
+    args, extras = parser.parse_known_args()
     require(not extras,
             'Unexpected trailing command-line arguments "{0}"'.format(extras))
 
     return args
 
 
-def get_repo_url(source_dir, repo_url):
+def get_repo_url(repo_url):
     """
     Figure out which repository to query.
     """
@@ -104,7 +102,7 @@ def get_repo_url(source_dir, repo_url):
     # Guess.
     cmd = 'git remote -v'
     p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
-              close_fds=True, universal_newlines=True)
+              close_fds=True, universal_newlines=True, encoding='utf-8')
     stdout_data, stderr_data = p.communicate()
     stdout_data = stdout_data.split('\n')
     matches = [P_GIT_REMOTE.match(line) for line in stdout_data]