~mdw
/
distorted-keys
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
New key type `reop'.
[distorted-keys]
/
extract-profile.in
diff --git
a/extract-profile.in
b/extract-profile.in
index
1d19fc2
..
0de7af0
100755
(executable)
--- a/
extract-profile.in
+++ b/
extract-profile.in
@@
-277,9
+277,11
@@
class Section (object, UD.DictMixin):
## Otherwise take as many constituent characters as we can.
else:
left = dol + 1
## Otherwise take as many constituent characters as we can.
else:
left = dol + 1
-
while left < n and (string[left].isalnum() or string[left] in '-_')
:
+
if left < n and string[left] == '@'
:
left += 1
left += 1
- prop = string[dol + 1:left].replace('-', '_')
+ while left < n and (string[left].isalnum() or string[left] in '%-_'):
+ left += 1
+ prop = string[dol + 1:left]
## If we came up empty, report an error.
if prop == '':
## If we came up empty, report an error.
if prop == '':
@@
-287,6
+289,7
@@
class Section (object, UD.DictMixin):
"invalid placeholder (empty name) in `%s'" % string
## Extend the path: we're going to do a recursive expansion.
"invalid placeholder (empty name) in `%s'" % string
## Extend the path: we're going to do a recursive expansion.
+ prop = prop.replace('-', '_')
path.append(prop)
## Report a cycle if we found one.
path.append(prop)
## Report a cycle if we found one.
@@
-295,10
+298,13
@@
class Section (object, UD.DictMixin):
(' -> '.join(["`%s'" % p for p in path[seen[prop]:]]))
## Look up the raw value.
(' -> '.join(["`%s'" % p for p in path[seen[prop]:]]))
## Look up the raw value.
- try:
- value = me.inherited[prop]
- except KeyError:
- raise UserError, "unknown property `%s'" % prop
+ if prop == '@name':
+ value = me.name
+ else:
+ try:
+ value = me.inherited[prop]
+ except KeyError:
+ raise UserError, "unknown property `%s'" % prop
## Recursively expand, and unwind the PATH and SEEN stuff.
seen[prop] = len(path) - 1
## Recursively expand, and unwind the PATH and SEEN stuff.
seen[prop] = len(path) - 1
@@
-375,6
+381,8
@@
def parse(filename, d):
continue
if line[0] == '[' and line[-1] == ']':
sect = line[1:-1]
continue
if line[0] == '[' and line[-1] == ']':
sect = line[1:-1]
+ if sect not in d:
+ d[sect] = Section(sect)
continue
## Parse an assignment.
continue
## Parse an assignment.
@@
-388,23
+396,18
@@
def parse(filename, d):
name = name.replace('-', '_')
if not (name and
(name in SPECIALS or
name = name.replace('-', '_')
if not (name and
(name in SPECIALS or
- all(map(lambda ch: ch
== '
_' or ch.isalnum(), name)))):
+ all(map(lambda ch: ch
in '%
_' or ch.isalnum(), name)))):
raise UserError, "%s:%d: bad name `%s'" % (filename, n, name)
## Store the assignment.
raise UserError, "%s:%d: bad name `%s'" % (filename, n, name)
## Store the assignment.
- try:
- d[sect][name] = value
- except KeyError:
- s = Section(sect)
- d[sect] = s
- s[name] = value
+ d[sect][name] = value
###--------------------------------------------------------------------------
### Main program.
OP = O.OptionParser(
###--------------------------------------------------------------------------
### Main program.
OP = O.OptionParser(
- usage = '%prog
FILE|DIRECTORY ... SECTION
',
- version = '%%prog,
version %s' % VERSION
,
+ usage = '%prog
SECTION FILE|DIRECTORY ...
',
+ version = '%%prog,
%s version %s' % (PACKAGE, VERSION)
,
description = '''\
Parse the configurations FILE and DIRECTORY contents, and output the named
SECTION as a sequence of simple assignments.
description = '''\
Parse the configurations FILE and DIRECTORY contents, and output the named
SECTION as a sequence of simple assignments.
@@
-417,8
+420,8
@@
def main(args):
opts, args = OP.parse_args(args[1:])
if len(args) < 2:
OP.error('not enough positional parameters')
opts, args = OP.parse_args(args[1:])
if len(args) < 2:
OP.error('not enough positional parameters')
-
files = args[:-1
]
-
sect = args[-1
]
+
sect = args[0
]
+
files = args[1:
]
## Read in the inputs.
d = { '@GLOBAL': Section('@GLOBAL') }
## Read in the inputs.
d = { '@GLOBAL': Section('@GLOBAL') }
@@
-445,6
+448,7
@@
def main(args):
except KeyError:
raise UserError, "unknown section `%s'" % sect
for k, v in s.inherited.iteritems():
except KeyError:
raise UserError, "unknown section `%s'" % sect
for k, v in s.inherited.iteritems():
+ if '%' in k: continue
print '%s=%s' % (k, s.expand(v))
## Report errors for expected problems.
print '%s=%s' % (k, s.expand(v))
## Report errors for expected problems.