Commit cb1a0589 by Craig Heffner

setup.py now creates version.py which defines the current binwalk version (with…

setup.py now creates version.py which defines the current binwalk version (with git commit hash, if avaliable)
parent cb5c5751
...@@ -8,6 +8,24 @@ from distutils.dir_util import remove_tree ...@@ -8,6 +8,24 @@ from distutils.dir_util import remove_tree
MODULE_NAME = "binwalk" MODULE_NAME = "binwalk"
SCRIPT_NAME = MODULE_NAME SCRIPT_NAME = MODULE_NAME
MODULE_VERSION = "2.1.2b"
VERSION_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), "src", "binwalk", "core", "version.py")
# Python3 has a built-in DEVNULL; for Python2, we have to open
# os.devnull to redirect subprocess stderr output to the ether.
try:
from subprocess import DEVNULL
except ImportError:
DEVNULL = open(os.devnull, 'wb')
# If this version of binwalk was checked out from the git repository,
# include the git commit hash as part of the version number reported
# by binwalk.
try:
label = subprocess.check_output(["git", "describe"], stderr=DEVNULL)
MODULE_VERSION += "-" + label.split('-')[-1].strip()
except subprocess.CalledProcessError:
pass
# Python2/3 compliance # Python2/3 compliance
try: try:
...@@ -15,9 +33,6 @@ try: ...@@ -15,9 +33,6 @@ try:
except NameError: except NameError:
raw_input = input raw_input = input
# 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"))
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
...@@ -203,6 +218,9 @@ class CleanCommand(Command): ...@@ -203,6 +218,9 @@ class CleanCommand(Command):
pass pass
def run(self): def run(self):
sys.stdout.write("removing %s%s" %(VERSION_FILE, os.linesep))
os.remove(VERSION_FILE)
try: try:
remove_tree("build") remove_tree("build")
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
...@@ -237,20 +255,24 @@ install_data_files = [] ...@@ -237,20 +255,24 @@ 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))
# Create a version.py file which defines the current binwalk version.
# This file is excluded from git in the .gitignore file.
sys.stdout.write("creating %s%s" % (VERSION_FILE, os.linesep))
with open(VERSION_FILE, "w") as fp:
fp.write("# This file has been auto-generated by setup.py" + os.linesep)
fp.write('__version__ = "%s"' % MODULE_VERSION)
# Install the module, script, and support files # Install the module, script, and support files
setup( setup(
name=MODULE_NAME, name=MODULE_NAME,
version="2.1.2b", version=MODULE_VERSION,
description="Firmware analysis tool", description="Firmware analysis tool",
author="Craig Heffner", author="Craig Heffner",
url="https://github.com/devttys0/%s" % url="https://github.com/devttys0/%s" % MODULE_NAME,
MODULE_NAME,
requires=[], requires=[],
package_dir={ package_dir={"": "src"},
"": "src"},
packages=[MODULE_NAME], packages=[MODULE_NAME],
package_data={ package_data={MODULE_NAME: install_data_files},
MODULE_NAME: install_data_files},
scripts=[ scripts=[
os.path.join( os.path.join(
"src", "src",
......
build build
dist dist
version.py
__all__ = ['scan', 'execute', 'ModuleException'] __all__ = ['scan', 'execute', 'ModuleException']
from binwalk.core.module import Modules from binwalk.core.module import Modules
from binwalk.core.version import __version__ # This file is auto-generated by setup.py and ignored by .gitignore
from binwalk.core.exceptions import ModuleException from binwalk.core.exceptions import ModuleException
# Convenience functions # Convenience functions
def scan(*args, **kwargs): def scan(*args, **kwargs):
with Modules(*args, **kwargs) as m: with Modules(*args, **kwargs) as m:
objs = m.execute() objs = m.execute()
......
...@@ -11,6 +11,7 @@ import inspect ...@@ -11,6 +11,7 @@ import inspect
import argparse import argparse
import traceback import traceback
from copy import copy from copy import copy
import binwalk
import binwalk.core.statuserver import binwalk.core.statuserver
import binwalk.core.common import binwalk.core.common
import binwalk.core.settings import binwalk.core.settings
...@@ -743,7 +744,7 @@ class Modules(object): ...@@ -743,7 +744,7 @@ class Modules(object):
Returns the help string. Returns the help string.
''' '''
modules = {} modules = {}
help_string = "\nBinwalk v%s\nCraig Heffner, http://www.binwalk.org\n" % binwalk.core.settings.Settings.VERSION help_string = "\nBinwalk v%s\nCraig Heffner, https://github.com/devttys0/binwalk\n" % binwalk.__version__
help_string += "\nUsage: binwalk [OPTIONS] [FILE1] [FILE2] [FILE3] ...\n" help_string += "\nUsage: binwalk [OPTIONS] [FILE1] [FILE2] [FILE3] ...\n"
# Build a dictionary of modules and their ORDER attributes. # Build a dictionary of modules and their ORDER attributes.
......
...@@ -19,9 +19,6 @@ class Settings: ...@@ -19,9 +19,6 @@ class Settings:
o BINWALK_MAGIC_FILE - Path to the default binwalk magic file. o BINWALK_MAGIC_FILE - Path to the default binwalk magic file.
o PLUGINS - Path to the plugins directory. o PLUGINS - Path to the plugins directory.
''' '''
# Release version
VERSION = "2.1.2b"
# Sub directories # Sub directories
BINWALK_USER_DIR = "binwalk" BINWALK_USER_DIR = "binwalk"
BINWALK_MAGIC_DIR = "magic" BINWALK_MAGIC_DIR = "magic"
......
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