summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Wilcox <AWilcox@Wilcox-Tech.com>2015-10-08 20:16:13 -0500
committerAndrew Wilcox <AWilcox@Wilcox-Tech.com>2015-10-08 20:16:13 -0500
commitfa9d3308fa1cd4c3a61a348659b6ecf23d8a3085 (patch)
tree8370813b2ae196949eda15faaf1fac4d566ce9bc
parente28c629584d07594c7abe6bc07145d6359d51566 (diff)
downloadapkkit-fa9d3308fa1cd4c3a61a348659b6ecf23d8a3085.tar.gz
apkkit-fa9d3308fa1cd4c3a61a348659b6ecf23d8a3085.tar.bz2
apkkit-fa9d3308fa1cd4c3a61a348659b6ecf23d8a3085.tar.xz
apkkit-fa9d3308fa1cd4c3a61a348659b6ecf23d8a3085.zip
PEP 8 + PyFlakes + PyLint fixes
-rw-r--r--apkkit/base/package.py20
-rw-r--r--apkkit/io/apkfile.py32
2 files changed, 40 insertions, 12 deletions
diff --git a/apkkit/base/package.py b/apkkit/base/package.py
index e80e08c..9985e6b 100644
--- a/apkkit/base/package.py
+++ b/apkkit/base/package.py
@@ -1,11 +1,10 @@
+"""Contains the Package class and related helper classes and functions."""
+
from jinja2 import Template
import os
-"""Contains the Package class and related helper classes and functions."""
-
-
-pkginfo_template = Template("""
+PKGINFO_TEMPLATE = Template("""
# Generated by APK Kit for Adélie Linux
# {{ builduser }}@{{ buildhost }} {{ builddate }}
pkgname = {{ package.name }}
@@ -44,8 +43,8 @@ class Package:
:param int size:
(Recommended) The installed size of the package. You almost always
- want to set this to something other than 0 if you don't want unhappy
- users. :)
+ want to set this to something other than 0 if you don't want
+ unhappy users. :)
:param str url:
(Optional) The URL of the homepage for the package.
@@ -57,7 +56,7 @@ class Package:
(Optional) One or more packages that are required to be installed
to use this package.
"""
-
+
self._pkgname = name
self._pkgver = str(version)
self._pkgdesc = description or name
@@ -124,14 +123,14 @@ class Package:
.. note:: To write a file, see the :py:meth:`.write_pkginfo` helper
method.
"""
- return pkginfo_template.render(builduser=os.environ.get('USER', '?'),
+ return PKGINFO_TEMPLATE.render(builduser=os.environ.get('USER', '?'),
buildhost=os.uname().nodename,
package=self)
@classmethod
def from_pkginfo(cls, buf):
"""Create a new :py:class:`Package` object from an existing PKGINFO.
-
+
:param buf:
The buffer to read from (whether file, StringIO, etc).
@@ -152,8 +151,7 @@ class Package:
params['depends'] = list()
for line in buf.readlines():
- # XXX TODO make this better
- if type(line) != str:
+ if not isinstance(line, str):
line = line.decode('utf-8')
# Skip comments.
diff --git a/apkkit/io/apkfile.py b/apkkit/io/apkfile.py
index 327ba08..313f485 100644
--- a/apkkit/io/apkfile.py
+++ b/apkkit/io/apkfile.py
@@ -1,10 +1,40 @@
+"""I/O classes and helpers for APK files."""
+
from apkkit.base.package import Package
-import gzip # Not used, but we need to raise ImportError if gzip isn't built.
+# Not used, but we need to raise ImportError if gzip isn't built.
+import gzip # pylint: disable=unused-import
import tarfile
+
class APKFile:
"""Represents an APK file on disk (or in memory)."""
def __init__(self, filename, mode='r'):
self.tar = tarfile.open(filename, mode)
self.package = Package.from_pkginfo(self.tar.extractfile('.PKGINFO'))
+
+ @classmethod
+ def create(cls, package, datadir, sign=True, signfile=None, data_hash=True,
+ hash_method='sha1'):
+ """Create an APK file in memory from a package and data directory.
+
+ :param package:
+ A :py:class:`Package` instance that describes the package.
+
+ :param datadir:
+ The path to the directory containing the package's data.
+
+ :param bool sign:
+ Whether to sign the package (default True).
+
+ :param signfile:
+ The path to the GPG key to sign the package with.
+
+ :param bool data_hash:
+ Whether to hash the data (default True).
+
+ :param str hash_method:
+ The hash method to use for hashing the data - default is sha1 to
+ maintain compatibility with upstream apk-tools.
+ """
+ raise NotImplementedError