Beispiel #1
0
def FilesUpdated(file_name, new_text, binary):
    """Diff the rendered acl with what's already on disk.

     Args:
       file_name: Name of file on disk to check against.
       file_string: Text of newly generated ACL.
       binary: True if file is a binary format.
  """
    try:
        if binary:
            conf = open(file_name, 'rb').read()
        else:
            conf = open(file_name).read()
    except IOError:
        return True
    if not binary:
        p4_id = '$I d:'.replace(' ', '')
        p4_date = '$Da te:'.replace(' ', '')
        p4_revision = '$Rev ision:'.replace(' ', '')

        p4_tags = lambda x: p4_id in x or p4_date in x or p4_revision in x

        conf = SkipLines(conf.split('\n'), skip_line_func=p4_tags)
        new_text = SkipLines(new_text.split('\n'), skip_line_func=p4_tags)

    diff = difflib.unified_diff(conf, new_text)

    # why oh why is it so hard to simply tell if two strings/lists are different?
    if not difflib.IS_CHARACTER_JUNK(''.join(diff)):
        logging.debug('\n'.join(diff))
        return True

    return False
Beispiel #2
0
def FilesUpdated(file_name, file_string):
    """Diff the rendered acl with what's already on disk."""
    try:
        conf = open(file_name).read()
    except IOError:
        return True

    p4_id = '$I d:'.replace(' ', '')
    p4_date = '$Da te:'.replace(' ', '')
    p4_revision = '$Rev ision:'.replace(' ', '')

    p4_tags = lambda x: p4_id in x or p4_date in x or p4_revision in x

    checked_in_text = SkipLines(conf.split('\n'), skip_line_func=p4_tags)
    new_text = SkipLines(file_string.split('\n'), skip_line_func=p4_tags)

    diff = difflib.unified_diff(checked_in_text, new_text)

    # why oh why is it so hard to simply tell if two strings/lists are different?
    if not difflib.IS_CHARACTER_JUNK(''.join(diff)):
        logging.debug('\n'.join(diff))
        return True

    return False
Beispiel #3
0
 def test_is_character_junk_false(self):
     for char in ['a', '#', '\n', '\f', '\r', '\v']:
         self.assertFalse(difflib.IS_CHARACTER_JUNK(char), repr(char))
Beispiel #4
0
 def test_is_character_junk_true(self):
     for char in [' ', '\t']:
         self.assertTrue(difflib.IS_CHARACTER_JUNK(char), repr(char))
Beispiel #5
0
def ignore_line_ending(ch):
    return difflib.IS_CHARACTER_JUNK(ch, ws=" \r\n")
def is_char_junk(ch):
    return difflib.IS_CHARACTER_JUNK(ch, ws=' \t\n')
Beispiel #7
0
 def update_event(self, inp=-1):
     self.set_output_val(0, difflib.IS_CHARACTER_JUNK(self.input(0), self.input(1)))