Python library for reading Debian package files and comparing version strings
Go to file
Nathan J. Mehl c56c520950 python3 and travis support
- python3 compatibility
- drop py2.6 support
- use email.message rather than rfc822.message
- add some initial debug logging
- pylint and pep8 fixes
- add object properties for file hashes
- add a simple cli demo script
- add travis for continuous build
2017-06-04 15:23:14 -07:00
pydpkg python3 and travis support 2017-06-04 15:23:14 -07:00
scripts python3 and travis support 2017-06-04 15:23:14 -07:00
tests python3 and travis support 2017-06-04 15:23:14 -07:00
.gitignore python3 and travis support 2017-06-04 15:23:14 -07:00
.travis.yml python3 and travis support 2017-06-04 15:23:14 -07:00
LICENSE.txt initial commit 2017-01-25 12:21:08 -08:00
README.md python3 and travis support 2017-06-04 15:23:14 -07:00
setup.cfg initial commit 2017-01-25 12:21:08 -08:00
setup.py python3 and travis support 2017-06-04 15:23:14 -07:00

README.md

Build Status

python-dpkg

This library can be used to:

  1. read and extract control data from Debian-format package files, even on platforms that generally lack a native implementation of dpkg

  2. compare dpkg version strings, using a pure Python implementation of the algorithm described at https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

This is primarily intended for use on platforms that do not normally ship python-apt due to licensing restrictions or the lack of a native libapt.so (e.g. macOS)

Currently only tested on CPython 2.7 and 3.5, but at least in theory should run on any python distribution that can install the arpy library.

Installing

Install the 'pydpkg' package from PyPi using the pip tool:

$ pip install pydpkg
Collecting pydpkg
  Downloading pydpkg-1.1-py2-none-any.whl
  Installing collected packages: pydpkg
  Successfully installed pydpkg-1.1

Usage

Read and extract headers

>>> from pydpkg import Dpkg
>>> dp = Dpkg('/tmp/testdeb_1:0.0.0-test_all.deb')

>>> dp.headers
{'maintainer': u'Climate Corp Engineering <no-reply@climate.com>', 'description': u'testdeb\n a bogus debian package for testing dpkg builds', 'package': u'testdeb', 'section': u'base', 'priority': u'extra', 'installed-size': u'0', 'version': u'1:0.0.0-test', 'architecture': u'all'}

>>> print dp
Package: testdeb
Version: 1:0.0.0-test
Section: base
Priority: extra
Architecture: all
Installed-Size: 0
Maintainer: Climate Corp Engineering <no-reply@climate.com>
Description: testdeb
 a bogus debian package for testing dpkg builds

Interact directly with the package control message

>>> dp.message
<email.message.Message instance at 0x10895c6c8>
>>> dp.message.get_content_type()
'text/plain'

Get package file fingerprints

>>> dp.fileinfo
{'sha256': '547500652257bac6f6bc83f0667d0d66c8abd1382c776c4de84b89d0f550ab7f', 'sha1': 'a5d28ae2f23e726a797349d7dd5f21baf8aa02b4', 'filesize': 910, 'md5': '149e61536a9fe36374732ec95cf7945d'}
>>> dp.md5
'149e61536a9fe36374732ec95cf7945d'
>>> dp.sha1
'a5d28ae2f23e726a797349d7dd5f21baf8aa02b4'
>>> dp.sha256
'547500652257bac6f6bc83f0667d0d66c8abd1382c776c4de84b89d0f550ab7f'
>>> dp.filesize
910

Get an arbitrary control header, case-independent

>>> dp.get_header('version')
u'1:0.0.0-test'

>>> dp.get_header('VERSION')
u'1:0.0.0-test'

Compare current version to a candidate version

>>> dp.compare_version_with('1.0')
1

>>> dp.compare_version_with('1:1.0')
-1

Compare two arbitrary version strings

>>> from pydpkg import Dpkg
>>> ver_1 = '0:1.0-test1'
>>> ver_2 = '0:1.0-test2'
>>> Dpkg.compare_versions(ver_1, ver_2)
-1

Use as a cmp function to sort a list of version strings

>>> from pydpkg import Dpkg
>>> sorted(['0:1.0-test1', '1:0.0-test0', '0:1.0-test2'] , cmp=Dpkg.compare_versions)
['0:1.0-test1', '0:1.0-test2', '1:0.0-test0']

Use the dpkg-inspect.py script to inspect packages

$ dpkg-inspect.py ~/testdeb*deb
Filename: /Home/n/testdeb_1:0.0.0-test_all.deb
Size:     910
MD5:      149e61536a9fe36374732ec95cf7945d
SHA1:     a5d28ae2f23e726a797349d7dd5f21baf8aa02b4
SHA256:   547500652257bac6f6bc83f0667d0d66c8abd1382c776c4de84b89d0f550ab7f
Headers:
  Package: testdeb
  Version: 1:0.0.0-test
  Section: base
  Priority: extra
  Architecture: all
  Installed-Size: 0
  Maintainer: Nathan Mehl <n@climate.com>
  Description: testdeb
   a bogus debian package for testing dpkg builds