gns-deb-diff

automate the documentation of the differences between gNewSense and Debian.
git clone git://git.ricketyspace.net/gns-deb-diff.git
Log | Files | Refs

commit 95d6e1427dad0a8844080b91fdd91385a52a7c6f
parent cf4d1f9279f88deb2d920f9fc611d29378168a87
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun, 30 Oct 2016 19:46:27 +0000

Add `slurp_fields_from_readme` function.

* gd_diff.py (slurp_fields_from_readme): New function.
* tests/test_gd_diff.py (test_slurp_fields_from_readme): Test method for
`slurp_fields_from_readme`

Diffstat:
gd_diff.py | 30++++++++++++++++++++++++++++++
tests/test_gd_diff.py | 44++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -7,6 +7,7 @@ # <https://creativecommons.org/publicdomain/zero/1.0> import os +import re import shlex import sys @@ -143,3 +144,32 @@ def read_gns_readme(release, pkg, local_dir): readme_content = read_file(readme_path) return readme_content + + +def slurp_fields_from_readme(content): + """Returns dict containing fields slurped from `content` + + - If a field is not defined or if its value is empty in the + `content`, then its corresponding value in the dict will be None. + + """ + # list of recognized fields. + field_list = [ + 'Change-Type', + 'Changed-From-Debian', + ] + + field_values = {} + for field in field_list: + pattern = r'{}:[ ]*(.+)'.format(field) + field_pattern = re.compile(pattern) + field_match = field_pattern.search(content) + + if (field_match and + field_match.group(1) and + field_match.group(1).strip()): + field_values[field] = field_match.group(1).strip() + else: + field_values[field] = None + + return field_values diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -154,6 +154,50 @@ class TestGdDiff(object): assert_equal(antlr_readme_content, expected_antlr_readme_content) + def test_slurp_fields_from_readme(self): + readme_content = '' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], None) + assert_equal(field_values['Changed-From-Debian'], None) + + readme_content = 'Changed-From-Debian: \n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], None) + assert_equal(field_values['Changed-From-Debian'], None) + + readme_content = 'Change-Type: Deblob\n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], 'Deblob') + assert_equal(field_values['Changed-From-Debian'], None) + + readme_content = 'Changed-From-Debian: \nChange-Type: \n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], None) + assert_equal(field_values['Changed-From-Debian'], None) + + readme_content = 'Changed-From-Debian: Branding. \nChange-Type: \n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], None) + assert_equal(field_values['Changed-From-Debian'], 'Branding.') + + readme_content = 'Changed-From-Debian: \nChange-Type: Modified' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], 'Modified') + assert_equal(field_values['Changed-From-Debian'], None) + + readme_content = 'Changed-From-Debian:Fixed ambiguous use of the word free.\n\n\nChange-Type:Deblob\n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], 'Deblob') + assert_equal(field_values['Changed-From-Debian'], + 'Fixed ambiguous use of the word free.') + + readme_content = 'Changed-From-Debian: Removed example with non-free files.\nChange-Type: Modified\n\nFor gNewSense, the non-free unicode.IDENTs files are *actually* removed (see\nalso README.source). See gNewSense bug #34218 for details.\n' + field_values = slurp_fields_from_readme(readme_content) + assert_equal(field_values['Change-Type'], 'Modified') + assert_equal(field_values['Changed-From-Debian'], + 'Removed example with non-free files.') + + def teardown(self): """Teardown method for this class.""" if(path.exists(self.gns_pkgs_dir)):