Commit f1fe110e by Craig Heffner

Merged sundhaug92's updates to setup.py

parent 639a7d44
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import os import os
import sys import sys
import shutil import shutil
import tempfile
import subprocess import subprocess
from distutils.core import setup, Command from distutils.core import setup, Command
from distutils.dir_util import remove_tree from distutils.dir_util import remove_tree
...@@ -17,14 +16,18 @@ except NameError: ...@@ -17,14 +16,18 @@ except NameError:
raw_input = input raw_input = input
# cd into the src directory, no matter where setup.py was invoked from # cd into the src directory, no matter where setup.py was invoked from
#os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "src")) # os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "src"))
def which(command): def which(command):
# /usr/local/bin is usually the default install path, though it may not be in $PATH # /usr/local/bin is usually the default install path, though it may not be in $PATH
usr_local_bin = os.path.sep.join([os.path.sep, 'usr', 'local', 'bin', command]) usr_local_bin = os.path.sep.join(
[os.path.sep, 'usr', 'local', 'bin', command])
try: try:
location = subprocess.Popen(["which", command], shell=False, stdout=subprocess.PIPE).communicate()[0].strip() location = subprocess.Popen(
["which", command],
shell=False, stdout=subprocess.PIPE).communicate()[0].strip()
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as e: except Exception as e:
...@@ -35,6 +38,7 @@ def which(command): ...@@ -35,6 +38,7 @@ def which(command):
return location return location
def find_binwalk_module_paths(): def find_binwalk_module_paths():
paths = [] paths = []
...@@ -48,6 +52,7 @@ def find_binwalk_module_paths(): ...@@ -48,6 +52,7 @@ def find_binwalk_module_paths():
return paths return paths
def remove_binwalk_module(pydir=None, pybin=None): def remove_binwalk_module(pydir=None, pybin=None):
if pydir: if pydir:
module_paths = [pydir] module_paths = [pydir]
...@@ -57,7 +62,7 @@ def remove_binwalk_module(pydir=None, pybin=None): ...@@ -57,7 +62,7 @@ def remove_binwalk_module(pydir=None, pybin=None):
for path in module_paths: for path in module_paths:
try: try:
remove_tree(path) remove_tree(path)
except OSError as e: except OSError:
pass pass
if not pybin: if not pybin:
...@@ -67,11 +72,12 @@ def remove_binwalk_module(pydir=None, pybin=None): ...@@ -67,11 +72,12 @@ def remove_binwalk_module(pydir=None, pybin=None):
try: try:
sys.stdout.write("removing '%s'\n" % pybin) sys.stdout.write("removing '%s'\n" % pybin)
os.remove(pybin) os.remove(pybin)
except KeyboardInterrupt as e: except KeyboardInterrupt:
pass pass
except Exception as e: except Exception:
pass pass
class IDAUnInstallCommand(Command): class IDAUnInstallCommand(Command):
description = "Uninstalls the binwalk IDA plugin module" description = "Uninstalls the binwalk IDA plugin module"
user_options = [ user_options = [
...@@ -80,14 +86,16 @@ class IDAUnInstallCommand(Command): ...@@ -80,14 +86,16 @@ class IDAUnInstallCommand(Command):
def initialize_options(self): def initialize_options(self):
self.idadir = None self.idadir = None
self.mydir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "src") self.mydir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "src")
def finalize_options(self): def finalize_options(self):
pass pass
def run(self): def run(self):
if self.idadir is None: if self.idadir is None:
sys.stderr.write("Please specify the path to your IDA install directory with the '--idadir' option!\n") sys.stderr.write(
"Please specify the path to your IDA install directory with the '--idadir' option!\n")
return return
binida_dst_path = os.path.join(self.idadir, 'plugins', 'binida.py') binida_dst_path = os.path.join(self.idadir, 'plugins', 'binida.py')
...@@ -100,6 +108,7 @@ class IDAUnInstallCommand(Command): ...@@ -100,6 +108,7 @@ class IDAUnInstallCommand(Command):
sys.stdout.write("removing %s\n" % binwalk_dst_path) sys.stdout.write("removing %s\n" % binwalk_dst_path)
shutil.rmtree(binwalk_dst_path) shutil.rmtree(binwalk_dst_path)
class IDAInstallCommand(Command): class IDAInstallCommand(Command):
description = "Installs the binwalk IDA plugin module" description = "Installs the binwalk IDA plugin module"
user_options = [ user_options = [
...@@ -108,34 +117,44 @@ class IDAInstallCommand(Command): ...@@ -108,34 +117,44 @@ class IDAInstallCommand(Command):
def initialize_options(self): def initialize_options(self):
self.idadir = None self.idadir = None
self.mydir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "src") self.mydir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "src")
def finalize_options(self): def finalize_options(self):
pass pass
def run(self): def run(self):
if self.idadir is None: if self.idadir is None:
sys.stderr.write("Please specify the path to your IDA install directory with the '--idadir' option!\n") sys.stderr.write(
"Please specify the path to your IDA install directory with the '--idadir' option!\n")
return return
binida_src_path = os.path.join(self.mydir, 'scripts', 'binida.py') binida_src_path = os.path.join(self.mydir, 'scripts', 'binida.py')
binida_dst_path = os.path.join(self.idadir, 'plugins') binida_dst_path = os.path.join(self.idadir, 'plugins')
if not os.path.exists(binida_src_path): if not os.path.exists(binida_src_path):
sys.stderr.write("ERROR: could not locate IDA plugin file '%s'!\n" % binida_src_path) sys.stderr.write(
"ERROR: could not locate IDA plugin file '%s'!\n" %
binida_src_path)
return return
if not os.path.exists(binida_dst_path): if not os.path.exists(binida_dst_path):
sys.stderr.write("ERROR: could not locate the IDA plugins directory '%s'! Check your --idadir option.\n" % binida_dst_path) sys.stderr.write(
"ERROR: could not locate the IDA plugins directory '%s'! Check your --idadir option.\n" %
binida_dst_path)
return return
binwalk_src_path = os.path.join(self.mydir, 'binwalk') binwalk_src_path = os.path.join(self.mydir, 'binwalk')
binwalk_dst_path = os.path.join(self.idadir, 'python') binwalk_dst_path = os.path.join(self.idadir, 'python')
if not os.path.exists(binwalk_src_path): if not os.path.exists(binwalk_src_path):
sys.stderr.write("ERROR: could not locate binwalk source directory '%s'!\n" % binwalk_src_path) sys.stderr.write(
"ERROR: could not locate binwalk source directory '%s'!\n" %
binwalk_src_path)
return return
if not os.path.exists(binwalk_dst_path): if not os.path.exists(binwalk_dst_path):
sys.stderr.write("ERROR: could not locate the IDA python directory '%s'! Check your --idadir option.\n" % binwalk_dst_path) sys.stderr.write(
"ERROR: could not locate the IDA python directory '%s'! Check your --idadir option.\n" %
binwalk_dst_path)
return return
binida_dst_path = os.path.join(binida_dst_path, 'binida.py') binida_dst_path = os.path.join(binida_dst_path, 'binida.py')
...@@ -146,12 +165,15 @@ class IDAInstallCommand(Command): ...@@ -146,12 +165,15 @@ class IDAInstallCommand(Command):
if os.path.exists(binwalk_dst_path): if os.path.exists(binwalk_dst_path):
shutil.rmtree(binwalk_dst_path) shutil.rmtree(binwalk_dst_path)
sys.stdout.write("copying %s -> %s\n" % (binida_src_path, binida_dst_path)) sys.stdout.write("copying %s -> %s\n" %
(binida_src_path, binida_dst_path))
shutil.copyfile(binida_src_path, binida_dst_path) shutil.copyfile(binida_src_path, binida_dst_path)
sys.stdout.write("copying %s -> %s\n" % (binwalk_src_path, binwalk_dst_path)) sys.stdout.write("copying %s -> %s\n" %
(binwalk_src_path, binwalk_dst_path))
shutil.copytree(binwalk_src_path, binwalk_dst_path) shutil.copytree(binwalk_src_path, binwalk_dst_path)
class UninstallCommand(Command): class UninstallCommand(Command):
description = "Uninstalls the Python module" description = "Uninstalls the Python module"
user_options = [ user_options = [
...@@ -169,6 +191,7 @@ class UninstallCommand(Command): ...@@ -169,6 +191,7 @@ class UninstallCommand(Command):
def run(self): def run(self):
remove_binwalk_module(self.pydir, self.pybin) remove_binwalk_module(self.pydir, self.pybin)
class CleanCommand(Command): class CleanCommand(Command):
description = "Clean Python build directories" description = "Clean Python build directories"
user_options = [] user_options = []
...@@ -194,24 +217,49 @@ class CleanCommand(Command): ...@@ -194,24 +217,49 @@ class CleanCommand(Command):
except Exception: except Exception:
pass pass
class TestCommand(Command):
description = "Run unit-tests"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
subprocess.call(
'nosetests --exe --with-coverage --include=src/*', shell=True)
# The data files to install along with the module # The data files to install along with the module
install_data_files = [] install_data_files = []
for data_dir in ["magic", "config", "plugins", "modules", "core"]: for data_dir in ["magic", "config", "plugins", "modules", "core"]:
install_data_files.append("%s%s*" % (data_dir, os.path.sep)) install_data_files.append("%s%s*" % (data_dir, os.path.sep))
# Install the module, script, and support files # Install the module, script, and support files
setup(name = MODULE_NAME, setup(
version = "2.1.2b", name=MODULE_NAME,
description = "Firmware analysis tool", version="2.1.2b",
author = "Craig Heffner", description="Firmware analysis tool",
url = "https://github.com/devttys0/%s" % MODULE_NAME, author="Craig Heffner",
url="https://github.com/devttys0/%s" %
requires = [], MODULE_NAME,
package_dir = {"" : "src"}, requires=[],
packages = [MODULE_NAME], package_dir={
package_data = {MODULE_NAME : install_data_files}, "": "src"},
scripts = [os.path.join("src", "scripts", SCRIPT_NAME)], packages=[MODULE_NAME],
package_data={
cmdclass = {'clean' : CleanCommand, 'uninstall' : UninstallCommand, 'idainstall' : IDAInstallCommand, 'idauninstall' : IDAUnInstallCommand} MODULE_NAME: install_data_files},
) scripts=[
os.path.join(
"src",
"scripts",
SCRIPT_NAME)],
cmdclass={
'clean': CleanCommand,
'uninstall': UninstallCommand,
'idainstall': IDAInstallCommand,
'idauninstall': IDAUnInstallCommand,
'test': TestCommand})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment