66 except ValueError: |
66 except ValueError: |
67 sys.stdout.write('Please respond with \'y\' or \'n\'.\n') |
67 sys.stdout.write('Please respond with \'y\' or \'n\'.\n') |
68 |
68 |
69 #if user_yes_no_query('want to exit?') == 1: sys.exit() |
69 #if user_yes_no_query('want to exit?') == 1: sys.exit() |
70 |
70 |
71 ''' |
|
72 ## {{{ http://code.activestate.com/recipes/577058/ (r2) |
|
73 def query_yes_no(question, default="yes"): |
|
74 valid = {"yes":"yes", "y":"yes", "ye":"yes", |
|
75 "no":"no", "n":"no"} |
|
76 if default == None: |
|
77 prompt = " [y/n] " |
|
78 elif default == "yes": |
|
79 prompt = " [Y/n] " |
|
80 elif default == "no": |
|
81 prompt = " [y/N] " |
|
82 else: |
|
83 raise ValueError("invalid default answer: '%s'" % default) |
|
84 |
|
85 while 1: |
|
86 sys.stdout.write(question + prompt) |
|
87 choice = input().lower() |
|
88 if default is not None and choice == '': |
|
89 return default |
|
90 elif choice in valid.keys(): |
|
91 return valid[choice] |
|
92 else: |
|
93 sys.stdout.write("Please respond with 'yes' or 'no' "\ |
|
94 "(or 'y' or 'n').\n") |
|
95 ## end of http://code.activestate.com/recipes/577058/ }}} |
|
96 ''' |
|
97 abspath = os.path.abspath(__file__) |
71 abspath = os.path.abspath(__file__) |
98 dname = os.path.dirname(abspath) |
72 dname = os.path.dirname(abspath) |
99 fname = os.path.basename(abspath) |
73 fname = os.path.basename(abspath) |
100 os.chdir(dname) |
74 os.chdir(dname) |
101 |
75 |