Skip to content

Commit

Permalink
new warning support for conditional streams
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 24, 2015
1 parent 937af98 commit 8a03278
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/admin_scripts/base/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def convert_encoding_walker(arguments, directory_name, names):
)
except:
extra.warn(
"failed converting encoding in file: %s (%s to %s)" %\
"Failed converting encoding in file: %s (%s to %s)" %\
(
valid_complete_name,
source_encoding,
Expand Down
18 changes: 9 additions & 9 deletions src/admin_scripts/base/stylesheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_property_index(property_line, property_order, line_number):
if len(property_line_splitted) > 2:
# warns about the extra values in the line and then returns
# with the length of the property order
extra.warn("extra values found at line %d" % line_number)
extra.warn("Extra values found at line %d" % line_number)

# runs a second split operation that limits the number of splits
# in the line to two so that no extra problems are raised and then
Expand All @@ -127,7 +127,7 @@ def get_property_index(property_line, property_order, line_number):
if not property_name in property_order:
# warns about the missing property name
extra.warn(
"order for property %s not defined at line %d" %\
"Order for property %s not defined at line %d" %\
(property_name, line_number)
)

Expand Down Expand Up @@ -206,7 +206,7 @@ def process_property_line(property_line, line_number):
# is considered to be empty (warning required) logs the message
# and then returns the line itself (no processing)
if not property_line.strip():
extra.warn("empty stylesheet property at line %s" % line_number)
extra.warn("Empty stylesheet property at line %s" % line_number)
return property_line

# strips the line to the right so that no newline characters
Expand Down Expand Up @@ -274,8 +274,8 @@ def fix_color(color):
color = color.lower()

# in case the color length is not in the valid range
# raises an exception indicatin the problem
if not color_length in VALID_COLOR_LENGTHS:
# raises an exception
raise Exception("invalid color length")

# in case the color is compacted
Expand Down Expand Up @@ -369,15 +369,15 @@ def cleanup_properties(input_buffer, windows_newline, fix_extra_newlines, proper
elif "/*" in line:
# in case the comment mode is already on
if comments_started: extra.warn(
"found opening comment inside open comment at line %d" % line_number
"Found opening comment inside open comment at line %d" % line_number
)

# increments the comments started counter
comments_started += 1
# in case the line contains the end of multiline comment
elif "*/" in line:
if not comments_started: extra.error(
"found closing comment without corresponding opening at line %d" % line_number
"Found closing comment without corresponding opening at line %d" % line_number
)

# decrements the comments started counter
Expand Down Expand Up @@ -419,7 +419,7 @@ def cleanup_properties(input_buffer, windows_newline, fix_extra_newlines, proper
# in case the rule set does not contain any property
# must log an information message about the empty rule
if rule_started and not rule_lines:
extra.warn("empty stylesheet rule at line %d" % line_number)
extra.warn("Empty stylesheet rule at line %d" % line_number)

# updates the flag to signal the rule has ended
rule_started = False
Expand Down Expand Up @@ -475,13 +475,13 @@ def cleanup_properties(input_buffer, windows_newline, fix_extra_newlines, proper
# otherwise in case this is an extra newline
elif not needs_newline and newlines > 1:
# logs a warning about this extra newline
extra.warn("found extra newline at line %d" % line_number)
extra.warn("Found extra newline at line %d" % line_number)

# disables the needs newline flag
needs_newline = False
else:
# warns about the statement outside a valid rule
extra.warn("found statement outside rule at line %d" % line_number)
extra.warn("Found statement outside rule at line %d" % line_number)

# writes the line to the output buffer taking into
# account the windows newline control flag
Expand Down
11 changes: 8 additions & 3 deletions src/admin_scripts/extra/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@

import sys

USE_STDERR = False

STDOUT = sys.stdout
STDERR = sys.stderr if USE_STDERR else STDOUT

def echo(message):
sys.stdout.write(message + "\n")
STDOUT.write(message + "\n")

def warn(message):
sys.stderr.write("WARNING: " + message + "\n")
STDERR.write("WARNING: " + message + "\n")

def error(message):
sys.stderr.write("ERROR: " + message + "\n")
STDERR.write("ERROR: " + message + "\n")

0 comments on commit 8a03278

Please sign in to comment.