Permalink
Browse files

Add setup.py and refactor accordingly

Make this thing an installable package and provide an xpisign
script/command
  • Loading branch information...
1 parent fbc988d commit 27a3e40664c5e7f44770365051525b1cfe8e76eb @nmaier committed Apr 28, 2012
Showing with 635 additions and 551 deletions.
  1. +6 −0 .gitignore
  2. +88 −0 scripts/xpisign
  3. +35 −0 setup.py
  4. +0 −551 xpisign.py
  5. +1 −0 xpisign/__init__.py
  6. +270 −0 xpisign/api.py
  7. +34 −0 xpisign/compat.py
  8. +48 −0 xpisign/context.py
  9. +153 −0 xpisign/crypto.py
View
@@ -0,0 +1,6 @@
+*.pyc
+*.egg-info
+*.xpi
+*.pem
+build/
+dist/
View
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+import os
+import sys
+
+from optparse import OptionParser
+
+from xpisign import xpisign, __version__
+from xpisign.compat import BytesIO
+
+def main(args):
+ global smime_pkcs7_der_sign
+
+ optparse = OptionParser(usage="Usage: %prog [options] xpifile outfile")
+ optparse.add_option("-k",
+ "--keyfile",
+ dest="keyfile",
+ default="sign.pem",
+ help="Key file to get the certificate from"
+ )
+ optparse.add_option("-f",
+ "--force",
+ dest="force",
+ action="store_true",
+ default=False,
+ help="Force signing, i.e. overwrite outfile if it already exists"
+ )
+ optparse.add_option("-o",
+ "--optimize",
+ dest="optimize",
+ action="store_true",
+ default=False,
+ help="Optimize signatures, avoiding inclusion of weak hashes. Also optimize the compression level."
+ )
+ optparse.add_option("-s",
+ "--signer",
+ dest="signer",
+ default=None,
+ help="Force signing with a particular implementation (m2, openssl)"
+ )
+ options, args = optparse.parse_args(args)
+ try:
+ xpifile, outfile = args
+ except ValueError:
+ optparse.error("Need to specify xpifile and outfile!")
+
+ if not os.path.isfile(xpifile):
+ optparse.error("xpifile %s is not a file" % xpifile)
+
+ if not options.force and os.path.exists(outfile):
+ optparse.error("outfile %s already exists" % outfile)
+
+ keyfile = options.keyfile
+ if not os.path.exists(keyfile):
+ optparse.error("keyfile %s cannot be found" % keyfile)
+
+ optimize = options.optimize
+ signer = options.signer
+
+ try:
+ # buffer stuff, in case xpifile == outfile
+ with open(xpifile, "rb") as tp:
+ xp = BytesIO(tp.read())
+ with xp:
+ try:
+ with BytesIO() as op:
+ try:
+ xpisign(xpifile=xp,
+ keyfile=keyfile,
+ outfile=op,
+ optimize_signatures=optimize,
+ optimize_compression=optimize,
+ signer=signer
+ )
+ with open(outfile, "wb") as outp:
+ outp.write(op.getvalue())
+ except ValueError, ex:
+ optparse.error(ex.message)
+ except IOError:
+ optparse.error("Failed to open outfile %s" % outfile)
+ except IOError:
+ optparse.error("Failed to open xpifile %s" % xpifile)
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
+
+# vim: ts=4:sw=4:et
View
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+
+import xpisign.api as xpisign
+
+classifiers = ["Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: Public Domain",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Topic :: Software Development :: Build Tools",
+ ]
+
+docstrings = xpisign.__doc__.split("\n")
+
+setup(name="xpisign",
+ version=xpisign.__version__,
+
+ author="Nils Maier",
+ author_email="maierman@web.de",
+ license="Public Domain",
+ url="https://github.com/nmaier/xpisign.py",
+ classifiers=classifiers,
+ description=docstrings[0],
+ long_description="\n".join(docstrings[1:]).strip(),
+
+ platforms=["any"],
+ scripts=["scripts/xpisign"],
+ packages=["xpisign"],
+
+ )
Oops, something went wrong.

0 comments on commit 27a3e40

Please sign in to comment.