-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setup.py and refactor accordingly
Make this thing an installable package and provide an xpisign script/command
- Loading branch information
Showing
9 changed files
with
635 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.pyc | ||
*.egg-info | ||
*.xpi | ||
*.pem | ||
build/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
|
||
) |
Oops, something went wrong.