summaryrefslogtreecommitdiffstats
path: root/gd_diff.py
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2016-09-24 20:05:14 +0000
committerrsiddharth <s@ricketyspace.net>2016-09-24 20:05:14 +0000
commite2e157cfc3286a291e64121bf1422faf85094880 (patch)
tree96803368649637f95648bdc9f8e084371812d421 /gd_diff.py
parentfac05f29bbd7a7bbddb9de828b502c40e40e2a4e (diff)
add gd_diff.py + tests for functions in it.
* gd_diff.py (read_file, get_packages): add functions. * tests/__init__.py: add file. * tests/files/pkgs.list: add file. * tests/test_gd_diff.py: add file.
Diffstat (limited to 'gd_diff.py')
-rw-r--r--gd_diff.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/gd_diff.py b/gd_diff.py
new file mode 100644
index 0000000..97cf175
--- /dev/null
+++ b/gd_diff.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# This file is part of gns-deb-diff.
+#
+# gns-deb-diff is under the Public Domain. See
+# <https://creativecommons.org/publicdomain/zero/1.0>
+
+import sys
+
+# list of recognized fields.
+field_list = [
+ "Change-Type",
+ "Changed-From-Debian",
+]
+
+def read_file(fpath):
+ """Read file `f` and return its content.
+
+ """
+ try:
+ f = open(fpath, 'r')
+ except FileNotFoundError as e:
+ print("Error opening '%s' \n Error Info:\n %r" % (fpath, e),
+ file=sys.stderr)
+ sys.exit(1)
+
+ return f.read()
+
+
+def get_packages(pkgs_file):
+ """Return an iterator contaning of package names from `pkgs_file`.
+
+ """
+ pkgs = read_file(pkgs_file).split('\n')
+ # sanitize
+ pkgs_iter = map(lambda x: x.strip(), pkgs)
+
+ return pkgs_iter