From 205872b7b88f64dcb5a725e53811aedacac21da1 Mon Sep 17 00:00:00 2001 From: Tom Zanussi Date: Wed, 12 Dec 2012 22:56:34 -0600 Subject: yocto-bsp: add 'edit-file' input line Add a subclassed edit box that verifies the existence of a user-specified file. (From meta-yocto rev: 8ca7f688a6a0e41dd6527b1c13ebaa77bbfeba69) Signed-off-by: Tom Zanussi Signed-off-by: Richard Purdie --- scripts/lib/bsp/engine.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'scripts') 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): return line +class FileEditBoxInputLine(EditBoxInputLine): + """ + Base class for 'editbox' Input lines for user input of existing + files. This class verifies the existence of the specified file. + + props: + name: example - "Load address" + msg: example - "Please enter the load address" + result: + Sets the value of the variable specified by 'name' to + whatever the user typed. + """ + def __init__(self, props, tag, lineno): + EditBoxInputLine.__init__(self, props, tag, lineno) + + def gen(self, context = None): + EditBoxInputLine.gen(self, context) + name = self.props["name"] + if not name: + self.parse_error("No input 'name' property found", + self.lineno, self.line) + msg = self.props["msg"] + if not msg: + self.parse_error("No input 'msg' property found", + self.lineno, self.line) + + try: + default_choice = self.props["default"] + except KeyError: + default_choice = "" + + msg += " [default: " + default_choice + "]" + + line = name + " = get_verified_file(\"" + msg + "\"," + name + ", True)" + + return line + + class BooleanInputLine(InputLine): """ Base class for boolean Input lines. @@ -509,6 +547,23 @@ def get_verified_git_repo(input_str, name): giturl = default(raw_input(msg), name) +def get_verified_file(input_str, name, filename_can_be_null): + """ + Return filename if the file exists, otherwise loop forever asking + user for filename. + """ + msg = input_str.strip() + " " + + filename = default(raw_input(msg), name) + + while True: + if not filename and filename_can_be_null: + return filename + if os.path.isfile(filename): + return filename + filename = default(raw_input(msg), name) + + def boolean(input_str, name): """ Return lowercase version of first char in string, or value in name. @@ -725,6 +780,8 @@ class SubstrateBase(object): return EditBoxInputLine(props, tag, lineno) if input_type == "edit-git-repo": return GitRepoEditBoxInputLine(props, tag, lineno) + if input_type == "edit-file": + return FileEditBoxInputLine(props, tag, lineno) elif input_type == "choicelist": self.prev_choicelist = ChoicelistInputLine(props, tag, lineno) return self.prev_choicelist -- cgit v1.2.3-54-g00ecf