This repository was archived by the owner on Apr 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 361
generate-config: display line numbers in errors #172
Merged
jeffkaufman
merged 3 commits into
oschaaf-generate-config
from
oschaaf-generate-config-linenumbers
Feb 13, 2013
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,49 +14,77 @@ | |
# | ||
# Author: [email protected] (Otto van der Schaaf) | ||
|
||
import sys | ||
import traceback | ||
|
||
class Error(Exception): | ||
pass | ||
|
||
def write_cfg(key_to_writer, config, level=0): | ||
def pyconf_fatal(lineno, e = None): | ||
message = "Exception while processing line [%s] from pyconf" % lineno | ||
if e: message = "%s\n\n%s\n" % (message,traceback.format_exc()) | ||
sys.exit(message) | ||
|
||
def exec_template_call(func, lineno, item, level): | ||
try: | ||
return func(item, level) | ||
except Exception as e: | ||
pyconf_fatal(lineno, e) | ||
raise | ||
|
||
def write_cfg(key_to_writer, config, key_to_node, level=0, parent_key = ""): | ||
global global_writer | ||
|
||
for key in config: | ||
key_path = "%s.%s" % (parent_key, key) | ||
next_level = level | ||
lineno = "unknown" | ||
handled = False | ||
|
||
if key_path in key_to_node: | ||
lineno = key_to_node[key_path].lineno | ||
|
||
if key + '_open' in key_to_writer: | ||
w = key_to_writer[key + '_open'] | ||
if w != write_void: | ||
next_level = next_level + 1 | ||
handled = w(config[key], level) | ||
|
||
handled = exec_template_call(w, lineno, config[key], level) | ||
|
||
if not handled: | ||
if key + '_open_item' in key_to_writer \ | ||
and isinstance(config[key], list): | ||
for (index, item) in enumerate(config[key]): | ||
w = key_to_writer[key + '_open_item'] | ||
handled = w(item, next_level) | ||
child_key_path = "%s.%s" % (key_path, str(index)) | ||
handled = exec_template_call( | ||
w, lineno, item, next_level) | ||
|
||
if not handled: | ||
write_cfg(key_to_writer, item, level + 1) | ||
write_cfg(key_to_writer, item, key_to_node, | ||
level + 1, child_key_path) | ||
if key + '_close_item' in key_to_writer: | ||
w = key_to_writer[key + '_close_item'] | ||
w(item, next_level) | ||
exec_template_call(w, lineno, item, next_level) | ||
else: | ||
write_cfg(key_to_writer, config[key], level) | ||
write_cfg(key_to_writer, config[key], key_to_node, level | ||
,key_path) | ||
|
||
if key + '_close' in key_to_writer: | ||
w = key_to_writer[key + '_close'] | ||
w(config[key], level) | ||
exec_template_call(w, lineno, config[key], level) | ||
else: | ||
if not isinstance(config[key], str) \ | ||
and not isinstance(config[key], int): | ||
raise Error("no tranform handler for [%s]" % key) | ||
raise Error("no tranform handler for [%s] at line [%s]" | ||
% (key_path, lineno)) | ||
|
||
def indent(txt, level): | ||
lines = txt.split("\n") | ||
r = [] | ||
for line in lines: | ||
if not line: continue | ||
r.append("%s%s\n" % (' ' * (level * 4), line)) | ||
|
||
return ''.join(r) | ||
|
||
def emit_indent(txt,level): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you check for
"#ifdef"
but then below check for"#ifndef "
. Note the space.