Skip to content

Commit

Permalink
New deb_pkg_tools.control.load_control_file() function
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 5, 2014
1 parent c6bf8c3 commit 3e192d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions deb_pkg_tools/__init__.py
@@ -1,11 +1,11 @@
# Debian packaging tools.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 1, 2014
# Last Change: June 5, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

# Semi-standard module versioning.
__version__ = '1.20.4'
__version__ = '1.20.5'

debian_package_dependencies = (
'apt', # apt-get
Expand Down
12 changes: 11 additions & 1 deletion deb_pkg_tools/control.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Control file manipulation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 1, 2014
# Last Change: June 5, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand Down Expand Up @@ -37,6 +37,16 @@
# separated list of package names with optional version specifications).
DEPENDS_LIKE_FIELDS = ('Conflicts', 'Depends', 'Provides', 'Replaces', 'Suggests')

def load_control_file(control_file):
"""
Load a control file and return the parsed control fields.
:param control_file: The filename of the control file to load (a string).
:returns: A dictionary created by :py:func:`parse_control_fields()`.
"""
with open(control_file) as handle:
return parse_control_fields(Deb822(handle))

def patch_control_file(control_file, overrides):
"""
Patch the fields of a Debian control file.
Expand Down
10 changes: 5 additions & 5 deletions deb_pkg_tools/tests.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Automated tests.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 1, 2014
# Last Change: June 5, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

# Standard library modules.
Expand All @@ -25,6 +25,7 @@
from deb_pkg_tools.cli import main
from deb_pkg_tools.compat import StringIO, unicode
from deb_pkg_tools.control import (deb822_from_string,
load_control_file,
merge_control_fields,
parse_control_fields,
unparse_control_fields)
Expand Down Expand Up @@ -92,7 +93,7 @@ def test_control_field_merging(self):
'Depends: python-deb-pkg-tools, python-pip, python-pip-accel',
'Architecture: amd64']))

def test_control_file_patching(self):
def test_control_file_patching_and_loading(self):
deb822_package = Deb822(['Package: unpatched-example',
'Depends: some-dependency'])
control_file = tempfile.mktemp()
Expand All @@ -102,10 +103,9 @@ def test_control_file_patching(self):
call('--patch=%s' % control_file,
'--set=Package: patched-example',
'--set=Depends: another-dependency')
with open(control_file) as handle:
patched_fields = Deb822(handle)
patched_fields = load_control_file(control_file)
self.assertEqual(patched_fields['Package'], 'patched-example')
self.assertEqual(patched_fields['Depends'], 'another-dependency, some-dependency')
self.assertEqual(str(patched_fields['Depends']), 'another-dependency, some-dependency')
finally:
os.unlink(control_file)

Expand Down

0 comments on commit 3e192d7

Please sign in to comment.