yocto-bsp: add 'edit-git-repo' input line
Add a subclassed edit box that verifies the existence of a user-specified git repo. Also adds a verify_git_repo() function that can be used as a basic sanity check for local git setup. (From meta-yocto rev: 64f1176d62ed02d7c61d32fdae11dc8b7d365603) Signed-off-by: Tom Zanussi <tom.zanussi@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
254bf8c5d9
commit
c08a4dc5eb
|
@ -37,6 +37,7 @@ from abc import ABCMeta, abstractmethod
|
||||||
from tags import *
|
from tags import *
|
||||||
import shlex
|
import shlex
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
class Line():
|
class Line():
|
||||||
"""
|
"""
|
||||||
|
@ -204,6 +205,45 @@ class EditBoxInputLine(InputLine):
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
class GitRepoEditBoxInputLine(EditBoxInputLine):
|
||||||
|
"""
|
||||||
|
Base class for 'editbox' Input lines for user input of remote git
|
||||||
|
repos. This class verifies the existence and connectivity of the
|
||||||
|
specified git repo.
|
||||||
|
|
||||||
|
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_git_repo(\"" + msg + "\"," + name + ")"
|
||||||
|
|
||||||
|
return line
|
||||||
|
|
||||||
|
|
||||||
class BooleanInputLine(InputLine):
|
class BooleanInputLine(InputLine):
|
||||||
"""
|
"""
|
||||||
Base class for boolean Input lines.
|
Base class for boolean Input lines.
|
||||||
|
@ -435,6 +475,40 @@ def default(input_str, name):
|
||||||
return input_str.strip()
|
return input_str.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def verify_git_repo(giturl):
|
||||||
|
"""
|
||||||
|
Verify that the giturl passed in can be connected to. This can be
|
||||||
|
used as a check for the existence of the given repo and/or basic
|
||||||
|
git remote connectivity.
|
||||||
|
|
||||||
|
Returns True if the connection was successful, fals otherwise
|
||||||
|
"""
|
||||||
|
if not giturl:
|
||||||
|
return False
|
||||||
|
|
||||||
|
gitcmd = "git ls-remote %s > /dev/null 2>&1" % (giturl)
|
||||||
|
rc = subprocess.call(gitcmd, shell=True)
|
||||||
|
if rc == 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_verified_git_repo(input_str, name):
|
||||||
|
"""
|
||||||
|
Return git repo if verified, otherwise loop forever asking user
|
||||||
|
for filename.
|
||||||
|
"""
|
||||||
|
msg = input_str.strip() + " "
|
||||||
|
|
||||||
|
giturl = default(raw_input(msg), name)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if verify_git_repo(giturl):
|
||||||
|
return giturl
|
||||||
|
giturl = default(raw_input(msg), name)
|
||||||
|
|
||||||
|
|
||||||
def boolean(input_str, name):
|
def boolean(input_str, name):
|
||||||
"""
|
"""
|
||||||
Return lowercase version of first char in string, or value in name.
|
Return lowercase version of first char in string, or value in name.
|
||||||
|
@ -649,6 +723,8 @@ class SubstrateBase(object):
|
||||||
return BooleanInputLine(props, tag, lineno)
|
return BooleanInputLine(props, tag, lineno)
|
||||||
if input_type == "edit":
|
if input_type == "edit":
|
||||||
return EditBoxInputLine(props, tag, lineno)
|
return EditBoxInputLine(props, tag, lineno)
|
||||||
|
if input_type == "edit-git-repo":
|
||||||
|
return GitRepoEditBoxInputLine(props, tag, lineno)
|
||||||
elif input_type == "choicelist":
|
elif input_type == "choicelist":
|
||||||
self.prev_choicelist = ChoicelistInputLine(props, tag, lineno)
|
self.prev_choicelist = ChoicelistInputLine(props, tag, lineno)
|
||||||
return self.prev_choicelist
|
return self.prev_choicelist
|
||||||
|
|
Loading…
Reference in New Issue