From 5a3eaca8b0203fbb2984b4d485acfab553eacb18 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Wed, 20 Jul 2016 17:00:08 +0200 Subject: [PATCH] Fix path already exists error in compiler. --- compile.py | 36 +----------------------------------- compile_single.py | 4 +++- helpers/compile_helper.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/compile.py b/compile.py index debc4ae16..d807da32e 100755 --- a/compile.py +++ b/compile.py @@ -9,40 +9,6 @@ from helpers import compile_helper from subprocess import call - -def query_yes_no(question, default="yes"): - """Ask a yes/no question via raw_input() and return their answer. - - "question" is a string that is presented to the user. - "default" is the presumed answer if the user just hits . - It must be "yes" (the default), "no" or None (meaning - an answer is required of the user). - - The "answer" return value is True for "yes" or False for "no". - """ - valid = {"yes": True, "y": True, "ye": True, - "no": False, "n": False} - if default is None: - prompt = " [y/n] " - elif default == "yes": - prompt = " [Y/n] " - elif default == "no": - prompt = " [y/N] " - else: - raise ValueError("invalid default answer: '%s'" % default) - - while True: - sys.stdout.write(question + prompt) - choice = raw_input().lower() - if default is not None and choice == '': - return valid[default] - elif choice in valid: - return valid[choice] - else: - sys.stdout.write("Please respond with 'yes' or 'no' " - "(or 'y' or 'n').\n") - - # Add this to your path protoc_path = "protoc" @@ -69,7 +35,7 @@ def query_yes_no(question, default="yes"): if not default_out_path: print 'Can we remove "%s"?' % tmp_out_path - may_remove = query_yes_no("Please answer.", default="no") + may_remove = compile_helper.query_yes_no("Please answer.", default="no") else: may_remove = True diff --git a/compile_single.py b/compile_single.py index 409a9c3ae..6e776ccc0 100644 --- a/compile_single.py +++ b/compile_single.py @@ -37,7 +37,9 @@ # Create necessary directory os.makedirs(tmp_path) -os.makedirs(out_path) + +if not os.path.exists(out_path): + os.makedirs(out_path) created_packages = [] diff --git a/helpers/compile_helper.py b/helpers/compile_helper.py index 4936efdd8..882371b59 100644 --- a/helpers/compile_helper.py +++ b/helpers/compile_helper.py @@ -13,3 +13,36 @@ def finish_compile(out_path, lang): with open(init_path, 'w') as init_file: if pogo_protos_path is root: init_file.write("'Generated'; import os; import sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))") + + +def query_yes_no(question, default="yes"): + """Ask a yes/no question via raw_input() and return their answer. + + "question" is a string that is presented to the user. + "default" is the presumed answer if the user just hits . + It must be "yes" (the default), "no" or None (meaning + an answer is required of the user). + + The "answer" return value is True for "yes" or False for "no". + """ + valid = {"yes": True, "y": True, "ye": True, + "no": False, "n": False} + if default is None: + prompt = " [y/n] " + elif default == "yes": + prompt = " [Y/n] " + elif default == "no": + prompt = " [y/N] " + else: + raise ValueError("invalid default answer: '%s'" % default) + + while True: + sys.stdout.write(question + prompt) + choice = raw_input().lower() + if default is not None and choice == '': + return valid[default] + elif choice in valid: + return valid[choice] + else: + sys.stdout.write("Please respond with 'yes' or 'no' " + "(or 'y' or 'n').\n")