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 da3aa246e8b1960da04ddbe0127d6b71a2c82650
parent 8c76a064acaf6401cfa6f10e437be0436d7ae26d
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun,  2 Oct 2016 15:21:52 +0000

Add `slurp_gns_readme` function (gd_diff).

* gd_diff.py (slurp_gns_readme): New function.
* tests/test_gd_diff.py (test_slurp_gns_readme_success)
(test_slurp_gns_readme_error): Tests for `slurp_gns_readme` function.
(setup, teardown): Update functions.

Diffstat:
gd_diff.py | 21+++++++++++++++++++++
tests/test_gd_diff.py | 24++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -20,6 +20,11 @@ field_list = [ "Changed-From-Debian", ] +# bzr +bzr_base_url = 'bzr://bzr.savannah.gnu.org/gnewsense/' +readme_url_fmt = '%s/packages-{}/{}/debian/README.gNewSense' % bzr_base_url + + def read_file(fpath): """Read file `f` and return its content. @@ -92,3 +97,19 @@ def save_gns_readme(content, release, pkg, local_dir): print('Saved {}'.format(gns_readme)) +def slurp_gns_readme(release, pkg, local_dir): + """Read and save the README.gNewSense for `pkg` in `release`. + + The README.gNewSense file gets save at `local_dir`/`release`/`pkg`/debian/ + """ + readme_url = readme_url_fmt.format(release, pkg) + cmd = 'bzr cat {}'.format(readme_url) + cp = execute(cmd, out=PIPE, err=PIPE) + + if(cp.returncode == 0): + save_gns_readme(cp.stdout, release, pkg, local_dir) + return True + else: + print("README.gNewSense not found for package {}".format(pkg), + file=sys.stderr) + return False diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -25,6 +25,7 @@ class TestGdDiff(object): self.pkgs_file = "tests/files/pkgs.list" self.pkgs_file_ne = 'tests/nonexistent-file.list' self.gns_pkgs_dir = 'tests/gns-pkgs' + self.stderr_orig = sys.stderr def test_read_file_success(self): f_content = read_file(self.pkgs_file) @@ -107,9 +108,32 @@ class TestGdDiff(object): save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + def test_slurp_gns_readme_success(self): + saved = slurp_gns_readme('parkes', 'antlr', self.gns_pkgs_dir) + assert saved == True + + gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', + 'antlr', 'debian', + 'README.gNewSense') + with open(gns_readme_file, 'rb') as f: + assert f.read() == b'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' + + + def test_slurp_gns_readme_error(self): + saved = slurp_gns_readme('parkes', 'non-existent-pkg', self.gns_pkgs_dir) + assert saved == False + + gns_readme_file = path.join(self.gns_pkgs_dir, 'parkes', + 'non-existent-pkg', 'debian', + 'README.gNewSense') + assert not path.exists(gns_readme_file) + + def teardown(self): """Teardown method for this class.""" if(path.exists(self.gns_pkgs_dir)): os.chmod(self.gns_pkgs_dir, mode=0o700) rmtree(self.gns_pkgs_dir) + # restore sys.stderr + sys.stderr = self.stderr_orig