def test_comments(self):
   self.assertEqual(String.remove_comment(''), '')
   self.assertEqual(String.remove_comment('#'), '')
   self.assertEqual(String.remove_comment('# a comment'), '')
   self.assertEqual(String.remove_comment('hello # a comment'), 'hello ')
   self.assertEqual(String.remove_comment(
     r'hello \# not a comment # a comment'),
     'hello # not a comment ')
Beispiel #2
0
 def test_comments(self):
     self.assertEqual(String.remove_comment(''), '')
     self.assertEqual(String.remove_comment('#'), '')
     self.assertEqual(String.remove_comment('# a comment'), '')
     self.assertEqual(String.remove_comment('hello # a comment'), 'hello ')
     self.assertEqual(
         String.remove_comment(r'hello \# not a comment # a comment'),
         'hello # not a comment ')
Beispiel #3
0
 def test_remove_quotes(self):
     errors = []
     self.assertEqual(String.remove_quotes('hello', print=errors.append),
                      'hello')
     self.assertEqual(String.remove_quotes('"hello"', print=errors.append),
                      'hello')
     self.assertEqual(String.remove_quotes('hello"', print=errors.append),
                      'hello"')
     self.assertEqual(errors, [])
 def test_remove_quotes(self):
   errors = []
   self.assertEqual(String.remove_quotes('hello', print=errors.append),
                    'hello')
   self.assertEqual(String.remove_quotes('"hello"', print=errors.append),
                    'hello')
   self.assertEqual(String.remove_quotes('hello"', print=errors.append),
                    'hello"')
   self.assertEqual(errors, [])
 def test_remove_quotes_error(self):
   errors = []
   self.assertEqual(String.remove_quotes('"hello', print=errors.append),
                    'hello')
   self.assertEqual(errors,
                    ['WARNING: line started with " but didn\'t end with one:',
                     '"hello'])
Beispiel #6
0
 def test_remove_quotes_error(self):
     errors = []
     self.assertEqual(String.remove_quotes('"hello', print=errors.append),
                      'hello')
     self.assertEqual(errors, [
         'WARNING: line started with " but didn\'t end with one:', '"hello'
     ])
Beispiel #7
0
def execute(args, include_errors=True, **kwds):
    """Execute a shell command and return the value.  If args is a string,
    it's split on spaces - if some of your arguments contain spaces, args should
    instead be a list of arguments."""
    if String.is_string(args):
        args = args.split()
    stderr = subprocess.STDOUT if include_errors else None
    return subprocess.check_output(args, stderr=stderr, **kwds)
Beispiel #8
0
def execute(args, include_errors=True, **kwds):
    """Execute a shell command and return the value.  If args is a string,
    it's split on spaces - if some of your arguments contain spaces, args should
    instead be a list of arguments."""
    if String.is_string(args):
        args = args.split()
    stderr = subprocess.STDOUT if include_errors else None
    return subprocess.check_output(args, stderr=stderr, **kwds)
Beispiel #9
0
def print_build_vars(name, value, same, print=print):
    """Pretty-print values as a build configuration."""
    name = '%s' % name.rjust(FIELD_WIDTH)
    color = Terminal.blue if same else Terminal.green

    for line in TEXT_WRAPPER.wrap(String.stringify(value, ' ')):
        print(' '.join([name, color(line)]))
        name = EMPTY_NAME
Beispiel #10
0
def print_build_vars(name, value, same, print=print):
    """Pretty-print values as a build configuration."""
    name = '%s' % name.rjust(FIELD_WIDTH)
    color = Terminal.blue if same else Terminal.green

    for line in TEXT_WRAPPER.wrap(String.stringify(value, ' ')):
        print(' '.join([name, color(line)]))
        name = EMPTY_NAME
Beispiel #11
0
def read_env_file(data, print=print):
    try:
        return json.loads(data)
    except ValueError:
        pass

    bad_lines = []
    results = {}
    for number, raw_line in enumerate(data.splitlines()):
        line = String.remove_comment(raw_line).strip()
        if line:
            match = ENV_LINE_MATCH.match(line)
            if match:
                name, value = match.groups()
                results[name.strip()] = String.remove_quotes(value.strip())
            else:
                bad_lines.append([number, raw_line])
    if bad_lines:
        warn("Didn't understand the following environment file lines:", print)
        for number, line in bad_lines:
            print('%d. >>> %s' % (number + 1, line))

    return results
def read_env_file(data, print=print):
    try:
        return json.loads(data)
    except ValueError:
        pass

    bad_lines = []
    results = {}
    for number, raw_line in enumerate(data.splitlines()):
        line = String.remove_comment(raw_line).strip()
        if line:
            match = ENV_LINE_MATCH.match(line)
            if match:
                name, value = match.groups()
                results[name.strip()] = String.remove_quotes(value.strip())
            else:
                bad_lines.append([number, raw_line])
    if bad_lines:
        warn("Didn't understand the following environment file lines:", print)
        for number, line in bad_lines:
            print("%d. >>> %s" % (number + 1, line))

    return results
Beispiel #13
0
def first_fields_after_prefix(filename, prefix):
    with open(filename, 'r') as f:
        return String.first_fields_after_prefix(prefix, f)
Beispiel #14
0
def print_cmd_line(s, target, source, env):
    print(EMPTY_NAME + Terminal.blue(String.stringify(target)))
Beispiel #15
0
def describe(**kwds):
    return String.single_line(Execute.execute("git describe --tags", **kwds))
Beispiel #16
0
def print_cmd_line(s, target, source, env):
    print(EMPTY_NAME + Terminal.blue(String.stringify(target)))
Beispiel #17
0
def describe(**kwds):
    return String.single_line(Execute.execute('git describe --tags', **kwds))