forked from bannsec/winevt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·99 lines (83 loc) · 3.1 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
import os
from setuptools.command.install import install
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
import shutil
from glob import glob
import sys
here = os.path.abspath(os.path.dirname(__file__))
def _build_ffi():
# This dance is hackish. Probably better way to do this.
# chdir so we know where we're importing from
old_dir = os.path.abspath(os.curdir)
os.chdir(os.path.join(here,"winevt"))
# Apprently sdist doesn't have "." added by default?
sys.path.append(".")
# Try compile it, but be OK with failure
try:
# Import our ffi builder
from winevt_build import ffibuilder
ffibuilder().compile(verbose=True)
shutil.copyfile(glob("_winevt.*.pyd")[0],"_winevt.pyd")
except Exception as e:
print(f"Error while attempting to compile in-line extension: {e}", file=sys.stderr)
# Put us back in our original directory
os.chdir(old_dir)
def _install_cffi():
# Major hack... I need cffi to do the transparent building
os.system('pip install cffi')
class CustomBuildPyCommand(build_py):
""" Handle generating pyd file but not erroring if we can't. """
def run(self):
self.execute(_build_ffi, (), msg='Building ffi')
build_py.run(self)
class CustomInstallCommand(install):
""" Handle generating pyd file but not erroring if we can't. """
def run(self):
self.execute(_install_cffi, (), msg='Installing cffi')
self.execute(_build_ffi, (), msg='Building ffi')
install.run(self)
class CustomSdistCommand(sdist):
""" Make sure we generate a new pyd when creating our sdist. """
def run(self):
self.execute(_build_ffi, (), msg='Building ffi')
sdist.run(self)
# Get the long description from the README file
#with open(path.join(here, 'README.md'), encoding='utf-8') as f:
# long_description = f.read()
long_description = "See website for more info."
setup(
name='winevt',
version='0.0.11',
description='Script to programmatically interface with Windows Events.',
long_description=long_description,
url='https://github.com/owlz/winevt',
author='Michael Bann',
author_email='self@bannsecurity.com',
license='MIT',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Operating System :: Microsoft :: Windows',
'Environment :: Console'
],
keywords='windows event evt evtx',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
install_requires=["cffi>=1.0.0","untangle"],
#cffi_modules=["winevt/winevt_build.py:ffibuilder"],
extras_require={
'dev': ['ipython'],
},
cmdclass={
'install': CustomInstallCommand,
'build_py': CustomBuildPyCommand,
'sdist': CustomSdistCommand,
},
package_data={'winevt': ['_winevt.pyd']},
)