diff --git a/jsk_tools/package.xml b/jsk_tools/package.xml index ae3bf4a90..6f506e8a5 100644 --- a/jsk_tools/package.xml +++ b/jsk_tools/package.xml @@ -20,7 +20,7 @@ cv_bridge python-percol python-colorama - python-pygithub3 + python-github-pip python-slacker-cli python-tabulate-pip python-texttable diff --git a/jsk_tools/src/git_commit_alias.py b/jsk_tools/src/git_commit_alias.py index 0a8fa4998..4bd2989eb 100755 --- a/jsk_tools/src/git_commit_alias.py +++ b/jsk_tools/src/git_commit_alias.py @@ -1,32 +1,34 @@ #!/usr/bin/env python -# Generate commit aliases for jsk-ros-pkg developers +"""Generate commit aliases for jsk-ros-pkg developers""" + import subprocess -from pygithub3 import Github +from jsk_tools.github_lib import login_github + -from getpass import getpass -user = raw_input('GitHub User name: ') -pw = getpass('Password: ') -gh = Github(login=user, password=pw) -result = gh.orgs.members.list('jsk-ros-pkg') -for page in result: - for member in page: - user = gh.users.get(member.login) +def main(): + gh = login_github() + + org = gh.get_organization('jsk-ros-pkg') + for user in org.get_members(): try: - name = user.name - alias_name = name + alias_name = name = user.name email = user.email if not email or email == "": raise Exception("No email specified") - if len(alias_name.split(" ")) > 0: + if len(name.split(" ")) > 0: alias_name = name.split(" ")[-1] alias_command = "commit-%s" % alias_name.lower() alias = "jsk-commit --author='%s <%s>'" % (name, email) - subprocess.check_call(["git", "config", "--global", - "alias.%s" % alias_command, - alias]) + subprocess.check_call( + ["git", "config", "--global", + "alias.%s" % alias_command, alias] + ) print "Added %s" % (alias_command) - except: - print "Failed to generate alias for %s" % (member.login) + except Exception as e: + print("Failed to generate alias for %s: %s" % (user.name, e)) + +if __name__ == '__main__': + main() diff --git a/jsk_tools/src/jsk_tools/__init__.py b/jsk_tools/src/jsk_tools/__init__.py index fb1eb6144..fbf4cf394 100644 --- a/jsk_tools/src/jsk_tools/__init__.py +++ b/jsk_tools/src/jsk_tools/__init__.py @@ -5,3 +5,4 @@ from . import video_directive from . import sanity_lib from . import cltool +from . import github_lib diff --git a/jsk_tools/src/jsk_tools/github_lib.py b/jsk_tools/src/jsk_tools/github_lib.py new file mode 100644 index 000000000..349a1f117 --- /dev/null +++ b/jsk_tools/src/jsk_tools/github_lib.py @@ -0,0 +1,24 @@ +import __builtin__ + +import getpass +import sys + +import github + + +def raw_input(prompt=None): + if prompt: + sys.stderr.write(str(prompt)) + return __builtin__.raw_input() + + +gh = None + + +def login_github(): + global gh + if gh is None: + username = raw_input('GitHub username: ') + password = getpass.getpass('Password: ', stream=sys.stderr) + gh = github.Github(username, password) + return gh diff --git a/jsk_tools/src/list_repos.py b/jsk_tools/src/list_repos.py new file mode 100755 index 000000000..9e6624b91 --- /dev/null +++ b/jsk_tools/src/list_repos.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import argparse + +from jsk_tools.github_lib import login_github + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--rosinstall', action='store_true', + help='Outputs with rosinstall format.') + args = parser.parse_args() + + rosinstall = args.rosinstall + + gh = login_github() + + for org_name in ['jsk-ros-pkg', 'start-jsk']: + org = gh.get_organization(org_name) + for repo in org.get_repos(): + if rosinstall: + if repo.private: + uri_prefix = 'git@github.com:' + else: + uri_prefix = 'https://github.com/' + print('''\ +- git: + local-name: {repo.full_name} + uri: {uri_prefix}{repo.full_name}.git + version: {repo.default_branch}'''.format(repo=repo, + uri_prefix=uri_prefix)) + else: + print(repo.full_name) + + +if __name__ == '__main__': + main()