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 8c76a064acaf6401cfa6f10e437be0436d7ae26d
parent 60ae86411fb4727dd29baacb60f1d7d78a1c0942
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun,  2 Oct 2016 13:25:35 +0000

Add `save_gns_readme` function (gd_diff.py).

* gd_diff.py (save_gns_readme): New function.
* tests/test_gd_diff.py (test_save_gns_readme)
(test_save_gns_readme_double, test_save_gns_readme_error): Tests for
`save_gns_readme` function.

Diffstat:
gd_diff.py | 34++++++++++++++++++++++++++++++++++
tests/test_gd_diff.py | 44+++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/gd_diff.py b/gd_diff.py @@ -6,9 +6,11 @@ # gns-deb-diff is under the Public Domain. See # <https://creativecommons.org/publicdomain/zero/1.0> +import os import shlex import sys +from os import path from subprocess import run, PIPE @@ -58,3 +60,35 @@ def get_packages(pkgs_file): pkgs_iter = map(lambda x: x.strip(), pkgs) return pkgs_iter + + +def save_gns_readme(content, release, pkg, local_dir): + """Save README.gNewsense locally. + + :param str content: + Content of the README.gNewsense file. + :param str release: + Release name. + :param str pkg: + Package name. + :param str local_dir: + Root directory under which readme of all packages get stored. + """ + # create gns_readme dir. for pkg. + gns_readme_dir = path.join(local_dir, release, pkg, 'debian') + + try: + os.makedirs(gns_readme_dir, exist_ok=True) + except Exception as e: + print("Error creating directory '%s'\n Error Info:\n %r" % (gns_readme_dir, e), + file=sys.stderr) + sys.exit(1) + + gns_readme = path.join(gns_readme_dir, 'README.gNewSense') + + with open(gns_readme, 'wb') as f: + f.write(content) + f.flush() + print('Saved {}'.format(gns_readme)) + + diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py @@ -10,6 +10,9 @@ import os import subprocess import sys +from os import path +from shutil import rmtree + from nose.tools import * from gd_diff import * @@ -21,6 +24,7 @@ class TestGdDiff(object): """Setup method for this class.""" self.pkgs_file = "tests/files/pkgs.list" self.pkgs_file_ne = 'tests/nonexistent-file.list' + self.gns_pkgs_dir = 'tests/gns-pkgs' def test_read_file_success(self): f_content = read_file(self.pkgs_file) @@ -67,7 +71,45 @@ class TestGdDiff(object): for pkg in pkgs_iter: assert not ' ' in pkg + def test_save_gns_readme(self): + cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' + cp = execute(cmd, out=subprocess.PIPE) + readme_content = cp.stdout + + # save it + save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + + 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_save_gns_readme_double(self): + cmd = 'bzr cat bzr://bzr.sv.gnu.org/gnewsense/packages-parkes/antlr/debian/README.gNewSense' + cp = execute(cmd, out=subprocess.PIPE) + readme_content = cp.stdout + + # save it twice + save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + + 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' + + @raises(SystemExit) + def test_save_gns_readme_error(self): + os.mkdir(self.gns_pkgs_dir, mode=0o500) + + # must error out + readme_content = 'lorem ipsum' + with open(os.devnull, 'w') as sys.stderr: + save_gns_readme(readme_content, 'parkes', 'antlr', self.gns_pkgs_dir) + + def teardown(self): """Teardown method for this class.""" - pass + if(path.exists(self.gns_pkgs_dir)): + os.chmod(self.gns_pkgs_dir, mode=0o700) + rmtree(self.gns_pkgs_dir)