From: Martin Jansa <martin.jansa@gmail.com>
To: mulhern <mulhern@gmail.com>
Cc: yocto@yoctoproject.org, mulhern@yoctoproject.org
Subject: Re: [PATCH 5/5] Bastille: set Yocto specific questions via config file.
Date: Mon, 26 Aug 2013 09:19:29 +0200 [thread overview]
Message-ID: <20130826071929.GM3544@jama> (raw)
In-Reply-To: <349e64db470d1dd1b87a1ee1ac45dbf698a88f2c.1377479358.git.mulhern@yoctoproject.org>
[-- Attachment #1: Type: text/plain, Size: 6719 bytes --]
On Sun, Aug 25, 2013 at 09:17:12PM -0400, mulhern wrote:
> [YOCTO #3867]
>
> The python script, set_required_questions.py reads the list of questions and
> answers from the config file and edits the REQUIRE_DISTRO field for those
> questions in the questions file so that it includes "Yocto" if it is not
> already present. This has the effect of causing Bastille, when loading
> questions for the Yocto distribution, to load only those that are answered
> in the existing config file. Under the assumption that the exisitng config
> file contains question/answer pairs that are relevant to the Yocto project,
> this will cause the interactive question screen to have answers that are
> relevant to the Yocto project.
>
> Signed-off-by: mulhern <mulhern@yoctoproject.org>
> ---
> recipes-security/bastille/bastille_3.2.1.bb | 3 +
> .../bastille/files/set_required_questions.py | 135 ++++++++++++++++++++
> 2 files changed, 138 insertions(+)
> create mode 100755 recipes-security/bastille/files/set_required_questions.py
>
> diff --git a/recipes-security/bastille/bastille_3.2.1.bb b/recipes-security/bastille/bastille_3.2.1.bb
> index 8969f6b..094f09c 100644
> --- a/recipes-security/bastille/bastille_3.2.1.bb
> +++ b/recipes-security/bastille/bastille_3.2.1.bb
> @@ -139,6 +139,9 @@ do_install () {
> install -m 0644 OSMap/HP-UX.service ${D}${datadir}/Bastille/OSMap
> install -m 0644 OSMap/OSX.bastille ${D}${datadir}/Bastille/OSMap
> install -m 0644 OSMap/OSX.system ${D}${datadir}/Bastille/OSMap
> +
> + ${THISDIR}/files/set_required_questions.py ${WORKDIR}/config Questions
> +
Inconsistent whitespace.
> install -m 0777 ${WORKDIR}/config ${D}${sysconfdir}/Bastille/config
>
> for file in `cat Modules.txt` ; do
> diff --git a/recipes-security/bastille/files/set_required_questions.py b/recipes-security/bastille/files/set_required_questions.py
> new file mode 100755
> index 0000000..a432dc5
> --- /dev/null
> +++ b/recipes-security/bastille/files/set_required_questions.py
> @@ -0,0 +1,135 @@
> +#!/usr/bin/env python
> +
> +import argparse, os, shutil, sys, tempfile
> +from os import path
> +
> +
> +
> +def get_config(lines):
> + """
> + From a sequence of lines retrieve the question file name, question identifier
> + pairs.
> + """
> + for l in lines:
> + if not l.startswith("#"):
> + try:
> + (coord, value) = l.split("=")
> + try:
> + (fname, ident) = coord.split(".")
> + yield fname, ident
> + except ValueError as e:
> + raise ValueError("Badly formatted coordinates %s in line %s." % (coord, l.strip()))
> + except ValueError as e:
> + raise ValueError("Skipping badly formatted line %s, %s" % (l.strip(), e))
> +
> +
> +
> +def check_contains(line, name):
> + """
> + Check if the value field for REQUIRE_DISTRO contains the given name.
> + @param name line The REQUIRE_DISTRO line
> + @param name name The name to look for in the value field of the line.
> + """
> + try:
> + (label, distros) = line.split(":")
> + return name in distros.split()
> + except ValueError as e:
> + raise ValueError("Error splitting REQUIRE_DISTRO line: %s" % e)
> +
> +
> +
> +def add_requires(the_ident, distro, lines):
> +
> + """
> + Yield a sequence of lines the same as lines except that where
> + the_ident matches a question identifier change the REQUIRE_DISTRO so that
> + it includes the specified distro.
> +
> + @param name the_ident The question identifier to be matched.
> + @param name distro The distribution to added to the questions REQUIRE_DISTRO
> + field.
> + @param lines The sequence to be processed.
> + """
> + for l in lines:
> + yield l
> + if l.startswith("LABEL:"):
> + try:
> + (label, ident) = l.split(":")
> + if ident.strip() == the_ident:
> + break
> + except ValueError as e:
> + raise ValueError("Unexpected line %s in questions file." % l.strip())
> + for l in lines:
> + if l.startswith("REQUIRE_DISTRO"):
> + if not check_contains(l, distro):
> + yield l.rstrip() + " " + distro + "\n"
> + else:
> + yield l
> + break;
> + else:
> + yield l
> + for l in lines:
> + yield l
> +
> +
> +
> +def xform_file(qfile, distro, qlabel):
> + questions_in = open(qfile)
> + questions_out = tempfile.NamedTemporaryFile(delete=False)
> + for l in add_requires(qlabel, distro, questions_in):
> + questions_out.write(l)
> + questions_out.close()
> + questions_in.close()
> + shutil.move(questions_out.name, qfile)
> +
> +
> +
> +def handle_args(parser):
> + parser.add_argument('config_file',
> + help = "Configuration file path.")
> + parser.add_argument('questions_dir',
> + help = "Directory containing Questions files.")
> + parser.add_argument('--distro', '-d',
> + help = "The distribution, the default is Yocto.",
> + default = "Yocto")
> + return parser.parse_args()
> +
> +
> +
> +def check_args(args):
> + args.config_file = os.path.abspath(args.config_file)
> + args.questions_dir = os.path.abspath(args.questions_dir)
> +
> + if not os.path.isdir(args.questions_dir):
> + raise ValueError("Specified Questions directory %s does not exist or is not a directory." % args.questions_dir)
> +
> + if not os.path.isfile(args.config_file):
> + raise ValueError("Specified configuration file %s not found." % args.config_file)
> +
> +
> +
> +def main():
> + opts = handle_args(argparse.ArgumentParser(description="A simple script that sets required questions based on the question/answer pairs in a configuration file."))
> +
> + try:
> + check_args(opts)
> + except ValueError as e:
> + sys.exit("Fatal error: %s" % e)
> +
> +
> + try:
> + config_in = open(opts.config_file)
> + for qfile, qlabel in get_config(config_in):
> + questions_file = os.path.join(opts.questions_dir, qfile + ".txt")
> + xform_file(questions_file, opts.distro, qlabel)
> + config_in.close()
> +
> + except IOError as e:
> + sys.exit("Fatal error reading config file: %s" % e)
> + except ValueError as e:
> + sys.exit("Fatal error: %s" % e)
> +
> +
> +
> +if __name__ == "__main__":
> + main()
> --
> 1.7.10.4
>
> _______________________________________________
> yocto mailing list
> yocto@yoctoproject.org
> https://lists.yoctoproject.org/listinfo/yocto
--
Martin 'JaMa' Jansa jabber: Martin.Jansa@gmail.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 205 bytes --]
prev parent reply other threads:[~2013-08-26 7:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-26 1:17 [PATCH 0/5] [meta-security] Bastille bug fixes and enhancements mulhern
2013-08-26 1:17 ` [PATCH 1/5] Bastille: Preliminary cleanup of existing patches mulhern
2013-08-26 1:17 ` [PATCH 2/5] Bastille: Miscellaneous fixes to the Bastille code base mulhern
2013-08-26 1:17 ` [PATCH 3/5] Bastille: change in behavior of bastille -l mulhern
2013-08-26 1:17 ` [PATCH 4/5] Bastille: accept and observe --os flag in multiple situations mulhern
2013-08-26 1:17 ` [PATCH 5/5] Bastille: set Yocto specific questions via config file mulhern
2013-08-26 7:19 ` Martin Jansa [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130826071929.GM3544@jama \
--to=martin.jansa@gmail.com \
--cc=mulhern@gmail.com \
--cc=mulhern@yoctoproject.org \
--cc=yocto@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.