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
MODULE_NAME = "binwalk"
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
try:
......@@ -15,9 +33,6 @@ try:
except NameError:
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):
# /usr/local/bin is usually the default install path, though it may not be in $PATH
......@@ -203,6 +218,9 @@ class CleanCommand(Command):
pass
def run(self):
sys.stdout.write("removing %s%s" %(VERSION_FILE, os.linesep))
os.remove(VERSION_FILE)
try:
remove_tree("build")
except KeyboardInterrupt as e:
......@@ -237,20 +255,24 @@ install_data_files = []
for data_dir in ["magic", "config", "plugins", "modules", "core"]:
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
setup(
name=MODULE_NAME,
version="2.1.2b",
version=MODULE_VERSION,
description="Firmware analysis tool",
author="Craig Heffner",
url="https://github.com/devttys0/%s" %
MODULE_NAME,
url="https://github.com/devttys0/%s" % MODULE_NAME,
requires=[],
package_dir={
"": "src"},
package_dir={"": "src"},
packages=[MODULE_NAME],
package_data={
MODULE_NAME: install_data_files},
package_data={MODULE_NAME: install_data_files},
scripts=[
os.path.join(
"src",
......
__all__ = ['scan', 'execute', 'ModuleException']
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
# Convenience functions
def scan(*args, **kwargs):
with Modules(*args, **kwargs) as m:
objs = m.execute()
......
......@@ -11,6 +11,7 @@ import inspect
import argparse
import traceback
from copy import copy
import binwalk
import binwalk.core.statuserver
import binwalk.core.common
import binwalk.core.settings
......@@ -743,7 +744,7 @@ class Modules(object):
Returns the help string.
'''
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"
# Build a dictionary of modules and their ORDER attributes.
......
......@@ -19,9 +19,6 @@ class Settings:
o BINWALK_MAGIC_FILE - Path to the default binwalk magic file.
o PLUGINS - Path to the plugins directory.
'''
# Release version
VERSION = "2.1.2b"
# Sub directories
BINWALK_USER_DIR = "binwalk"
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