diff options
Diffstat (limited to 'scripts/lib/bsp')
-rw-r--r-- | scripts/lib/bsp/engine.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/lib/bsp/engine.py b/scripts/lib/bsp/engine.py index 8d47bbfdcd..bd776b2100 100644 --- a/scripts/lib/bsp/engine.py +++ b/scripts/lib/bsp/engine.py | |||
@@ -37,6 +37,7 @@ from abc import ABCMeta, abstractmethod | |||
37 | from tags import * | 37 | from tags import * |
38 | import shlex | 38 | import shlex |
39 | import json | 39 | import json |
40 | import subprocess | ||
40 | 41 | ||
41 | class Line(): | 42 | class Line(): |
42 | """ | 43 | """ |
@@ -204,6 +205,45 @@ class EditBoxInputLine(InputLine): | |||
204 | return line | 205 | return line |
205 | 206 | ||
206 | 207 | ||
208 | class GitRepoEditBoxInputLine(EditBoxInputLine): | ||
209 | """ | ||
210 | Base class for 'editbox' Input lines for user input of remote git | ||
211 | repos. This class verifies the existence and connectivity of the | ||
212 | specified git repo. | ||
213 | |||
214 | props: | ||
215 | name: example - "Load address" | ||
216 | msg: example - "Please enter the load address" | ||
217 | result: | ||
218 | Sets the value of the variable specified by 'name' to | ||
219 | whatever the user typed. | ||
220 | """ | ||
221 | def __init__(self, props, tag, lineno): | ||
222 | EditBoxInputLine.__init__(self, props, tag, lineno) | ||
223 | |||
224 | def gen(self, context = None): | ||
225 | EditBoxInputLine.gen(self, context) | ||
226 | name = self.props["name"] | ||
227 | if not name: | ||
228 | self.parse_error("No input 'name' property found", | ||
229 | self.lineno, self.line) | ||
230 | msg = self.props["msg"] | ||
231 | if not msg: | ||
232 | self.parse_error("No input 'msg' property found", | ||
233 | self.lineno, self.line) | ||
234 | |||
235 | try: | ||
236 | default_choice = self.props["default"] | ||
237 | except KeyError: | ||
238 | default_choice = "" | ||
239 | |||
240 | msg += " [default: " + default_choice + "]" | ||
241 | |||
242 | line = name + " = get_verified_git_repo(\"" + msg + "\"," + name + ")" | ||
243 | |||
244 | return line | ||
245 | |||
246 | |||
207 | class BooleanInputLine(InputLine): | 247 | class BooleanInputLine(InputLine): |
208 | """ | 248 | """ |
209 | Base class for boolean Input lines. | 249 | Base class for boolean Input lines. |
@@ -435,6 +475,40 @@ def default(input_str, name): | |||
435 | return input_str.strip() | 475 | return input_str.strip() |
436 | 476 | ||
437 | 477 | ||
478 | def verify_git_repo(giturl): | ||
479 | """ | ||
480 | Verify that the giturl passed in can be connected to. This can be | ||
481 | used as a check for the existence of the given repo and/or basic | ||
482 | git remote connectivity. | ||
483 | |||
484 | Returns True if the connection was successful, fals otherwise | ||
485 | """ | ||
486 | if not giturl: | ||
487 | return False | ||
488 | |||
489 | gitcmd = "git ls-remote %s > /dev/null 2>&1" % (giturl) | ||
490 | rc = subprocess.call(gitcmd, shell=True) | ||
491 | if rc == 0: | ||
492 | return True | ||
493 | |||
494 | return False | ||
495 | |||
496 | |||
497 | def get_verified_git_repo(input_str, name): | ||
498 | """ | ||
499 | Return git repo if verified, otherwise loop forever asking user | ||
500 | for filename. | ||
501 | """ | ||
502 | msg = input_str.strip() + " " | ||
503 | |||
504 | giturl = default(raw_input(msg), name) | ||
505 | |||
506 | while True: | ||
507 | if verify_git_repo(giturl): | ||
508 | return giturl | ||
509 | giturl = default(raw_input(msg), name) | ||
510 | |||
511 | |||
438 | def boolean(input_str, name): | 512 | def boolean(input_str, name): |
439 | """ | 513 | """ |
440 | Return lowercase version of first char in string, or value in name. | 514 | Return lowercase version of first char in string, or value in name. |
@@ -649,6 +723,8 @@ class SubstrateBase(object): | |||
649 | return BooleanInputLine(props, tag, lineno) | 723 | return BooleanInputLine(props, tag, lineno) |
650 | if input_type == "edit": | 724 | if input_type == "edit": |
651 | return EditBoxInputLine(props, tag, lineno) | 725 | return EditBoxInputLine(props, tag, lineno) |
726 | if input_type == "edit-git-repo": | ||
727 | return GitRepoEditBoxInputLine(props, tag, lineno) | ||
652 | elif input_type == "choicelist": | 728 | elif input_type == "choicelist": |
653 | self.prev_choicelist = ChoicelistInputLine(props, tag, lineno) | 729 | self.prev_choicelist = ChoicelistInputLine(props, tag, lineno) |
654 | return self.prev_choicelist | 730 | return self.prev_choicelist |