Commit 0252d30f authored by Emanuel Jacob's avatar Emanuel Jacob

build(gitlab#3): Change move skeleton code fragments to lib/Skeleton class, make use of that class

parent 965e26ee
import argparse
import os
import re
import shutil
import subprocess
import sys
import urllib.request
import termcolor
from .lib.skeleton import Skeleton
from .exceptions import B5ExecutionError
NON_URL_SKELETON = re.compile('^[A-Za-z0-9_-]+$')
def _run_cmd(cmd, error='Command execution failed, see above'):
......@@ -45,27 +40,17 @@ def main():
args = parser.parse_args()
skeleton = args.skeleton
skeleton = Skeleton(args.skeleton)
branch = args.branch
path = args.path
if NON_URL_SKELETON.match(skeleton):
skeleton_url = '{skeleton}.git'.format(skeleton=skeleton)
'''if it's not a public repository, clone using ssh in order to allow ssh key file auth'''
if not is_public_repository(skeleton_url):
skeleton_url = '{skeleton}.git'.format(skeleton=skeleton)
skeleton_url = skeleton
full_path = os.path.realpath(os.path.join(os.getcwd(), path))
os.makedirs(full_path, exist_ok=True)
if os.listdir(full_path):
raise B5ExecutionError('Cannot init an existing directory if not empty')
_run_cmd(['git', 'clone', skeleton_url, full_path], 'Could not clone skeleton repository, see above')
_run_cmd(['git', 'clone', skeleton.url, full_path], 'Could not clone skeleton repository, see above')
if not branch is None:
_run_cmd(['git', 'checkout', branch], 'Could not checkout required branch, see above')
......@@ -84,21 +69,8 @@ def main():
# _run_cmd(['git', 'add', '-A'])
termcolor.cprint('Successful initialized {path}'.format(path=path), 'green')
termcolor.cprint(' skeleton used: {skeleton_url}'.format(skeleton_url=skeleton_url), 'green')
termcolor.cprint(' skeleton used: {skeleton_url}'.format(skeleton_url=skeleton.url), 'green')
termcolor.cprint(' project path: {full_path}'.format(full_path=full_path), 'green')
except B5ExecutionError as error:
termcolor.cprint(str(error), 'red')
def is_public_repository(url):
req = urllib.request.urlopen(url)
req_url = req.geturl()
if url == req_url or os.path.splitext(url)[0] == req_url :
if req.getcode() == 200 :
return True
except Exception:
return False
return False
\ No newline at end of file
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