summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/bsp/engine.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/lib/bsp/engine.py b/scripts/lib/bsp/engine.py
index bd776b2100..6309e29a23 100644
--- a/scripts/lib/bsp/engine.py
+++ b/scripts/lib/bsp/engine.py
@@ -244,6 +244,44 @@ class GitRepoEditBoxInputLine(EditBoxInputLine):
244 return line 244 return line
245 245
246 246
247class FileEditBoxInputLine(EditBoxInputLine):
248 """
249 Base class for 'editbox' Input lines for user input of existing
250 files. This class verifies the existence of the specified file.
251
252 props:
253 name: example - "Load address"
254 msg: example - "Please enter the load address"
255 result:
256 Sets the value of the variable specified by 'name' to
257 whatever the user typed.
258 """
259 def __init__(self, props, tag, lineno):
260 EditBoxInputLine.__init__(self, props, tag, lineno)
261
262 def gen(self, context = None):
263 EditBoxInputLine.gen(self, context)
264 name = self.props["name"]
265 if not name:
266 self.parse_error("No input 'name' property found",
267 self.lineno, self.line)
268 msg = self.props["msg"]
269 if not msg:
270 self.parse_error("No input 'msg' property found",
271 self.lineno, self.line)
272
273 try:
274 default_choice = self.props["default"]
275 except KeyError:
276 default_choice = ""
277
278 msg += " [default: " + default_choice + "]"
279
280 line = name + " = get_verified_file(\"" + msg + "\"," + name + ", True)"
281
282 return line
283
284
247class BooleanInputLine(InputLine): 285class BooleanInputLine(InputLine):
248 """ 286 """
249 Base class for boolean Input lines. 287 Base class for boolean Input lines.
@@ -509,6 +547,23 @@ def get_verified_git_repo(input_str, name):
509 giturl = default(raw_input(msg), name) 547 giturl = default(raw_input(msg), name)
510 548
511 549
550def get_verified_file(input_str, name, filename_can_be_null):
551 """
552 Return filename if the file exists, otherwise loop forever asking
553 user for filename.
554 """
555 msg = input_str.strip() + " "
556
557 filename = default(raw_input(msg), name)
558
559 while True:
560 if not filename and filename_can_be_null:
561 return filename
562 if os.path.isfile(filename):
563 return filename
564 filename = default(raw_input(msg), name)
565
566
512def boolean(input_str, name): 567def boolean(input_str, name):
513 """ 568 """
514 Return lowercase version of first char in string, or value in name. 569 Return lowercase version of first char in string, or value in name.
@@ -725,6 +780,8 @@ class SubstrateBase(object):
725 return EditBoxInputLine(props, tag, lineno) 780 return EditBoxInputLine(props, tag, lineno)
726 if input_type == "edit-git-repo": 781 if input_type == "edit-git-repo":
727 return GitRepoEditBoxInputLine(props, tag, lineno) 782 return GitRepoEditBoxInputLine(props, tag, lineno)
783 if input_type == "edit-file":
784 return FileEditBoxInputLine(props, tag, lineno)
728 elif input_type == "choicelist": 785 elif input_type == "choicelist":
729 self.prev_choicelist = ChoicelistInputLine(props, tag, lineno) 786 self.prev_choicelist = ChoicelistInputLine(props, tag, lineno)
730 return self.prev_choicelist 787 return self.prev_choicelist