Date: Thu, 12 Dec 2013 01:03:55 +0000 From: "Teske, Devin" <Devin.Teske@fisglobal.com> To: "Daniel O'Connor" <doconnor@gsoft.com.au> Cc: Kevin Oberman <rkoberman@gmail.com>, Devin Teske <dteske@freebsd.org>, "freebsd-stable@freebsd.org Stable" <freebsd-stable@freebsd.org>, "Teske, Devin" <Devin.Teske@fisglobal.com>, Darren Pilgrim <list_freebsd@bluerosetech.com> Subject: Re: BIND segway -> python -> first-class ports Message-ID: <4174A92E-F202-4FFB-BFED-C38A9D0A7F91@fisglobal.com> In-Reply-To: <0EC3A50D-A6BE-4F3B-87D6-AB0470F0BA64@gsoft.com.au> References: <20131210023615.GR55638@funkthat.com> <52A68141.6010003@mu.org> <622122.74675.bm@smtp120.sbc.mail.gq1.yahoo.com> <20131210224915.GA55638@funkthat.com> <CAN6yY1tSqbrkt5bkjhDW6npT4PAXmMck0Xco%2BERwBE=wkkBDBQ@mail.gmail.com> <52A82099.9080100@bluerosetech.com> <B62F85D0-89E6-4FF8-ADE4-5025FB360462@gsoft.com.au> <D0F85D74-E727-4487-AEA1-B9C16660192E@fisglobal.com> <0EC3A50D-A6BE-4F3B-87D6-AB0470F0BA64@gsoft.com.au>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Dec 11, 2013, at 3:09 PM, Daniel O'Connor wrote:
>
> On 12 Dec 2013, at 2:16, Teske, Devin <Devin.Teske@fisglobal.com> wrote:
>> On Dec 11, 2013, at 2:45 AM, Daniel O'Connor wrote:
>> On 11 Dec 2013, at 18:51, Darren Pilgrim <list_freebsd@bluerosetech.com> wrote:
>>>> On 12/10/2013 9:34 PM, Kevin Oberman wrote:
>>>>> A parseable output from gpart would be wonderful.
>>>>
>>>> Have you seen the kern.geom.conf* sysctls?
>>>
>>> Have you tried parsing them from a shell script? :)
>>>
>>
>> Trivial in my honest opinion. I'm just working on other ``more important'' things.
>
> I'd be interested in seeing such trivial code.
>
> Parsing XML using standard shell tools (and without making assumptions about line breaks etc etc) is pretty tedious :(
Sure, here we go... see attached "geom_parser-0.0.sh"
--
Devin
_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
[-- Attachment #2 --]
#!/bin/sh
. /usr/share/bsdconfig/struct.subr || exit 1
parse_geom_confxml()
{
# NB: Change "echo" to "eval" below to perform the output
echo "$( sysctl -n kern.geom.confxml | awk '
BEGIN {
struct_count["class"] = 0
struct_count["geom"] = 0
struct_count["consumer"] = 0
struct_count["provider"] = 0
}
############################################### FUNCTIONS
function set_value(prop, value)
{
if (!struct_stack[cur_struct]) return failure
printf "%s set %s \"%s\"\n",
struct_stack[cur_struct], prop, value
}
function create(type, id)
{
if (struct = created[type "_" id]) {
print "f_struct_free", struct
print "f_struct_new GEOM_" toupper(type), struct
} else {
struct = struct_stack[cur_struct]
struct = struct ( struct ? "" : "geom" )
struct = struct "_" type "_" ++struct_count[type]
print "f_struct_new GEOM_" toupper(type), struct
}
struct_stack[++cur_struct] = struct
set_value("id", id)
}
function extract_attr(field, attr)
{
if (match(field, attr "=\"0x[[:xdigit:]]+\"")) {
len = length(attr)
return substr($2, len + 3, RLENGTH - len - 3)
}
}
function extract_data(type)
{
data = $0
sub("^[[:space:]]*<" type ">", "", data)
sub("</" type ">.*$", "", data)
return data
}
############################################### OPENING PATTERNS
$1 ~ /^<mesh/ { mesh = 1 }
$1 ~ /^<(class|geom|consumer|provider)$/ && mesh {
if ((ref = extract_attr($2, "ref")) != "")
set_value(substr($1, 2) "_ref", ref)
else if ((id = extract_attr($2, "id")) != "")
create(substr($1, 2), id)
}
############################################### PROPERTIES
$1 ~ /^<[[:alnum:]]+>/ {
prop = $1
sub(/^</, "", prop); sub(/>.*/, "", prop)
set_value(prop, extract_data(prop))
}
############################################### CLOSING PATTERNS
$1 ~ "^</(consumer|provider)>$" {
cur_struct--
}
$1 == "</geom>" {
cur_struct--
set_value("nconsumers", struct_count["consumer"])
set_value("nproviders", struct_count["provider"])
struct_count["consumer"] = 0
struct_count["provider"] = 0
}
$1 == "</class>" {
set_value("ngeoms", struct_count["geom"])
cur_struct--
struct_count["consumer"] = 0
struct_count["provider"] = 0
struct_count["geom"] = 0
}
$1 == "</mesh>" {
printf "NGEOM_CLASSES=%u\n", struct_count["class"]
delete struct_count
mesh = 0
}
' )"
}
parse_geom_confxml
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4174A92E-F202-4FFB-BFED-C38A9D0A7F91>
