Commit 5fcb44db by heffnercj

setup.py made python3 compliant

parent ad9365b0
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import subprocess
from os import listdir, path
from distutils.core import setup
# Python2/3 compliance
try:
raw_input
except:
raw_input = input
# This is super hacky.
if "--yes" in sys.argv:
sys.argv.pop(sys.argv.index("--yes"))
......@@ -20,10 +27,10 @@ def warning(lines, terminate=True, prompt=False):
WIDTH = 115
if not IGNORE_WARNINGS:
print "\n", "*" * WIDTH
print("\n" + "*" * WIDTH)
for line in lines:
print line
print "*" * WIDTH, "\n"
print(line)
print("*" * WIDTH, "\n")
if prompt:
if raw_input('Continue installation anyway (Y/n)? ').lower().startswith('n'):
......@@ -34,20 +41,19 @@ def warning(lines, terminate=True, prompt=False):
if terminate:
sys.exit(1)
# Check for pre-requisite modules only if --no-prereq-checks was not specified
print "checking pre-requisites"
print("checking pre-requisites")
try:
import magic
try:
magic.MAGIC_NO_CHECK_TEXT
except Exception, e:
msg = ["Pre-requisite failure:", str(e),
except Exception as e:
msg = ["Pre-requisite failure: " + str(e),
"It looks like you have an old or incompatible magic module installed.",
"Please install the official python-magic module, or download and install it from source: ftp://ftp.astron.com/pub/file/"
]
warning(msg)
except Exception, e:
except Exception as e:
msg = ["Pre-requisite failure:", str(e),
"Please install the python-magic module, or download and install it from source: ftp://ftp.astron.com/pub/file/",
]
......@@ -59,8 +65,8 @@ try:
matplotlib.use('Agg')
import matplotlib.pyplot
import numpy
except Exception, e:
msg = ["Pre-requisite check warning:", str(e),
except Exception as e:
msg = ["Pre-requisite check warning: " + str(e),
"To take advantage of this tool's entropy plotting capabilities, please install the python-matplotlib module.",
]
......@@ -80,7 +86,7 @@ if not os.path.exists(c_lib_makefile):
status |= os.system("make")
if status != 0:
msg = ["Failed to build compression libraries.",
msg = ["Build warning: failed to build compression libraries.",
"Some plugins will not work without these libraries."
]
......@@ -88,7 +94,7 @@ if status != 0:
else:
if "install" in sys.argv:
if os.system("make install") != 0:
msg = ["Failed to install compression libraries.",
msg = ["Install warning: failed to install compression libraries.",
"Some plugins will not work without these libraries."
]
......@@ -97,14 +103,18 @@ else:
os.chdir(working_directory)
# Generate a new magic file from the files in the magic directory
print "generating binwalk magic file"
print("generating binwalk magic file")
magic_files = listdir("magic")
magic_files.sort()
fd = open("binwalk/magic/binwalk", "wb")
for magic in magic_files:
fpath = path.join("magic", magic)
if path.isfile(fpath):
fd.write(open(fpath).read())
data = open(fpath).read()
try:
fd.write(data)
except TypeError:
fd.write(bytes(data, 'UTF-8'))
fd.close()
# The data files to install along with the binwalk module
......@@ -115,7 +125,7 @@ setup( name = "binwalk",
version = "1.2.3",
description = "Firmware analysis tool",
author = "Craig Heffner",
url = "http://binwalk.googlecode.com",
url = "https://github.com/devttys0/binwalk",
requires = ["magic", "matplotlib.pyplot"],
packages = ["binwalk"],
......@@ -137,8 +147,14 @@ if python2_path and binwalk_path:
for line in open(binwalk_path, 'rb').readlines():
if i == 0:
line = "#!/usr/bin/env python2\n"
data += line
data += str(line)
i += 1
open(binwalk_path, 'wb').write(data)
fd = open(binwalk_path, 'wb')
try:
fd.write(data)
except TypeError:
fd.write(bytes(data, 'UTF-8'))
fd.close()
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