Commit 33b5fee8 authored by David Danier's avatar David Danier

Cleanup of URL check and fitting changes into normal b5 coding style

parent ca36c09b
...@@ -5,27 +5,29 @@ from urllib.error import URLError ...@@ -5,27 +5,29 @@ from urllib.error import URLError
class Skeleton: class Skeleton:
NON_URL_SKELETON = re.compile('^[A-Za-z0-9_-]+$')
def __init__(self, skeleton): def __init__(self, skeleton_identified):
self._skeleton = skeleton self._skeleton_identified = skeleton_identified
def get_url(self): def get_url(self):
if not self._url: try:
non_url_skeleton = re.compile('^[A-Za-z0-9_-]+$') return self._url
if non_url_skeleton.match(self._skeleton): except AttributeError:
self._url = 'https://git.team23.de/build/b5-skel-{skeleton}.git'.format(skeleton=self._skeleton) skeleton_url = self._skeleton_identified
'''if it's not a public repository, clone using ssh in order to allow ssh key file auth''' if self.NON_URL_SKELETON.match(skeleton_url):
if not self.__is_public_repository(self._url): skeleton_url = 'https://git.team23.de/build/b5-skel-{skeleton}.git'.format(skeleton=self._skeleton_identified)
self._url = 'git@git.team23.de:build/b5-skel-{skeleton}.git'.format(skeleton=self._skeleton) # If it's not a public repository, clone using ssh in order to allow ssh key file auth
else: if not self.__is_public_repository(skeleton_url):
self._url = self._skeleton skeleton_url = 'git@git.team23.de:build/b5-skel-{skeleton}.git'.format(skeleton=self._skeleton_identified)
return self._url self._url = skeleton_url
return self._url
def __is_public_repository(self, url): def __is_public_repository(self, url):
request = urllib.request.urlopen(self._url) request = urllib.request.urlopen(url)
request_url = request.geturl() request_url = request.geturl()
if self._url == request_url or os.path.splitext(self._url)[0] == request_url: if url == request_url or url.rsplit('.', 1)[0] == request_url:
try: try:
if request.getcode() == 200: if request.getcode() == 200:
return True return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment