Skip to content

Commit

Permalink
Add setup.py and refactor accordingly
Browse files Browse the repository at this point in the history
Make this thing an installable package and provide an xpisign
script/command
  • Loading branch information
nmaier committed Apr 28, 2012
1 parent fbc988d commit 27a3e40
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 551 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.egg-info
*.xpi
*.pem
build/
dist/
88 changes: 88 additions & 0 deletions scripts/xpisign
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"],

)
Loading

0 comments on commit 27a3e40

Please sign in to comment.