1import sys, os 2import shutil 3from colorama import init 4from termcolor import colored 5 6 7def define_input(proto_input_dir,git_repository_url,git_repository_token): 8 """ 9 :param args: command line args 10 :type args: argparse.Namespace 11 :return: route of the inputdir 12 :type: str 13 """ 14 input_dir = proto_input_dir 15 16 # cloning repository 17 18 if git_repository_url != '': 19 command = '' 20 if str(git_repository_url).lower().find("gitlab") != -1: 21 command = "git clone https://oauth2:" + git_repository_token + "@" + str(git_repository_url).replace("https://", 22 "").replace( 23 "http://", "") 24 elif str(git_repository_url).lower().find("github") != -1: 25 command = "git clone https://" + git_repository_token + "@" + str(git_repository_url).replace("https://", "").replace( 26 "http://", "") 27 if (command == ''): 28 raise ValueError('only support gitlab and github repositories') 29 print(command) 30 out = os.system(command + " proto_temp") 31 # change input dir for clone dir 32 input_dir = os.path.join(os.getcwd(), "proto_temp") 33 else: 34 input_dir = os.popen("pwd").read().rstrip("\n\r") 35 if str(proto_input_dir).startswith("./"): 36 input_dir = os.path.join(input_dir, str(proto_input_dir).replace("./", "")) 37 elif str(proto_input_dir) == '.': 38 raise ValueError('-d , --dir args not target to root folder, locate proto \ 39files in a subfolder. example: ./myProtos') 40 else: 41 input_dir = proto_input_dir 42 return str(input_dir) 43