summaryrefslogtreecommitdiffstats
path: root/scripts/lib/bsp/engine.py
diff options
context:
space:
mode:
authorTom Zanussi <tom.zanussi@intel.com>2012-12-12 22:56:34 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-12-13 16:54:33 +0000
commit205872b7b88f64dcb5a725e53811aedacac21da1 (patch)
treef125d0ff1d62fef2eb80b8df0772d2c9a68403bc /scripts/lib/bsp/engine.py
parentc08a4dc5eb6709689b52bab8ac946a94d22a6947 (diff)
downloadast2050-yocto-poky-205872b7b88f64dcb5a725e53811aedacac21da1.zip
ast2050-yocto-poky-205872b7b88f64dcb5a725e53811aedacac21da1.tar.gz
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 <tom.zanussi@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/bsp/engine.py')
-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 bd776b2..6309e29 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
OpenPOWER on IntegriCloud