Skip to content

Commit

Permalink
Fix rosdep files check/clean scripts
Browse files Browse the repository at this point in the history
Use pyyaml internal rules to decide whether to put quotes
or not around strings. This prevents crashes for gentoo rules (among others)
  • Loading branch information
Paul Mathieu committed Feb 19, 2013
1 parent a83cc4d commit d28e40c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
9 changes: 4 additions & 5 deletions scripts/check_rosdep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import sys

indent_atom = ' '
#!/usr/bin/env python
#

# pretty - A miniature library that provides a Python print and stdout
# wrapper that makes colored terminal text easier to use (eg. without
# having to mess around with ANSI escape sequences). This code is public
# domain - there is no license except that you must leave this header.
#
# Copyright (C) 2008 Brian Nez <thedude at bri1 dot com>
#

import sys
# With modifications
# (C) 2013 Paul M <[email protected]>

codeCodes = {
'black': '0;30', 'bright gray': '0;37',
Expand Down Expand Up @@ -103,7 +102,7 @@ def check_brackets(buf):
def fun(i, l, o):
m = re.match(r'^(?:' + indent_atom + r')*([^:]*):\s*(\w.*)$', l)
if m is not None and m.groups()[0] not in excepts:
print_err("lists of packages not in square brackets line %u" % (i+1))
print_err("list not in square brackets line %u" % (i+1))
return False
return True
return generic_parser(buf, fun)
Expand Down
15 changes: 9 additions & 6 deletions scripts/clean_rosdep_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import yaml
import argparse
import re

dont_bracket = ['uri', 'md5sum']
use_quotes = ['>', '=']

def paddify(s, l):
a = s.split('\n')
Expand All @@ -14,21 +14,24 @@ def paddify(s, l):
buf += "%s%s\n" % (pad, r)
return buf

def quote_if_necessary(s):
if type(s) is list:
return [quote_if_necessary(a) for a in s]
return re.search('{a: (.*)}\n', yaml.dump({'a': s})).group(1)

def prn(n, nm, lvl):
pad = ' ' * lvl
if isinstance(n, list):
return "%s%s: [%s]\n" % (pad, nm, ', '.join(n))
return "%s%s: [%s]\n" % (pad, nm, ', '.join(quote_if_necessary(n)))
elif n is None:
return "%s%s:\n" % (pad, nm)
elif isinstance(n, str):
if len(n.split('\n')) > 1:
return "%s%s: |\n%s" % (pad, nm, paddify(n, lvl+1))
else:
if n.lstrip()[0] in use_quotes:
return "%s%s: ['%s']\n" % (pad, nm, "', '".join(n.split()))
if nm in dont_bracket:
return "%s%s: %s\n" % (pad, nm, n)
return "%s%s: [%s]\n" % (pad, nm, ', '.join(n.split()))
return "%s%s: %s\n" % (pad, nm, quote_if_necessary(n))
return "%s%s: [%s]\n" % (pad, nm, ', '.join(quote_if_necessary(n.split())))
buf = "%s%s:\n" % (pad, nm)
for a in sorted(n.keys()):
buf += prn(n[a], a, lvl+1)
Expand Down

0 comments on commit d28e40c

Please sign in to comment.