Skip to content

Commit 750a42d

Browse files
authored
Add print_repo_name + minor fixes (#5)
1 parent db9e15d commit 750a42d

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ deploy:
2020
provider: pypi
2121
user: niosus
2222
password:
23-
secure: "S78qnarfHHG0QxFbBHNTwADWBUK67mpKcb8ZxI9xozgIJ/H8vi0WIOrovTt6BxID3QdL2XLw0tSLwupzy1b1rhsnvUbM2g6X4AbCiNtWQ2ao/yGs3uvzyroCXtbOGn5OixuidHkLfMmc7UWBZou+9Xsrhrb1XX+GvXpSD6sJ1rTfcJ1IJ0+eKf8nZMDNEyvvLw8a36mGVWWMBt3xvLRnca+jpBhGrwUYN595mgvh889HytW/oRuNR91F5wbYFWnCfea/WsPeFOzNTER3nMZkF7xN/GR6lVbkKhXh0iPGG26+xyWtVuEG5Qhmlusbg/nDJ1w8FjxJQMp1H0VmjJaU+B271bsalyYGLB+VfmRPI+PmBgbt2+j1/htGSfTLo5UEfOTuhyDqrGYH2ikEJbLQgxladSaEudYVGPbx53izDp36b86fMUZBLnApEDckOeDEYMWsJY3bBQqhO0nkRTQ+V9cZ0g7AW9E6vQdKJyVCK9u+WJudJHMIiSqsxq35Dc5QOWNM5VF7xA7UQyscv5MLdTjrgeATnPvdo6h75vPvhVcen1emd0UuCDWRjsMhS8PaFntdrBf27bf+B7oDt0WbgA5LhStzV+v3SdHzlvXgVEWhTLuXz4Zdmg4lF+rnJHiH0WYmmZMfF78cDN/a1V3LahT2QHTlH3i6Yp6rH0Wu4to="
23+
secure: "WYExMzPfJBjOwmJ+8bhbSdmwc+lmIvxVLn6VvFgeNoSrKPVYJvMVIYKa1P6h2Ar1+qGLutlt8rLr8J0y5ahlIH4fSlO64qRKJPEOq0nbTGTWOaLQKcR7INNnRHPWG9d3+YSKkvZmlUQVrRXviF9RMQIiwFJ9zEah5g5buRlUiLi0fBxzLTgipwaFeQYACYq4QoKY75gbLbfVh8TqBX/HXdODVcqvRKt74BcTvbIlYgKizXQdun+INs5rVCvwECAPC23+5AzYpU8TAnosDuHGYFw7vAadUj0jDFaRqmHXA2l8LP5EhKXHdcY0P1Tipx13Dx0kqGw3sa1YcpQlT4ElaD/dt3q0RCzfTVyVlEOO7rZwzU+iTKoUBi4L8gea1UrY2JTfC8/RyyOaoSXQf70NK+GGZL8DDYhLOBlYu8+ctutFXtdIgXGWZm+0s7FQqbw/XC02kYdzQXNCAk+GAl1AJIdg2unD2hklgTQ8LVA7qZLUAcVwD/gQNMH7b3eEWSEIAwRXqKOHrNFkivpa2E0VqL5RMsz6p7ZAwby97GfSYc5CtQ+cWSqzgqNvqbXn98vhgq+wyb0JJcfO+2jDei+oxOlSurY0YDlk6sRdHDmb9Rp8d8+W3LofntrNa3+EsLiTZXBYAelGQGADQkhT9Q7Hd9tnUkYxzqzEE6wS4yUuI0Q="
2424
on:
2525
tags: true
2626
distributions: sdist bdist_wheel
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/python3
2+
"""A script to parse an input git url and get it's wiki counterpart.
3+
4+
Attributes:
5+
wiki_repo_mask (str): mask of wiki git repo
6+
"""
7+
import sys
8+
9+
from .tools import parse_git_url
10+
11+
wiki_repo_mask = "git@{domain}:{user}/{project}.wiki.git"
12+
repo_mask = "git@{domain}:{user}/{project}.git"
13+
14+
15+
def main():
16+
"""Print the name of the repo."""
17+
if len(sys.argv) < 3:
18+
print("ERROR: must be supplied with a git url and type [wiki|code]")
19+
print("[Example]: {binary} {repo} {type}".format(
20+
binary='python3 print_repo_name.py',
21+
repo='git@gitlab.igg.uni-bonn.de:igor/some_project.git',
22+
type='wiki'))
23+
print("[Example]: {binary} {repo} {type}".format(
24+
binary='python3 print_repo_name.py',
25+
repo='https://gitlab.ipb.uni-bonn.de/igor/some_project.git',
26+
type='code'))
27+
exit(1)
28+
if len(sys.argv) == 3:
29+
repo = sys.argv[1]
30+
domain, user, project = parse_git_url(repo)
31+
repo_type = sys.argv[2]
32+
if repo_type == 'wiki':
33+
print(wiki_repo_mask.format(domain=domain,
34+
user=user,
35+
project=project))
36+
elif repo_type == 'code':
37+
print(repo_mask.format(domain=domain,
38+
user=user,
39+
project=project))
40+
else:
41+
print('ERROR: type "{}" is not "wiki" or "code"'.format(repo_type))
42+
43+
44+
if __name__ == '__main__':
45+
main()

ipb_homework_checker/tests/test_tools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ def test_sleep_timeout(self):
4747
cmd_result.stderr,
4848
"Timeout: command 'sleep 10' ran longer than 1 seconds")
4949

50+
def test_git_url(self):
51+
"""Test that we can break an endless loop."""
52+
domain, user, project = tools.parse_git_url(
53+
"https://gitlab.ipb.uni-bonn.de/igor/some_project.git")
54+
self.assertEqual(domain, "gitlab.ipb.uni-bonn.de")
55+
self.assertEqual(user, "igor")
56+
self.assertEqual(project, "some_project")
57+
domain, user, project = tools.parse_git_url(
58+
"git@gitlab.ipb.uni-bonn.de:igor/some_project.git")
59+
self.assertEqual(domain, "gitlab.ipb.uni-bonn.de")
60+
self.assertEqual(user, "igor")
61+
self.assertEqual(project, "some_project")
62+
domain, user, project = tools.parse_git_url(
63+
"git@github.com:PRBonn/depth_clustering.git")
64+
self.assertEqual(domain, "github.com")
65+
self.assertEqual(user, "PRBonn")
66+
self.assertEqual(project, "depth_clustering")
67+
5068
def test_endless_loop_timeout(self):
5169
"""Test that we can break an endless loop."""
5270
from time import monotonic as timer

ipb_homework_checker/tools.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ def convert_to(output_type, value):
6262
return result, "OK"
6363

6464

65+
def parse_git_url(git_url):
66+
"""Parse the git url.
67+
68+
Args:
69+
git_url (str): url of a git repository (https or ssh)
70+
71+
Returns:
72+
(str, str, str): tupple of domain, user and project name parsed from url
73+
"""
74+
import re
75+
regex = re.compile(r'(?:git@|https:\/\/)' # Prefix
76+
r'([\w\-_\.]+)' # Domain
77+
r'[:\/]' # Separator : or /
78+
r'([\w\-_\.\/]+)' # User or folders
79+
r'[\/]' # Separator /
80+
r'([\w\-_]+)' # Project name
81+
r'(?:.git)*$') # .git or nothing
82+
domain, user, project = regex.search(git_url).groups()
83+
return domain, user, project
84+
85+
6586
class CmdResult:
6687
"""A small container for command result."""
6788
SUCCESS = 0
@@ -153,7 +174,7 @@ def run_command(command, shell=True, cwd=path.curdir, env=environ, timeout=20):
153174
return CmdResult(returncode=1, stderr=output_text)
154175

155176

156-
def __run_subprocess(*popenargs,
177+
def __run_subprocess(command,
157178
input=None,
158179
timeout=None,
159180
check=False,
@@ -178,7 +199,7 @@ def __run_subprocess(*popenargs,
178199
import signal
179200
from subprocess import Popen, TimeoutExpired, CalledProcessError
180201
from subprocess import CompletedProcess
181-
with Popen(*popenargs, preexec_fn=os.setsid, **kwargs) as process:
202+
with Popen(command, preexec_fn=os.setsid, **kwargs) as process:
182203
try:
183204
stdout, stderr = process.communicate(input, timeout=timeout)
184205
except TimeoutExpired:

setup.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from setuptools import setup
77
from setuptools.command.install import install
88

9-
VERSION_STRING = '0.0.5'
9+
VERSION_STRING = '0.0.6'
1010

1111
PACKAGE_NAME = 'ipb_homework_checker'
1212

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

0 commit comments

Comments
 (0)