Skip to content

Commit

Permalink
Add print_repo_name + minor fixes (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Dec 17, 2018
1 parent db9e15d commit 750a42d
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deploy:
provider: pypi
user: niosus
password:
secure: "S78qnarfHHG0QxFbBHNTwADWBUK67mpKcb8ZxI9xozgIJ/H8vi0WIOrovTt6BxID3QdL2XLw0tSLwupzy1b1rhsnvUbM2g6X4AbCiNtWQ2ao/yGs3uvzyroCXtbOGn5OixuidHkLfMmc7UWBZou+9Xsrhrb1XX+GvXpSD6sJ1rTfcJ1IJ0+eKf8nZMDNEyvvLw8a36mGVWWMBt3xvLRnca+jpBhGrwUYN595mgvh889HytW/oRuNR91F5wbYFWnCfea/WsPeFOzNTER3nMZkF7xN/GR6lVbkKhXh0iPGG26+xyWtVuEG5Qhmlusbg/nDJ1w8FjxJQMp1H0VmjJaU+B271bsalyYGLB+VfmRPI+PmBgbt2+j1/htGSfTLo5UEfOTuhyDqrGYH2ikEJbLQgxladSaEudYVGPbx53izDp36b86fMUZBLnApEDckOeDEYMWsJY3bBQqhO0nkRTQ+V9cZ0g7AW9E6vQdKJyVCK9u+WJudJHMIiSqsxq35Dc5QOWNM5VF7xA7UQyscv5MLdTjrgeATnPvdo6h75vPvhVcen1emd0UuCDWRjsMhS8PaFntdrBf27bf+B7oDt0WbgA5LhStzV+v3SdHzlvXgVEWhTLuXz4Zdmg4lF+rnJHiH0WYmmZMfF78cDN/a1V3LahT2QHTlH3i6Yp6rH0Wu4to="
secure: "WYExMzPfJBjOwmJ+8bhbSdmwc+lmIvxVLn6VvFgeNoSrKPVYJvMVIYKa1P6h2Ar1+qGLutlt8rLr8J0y5ahlIH4fSlO64qRKJPEOq0nbTGTWOaLQKcR7INNnRHPWG9d3+YSKkvZmlUQVrRXviF9RMQIiwFJ9zEah5g5buRlUiLi0fBxzLTgipwaFeQYACYq4QoKY75gbLbfVh8TqBX/HXdODVcqvRKt74BcTvbIlYgKizXQdun+INs5rVCvwECAPC23+5AzYpU8TAnosDuHGYFw7vAadUj0jDFaRqmHXA2l8LP5EhKXHdcY0P1Tipx13Dx0kqGw3sa1YcpQlT4ElaD/dt3q0RCzfTVyVlEOO7rZwzU+iTKoUBi4L8gea1UrY2JTfC8/RyyOaoSXQf70NK+GGZL8DDYhLOBlYu8+ctutFXtdIgXGWZm+0s7FQqbw/XC02kYdzQXNCAk+GAl1AJIdg2unD2hklgTQ8LVA7qZLUAcVwD/gQNMH7b3eEWSEIAwRXqKOHrNFkivpa2E0VqL5RMsz6p7ZAwby97GfSYc5CtQ+cWSqzgqNvqbXn98vhgq+wyb0JJcfO+2jDei+oxOlSurY0YDlk6sRdHDmb9Rp8d8+W3LofntrNa3+EsLiTZXBYAelGQGADQkhT9Q7Hd9tnUkYxzqzEE6wS4yUuI0Q="
on:
tags: true
distributions: sdist bdist_wheel
Expand Down
45 changes: 45 additions & 0 deletions ipb_homework_checker/print_repo_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
"""A script to parse an input git url and get it's wiki counterpart.
Attributes:
wiki_repo_mask (str): mask of wiki git repo
"""
import sys

from .tools import parse_git_url

wiki_repo_mask = "git@{domain}:{user}/{project}.wiki.git"
repo_mask = "git@{domain}:{user}/{project}.git"


def main():
"""Print the name of the repo."""
if len(sys.argv) < 3:
print("ERROR: must be supplied with a git url and type [wiki|code]")
print("[Example]: {binary} {repo} {type}".format(
binary='python3 print_repo_name.py',
repo='git@gitlab.igg.uni-bonn.de:igor/some_project.git',
type='wiki'))
print("[Example]: {binary} {repo} {type}".format(
binary='python3 print_repo_name.py',
repo='https://gitlab.ipb.uni-bonn.de/igor/some_project.git',
type='code'))
exit(1)
if len(sys.argv) == 3:
repo = sys.argv[1]
domain, user, project = parse_git_url(repo)
repo_type = sys.argv[2]
if repo_type == 'wiki':
print(wiki_repo_mask.format(domain=domain,
user=user,
project=project))
elif repo_type == 'code':
print(repo_mask.format(domain=domain,
user=user,
project=project))
else:
print('ERROR: type "{}" is not "wiki" or "code"'.format(repo_type))


if __name__ == '__main__':
main()
18 changes: 18 additions & 0 deletions ipb_homework_checker/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ def test_sleep_timeout(self):
cmd_result.stderr,
"Timeout: command 'sleep 10' ran longer than 1 seconds")

def test_git_url(self):
"""Test that we can break an endless loop."""
domain, user, project = tools.parse_git_url(
"https://gitlab.ipb.uni-bonn.de/igor/some_project.git")
self.assertEqual(domain, "gitlab.ipb.uni-bonn.de")
self.assertEqual(user, "igor")
self.assertEqual(project, "some_project")
domain, user, project = tools.parse_git_url(
"git@gitlab.ipb.uni-bonn.de:igor/some_project.git")
self.assertEqual(domain, "gitlab.ipb.uni-bonn.de")
self.assertEqual(user, "igor")
self.assertEqual(project, "some_project")
domain, user, project = tools.parse_git_url(
"git@github.com:PRBonn/depth_clustering.git")
self.assertEqual(domain, "github.com")
self.assertEqual(user, "PRBonn")
self.assertEqual(project, "depth_clustering")

def test_endless_loop_timeout(self):
"""Test that we can break an endless loop."""
from time import monotonic as timer
Expand Down
25 changes: 23 additions & 2 deletions ipb_homework_checker/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ def convert_to(output_type, value):
return result, "OK"


def parse_git_url(git_url):
"""Parse the git url.
Args:
git_url (str): url of a git repository (https or ssh)
Returns:
(str, str, str): tupple of domain, user and project name parsed from url
"""
import re
regex = re.compile(r'(?:git@|https:\/\/)' # Prefix
r'([\w\-_\.]+)' # Domain
r'[:\/]' # Separator : or /
r'([\w\-_\.\/]+)' # User or folders
r'[\/]' # Separator /
r'([\w\-_]+)' # Project name
r'(?:.git)*$') # .git or nothing
domain, user, project = regex.search(git_url).groups()
return domain, user, project


class CmdResult:
"""A small container for command result."""
SUCCESS = 0
Expand Down Expand Up @@ -153,7 +174,7 @@ def run_command(command, shell=True, cwd=path.curdir, env=environ, timeout=20):
return CmdResult(returncode=1, stderr=output_text)


def __run_subprocess(*popenargs,
def __run_subprocess(command,
input=None,
timeout=None,
check=False,
Expand All @@ -178,7 +199,7 @@ def __run_subprocess(*popenargs,
import signal
from subprocess import Popen, TimeoutExpired, CalledProcessError
from subprocess import CompletedProcess
with Popen(*popenargs, preexec_fn=os.setsid, **kwargs) as process:
with Popen(command, preexec_fn=os.setsid, **kwargs) as process:
try:
stdout, stderr = process.communicate(input, timeout=timeout)
except TimeoutExpired:
Expand Down
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import setup
from setuptools.command.install import install

VERSION_STRING = '0.0.5'
VERSION_STRING = '0.0.6'

PACKAGE_NAME = 'ipb_homework_checker'

Expand Down Expand Up @@ -60,15 +60,12 @@ def run(self):
'License :: OSI Approved :: Apache Software License',
],
description="""A generic homework checker.""",
long_description="""This is a homework checker. It can run various types of
code, such as Python, Bash and C++ and compare the output with expected one
defined in a yaml receipt. It is also able to run Google tests. As a result
it generates a markdown table that is suited for an upload to a students
repo.""",
long_description=open('README.md').read(),
test_suite='tests',
entry_points={
'console_scripts': [
'check_homework = ipb_homework_checker.check_homework:main',
'print_repo_name = ipb_homework_checker.print_repo_name:main',
],
},
cmdclass={'install': PermissiveInstall},
Expand Down

0 comments on commit 750a42d

Please sign in to comment.