Skip to content

Commit

Permalink
Fix path already exists error in compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed Jul 20, 2016
1 parent 399cda0 commit 5a3eaca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
36 changes: 1 addition & 35 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Enter>.
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"

Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion compile_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
33 changes: 33 additions & 0 deletions helpers/compile_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Enter>.
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")

0 comments on commit 5a3eaca

Please sign in to comment.