1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 05:01:29 +00:00

Apply PEP 8 style guidance to zenmap

Using the pep8 tool (https://pypi.python.org/pypi/pep8), fixed the
following style issues:

Count   Issue
11      E201 whitespace after '['
8       E203 whitespace before ','
41      E211 whitespace before '('
11      E221 multiple spaces before operator
61      E225 missing whitespace around operator
237     E231 missing whitespace after ':'
91      E251 no spaces around keyword / parameter equals
19      E261 at least two spaces before inline comment
41      E301 expected 1 blank line, found 0
200     E302 expected 2 blank lines, found 1
356     E303 too many blank lines (2)
563     E501 line too long (106 characters)
39      E701 multiple statements on one line (colon)
13      E702 multiple statements on one line (semicolon)
4       W291 trailing whitespace
2       W293 blank line contains whitespace
8       W391 blank line at end of file
21      W601 .has_key() is deprecated, use 'in'
2       W602 deprecated form of raising exception

The remaining issues are long lines due to very deep data structures. I
chose not to alter them, as it would involve backslash-continuation
where whitespace is not permitted:

./zenmapGUI/ScanInterface.py:323:80: E501 line too long (90 characters)
./zenmapGUI/ScanInterface.py:456:80: E501 line too long (84 characters)
./zenmapGUI/ScanInterface.py:464:80: E501 line too long (84 characters)
./zenmapGUI/ScanInterface.py:472:80: E501 line too long (122 characters)
./zenmapGUI/ScanInterface.py:479:80: E501 line too long (122 characters)
./zenmapGUI/ScanInterface.py:920:80: E501 line too long (94 characters)
./zenmapGUI/ScanInterface.py:923:80: E501 line too long (93 characters)
./zenmapGUI/MainWindow.py:575:80: E501 line too long (99 characters)
./zenmapGUI/MainWindow.py:906:80: E501 line too long (99 characters)
This commit is contained in:
dmiller
2014-01-08 19:50:22 +00:00
parent 9210a7f1fa
commit 5c662fffdc
100 changed files with 2287 additions and 1814 deletions

View File

@@ -136,9 +136,11 @@ import zenmapCore.Paths
# The [paths] configuration from zenmap.conf, used to get ndiff_command_path.
paths_config = PathsConfig()
class NdiffParseException(Exception):
pass
def get_path():
"""Return a value for the PATH environment variable that is appropriate
for the current platform. It will be the PATH from the environment plus
@@ -153,8 +155,9 @@ def get_path():
search_paths.append(path)
return os.pathsep.join(search_paths)
class NdiffCommand(subprocess.Popen):
def __init__(self, filename_a, filename_b, temporary_filenames = []):
def __init__(self, filename_a, filename_b, temporary_filenames=[]):
self.temporary_filenames = temporary_filenames
search_paths = get_path()
@@ -162,20 +165,38 @@ class NdiffCommand(subprocess.Popen):
env["PATH"] = search_paths
if getattr(sys, "frozen", None) == "macosx_app":
# These variables are set by py2app, but they can interfere with
# Ndiff because Ndiff is also a Python application. Without removing
# these, Ndiff will attempt to run using the py2app-bundled Python
# library, and may run into version or architecture mismatches.
if env.has_key("PYTHONPATH"):
# Ndiff because Ndiff is also a Python application. Without
# removing these, Ndiff will attempt to run using the
# py2app-bundled Python library, and may run into version or
# architecture mismatches.
if "PYTHONPATH" in env:
del env["PYTHONPATH"]
if env.has_key("PYTHONHOME"):
if "PYTHONHOME" in env:
del env["PYTHONHOME"]
command_list = [paths_config.ndiff_command_path, "--verbose", "--", filename_a, filename_b]
self.stdout_file = tempfile.TemporaryFile(mode = "rb", prefix = APP_NAME + "-ndiff-", suffix = ".xml")
command_list = [
paths_config.ndiff_command_path,
"--verbose",
"--",
filename_a,
filename_b
]
self.stdout_file = tempfile.TemporaryFile(
mode="rb",
prefix=APP_NAME + "-ndiff-",
suffix=".xml"
)
log.debug("Running command: %s" % repr(command_list))
# See zenmapCore.NmapCommand.py for an explanation of the shell argument.
subprocess.Popen.__init__(self, command_list, stdout = self.stdout_file, stderr = self.stdout_file, env = env, shell = (sys.platform == "win32"))
# shell argument explained in zenmapCore.NmapCommand.py
subprocess.Popen.__init__(
self,
command_list,
stdout=self.stdout_file,
stderr=self.stdout_file,
env=env,
shell=(sys.platform == "win32")
)
def get_scan_diff(self):
self.wait()
@@ -194,13 +215,17 @@ class NdiffCommand(subprocess.Popen):
def kill(self):
self.close()
def ndiff(scan_a, scan_b):
"""Run Ndiff on two scan results, which may be filenames or NmapParserSAX
objects, and return a running NdiffCommand object."""
temporary_filenames = []
if isinstance(scan_a, NmapParserSAX):
fd, filename_a = tempfile.mkstemp(prefix = APP_NAME + "-diff-", suffix = ".xml")
fd, filename_a = tempfile.mkstemp(
prefix=APP_NAME + "-diff-",
suffix=".xml"
)
temporary_filenames.append(filename_a)
f = os.fdopen(fd, "wb")
scan_a.write_xml(f)
@@ -209,7 +234,10 @@ def ndiff(scan_a, scan_b):
filename_a = scan_a
if isinstance(scan_b, NmapParserSAX):
fd, filename_b = tempfile.mkstemp(prefix = APP_NAME + "-diff-", suffix = ".xml")
fd, filename_b = tempfile.mkstemp(
prefix=APP_NAME + "-diff-",
suffix=".xml"
)
temporary_filenames.append(filename_b)
f = os.fdopen(fd, "wb")
scan_b.write_xml(f)