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:
@@ -133,7 +133,7 @@ import ConfigParser
|
||||
# Python 2.7 that otherwise causes an assertion failure. See
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=620216#c10.
|
||||
import warnings
|
||||
warnings.filterwarnings("error", module = "gtk", append = "True")
|
||||
warnings.filterwarnings("error", module="gtk", append="True")
|
||||
try:
|
||||
import gtk
|
||||
except Exception:
|
||||
@@ -171,6 +171,7 @@ from zenmapGUI.higwidgets.higdialogs import HIGAlertDialog
|
||||
# gtk.main_quit.
|
||||
open_windows = []
|
||||
|
||||
|
||||
def _destroy_callback(window):
|
||||
open_windows.remove(window)
|
||||
if len(open_windows) == 0:
|
||||
@@ -183,6 +184,7 @@ def _destroy_callback(window):
|
||||
# Cleaning up data base
|
||||
UmitDB().cleanup(SearchConfig().converted_save_time)
|
||||
|
||||
|
||||
def new_window():
|
||||
w = ScanWindow()
|
||||
w.connect("destroy", _destroy_callback)
|
||||
@@ -193,11 +195,14 @@ def new_window():
|
||||
open_windows.append(w)
|
||||
return w
|
||||
|
||||
# Script found at http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
|
||||
|
||||
# Script found at
|
||||
# http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
|
||||
def main_is_frozen():
|
||||
return (hasattr(sys, "frozen") # new py2exe
|
||||
or hasattr(sys, "importers") # old py2exe
|
||||
or imp.is_frozen("__main__")) # tools/freeze
|
||||
return (hasattr(sys, "frozen") # new py2exe
|
||||
or hasattr(sys, "importers") # old py2exe
|
||||
or imp.is_frozen("__main__")) # tools/freeze
|
||||
|
||||
|
||||
def is_root():
|
||||
if 'NMAP_PRIVILEGED' in os.environ:
|
||||
@@ -207,6 +212,7 @@ def is_root():
|
||||
else:
|
||||
return sys.platform == "win32" or os.getuid() == 0 or is_maemo()
|
||||
|
||||
|
||||
def install_excepthook():
|
||||
# This will catch exceptions and send them to bugzilla
|
||||
def excepthook(type, value, tb):
|
||||
@@ -218,7 +224,7 @@ def install_excepthook():
|
||||
# produces a warning, but the lack of a display eventually causes a
|
||||
# segmentation fault. See http://live.gnome.org/PyGTK/WhatsNew210.
|
||||
import warnings
|
||||
warnings.filterwarnings("error", module = "gtk")
|
||||
warnings.filterwarnings("error", module="gtk")
|
||||
import gtk
|
||||
warnings.resetwarnings()
|
||||
|
||||
@@ -229,8 +235,7 @@ def install_excepthook():
|
||||
if type == ImportError:
|
||||
d = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
|
||||
message_format=_("Import error"),
|
||||
secondary_text=_("""\
|
||||
A required module was not found.
|
||||
secondary_text=_("""A required module was not found.
|
||||
|
||||
""" + unicode(value)))
|
||||
d.run()
|
||||
@@ -246,6 +251,7 @@ A required module was not found.
|
||||
|
||||
sys.excepthook = excepthook
|
||||
|
||||
|
||||
def safe_shutdown(signum, stack):
|
||||
"""Kills any active scans/tabs and shuts down the application."""
|
||||
log.debug("\n\n%s\nSAFE SHUTDOWN!\n%s\n" % ("#" * 30, "#" * 30))
|
||||
@@ -256,6 +262,7 @@ def safe_shutdown(signum, stack):
|
||||
|
||||
sys.exit(signum)
|
||||
|
||||
|
||||
def run():
|
||||
if os.name == "posix":
|
||||
signal.signal(signal.SIGHUP, safe_shutdown)
|
||||
@@ -271,19 +278,25 @@ def run():
|
||||
try:
|
||||
# Create the ~/.zenmap directory by copying from the system-wide
|
||||
# template directory.
|
||||
zenmapCore.Paths.create_user_config_dir(Path.user_config_dir, Path.config_dir)
|
||||
zenmapCore.Paths.create_user_config_dir(
|
||||
Path.user_config_dir, Path.config_dir)
|
||||
except (IOError, OSError), e:
|
||||
error_dialog = HIGAlertDialog(message_format = _("Error creating the per-user configuration directory"),
|
||||
secondary_text = _("""\
|
||||
error_dialog = HIGAlertDialog(
|
||||
message_format=_(
|
||||
"Error creating the per-user configuration directory"),
|
||||
secondary_text=_("""\
|
||||
There was an error creating the directory %s or one of the files in it. \
|
||||
The directory is created by copying the contents of %s. \
|
||||
The specific error was\n\
|
||||
\n\
|
||||
%s\n\
|
||||
\n\
|
||||
The specific error was
|
||||
|
||||
%s
|
||||
|
||||
%s needs to create this directory to store information such as the list of \
|
||||
scan profiles. Check for access to the directory and try again.\
|
||||
""") % (repr(Path.user_config_dir), repr(Path.config_dir), repr(str(e)), APP_DISPLAY_NAME))
|
||||
scan profiles. Check for access to the directory and try again.""") % (
|
||||
repr(Path.user_config_dir), repr(Path.config_dir),
|
||||
repr(str(e)), APP_DISPLAY_NAME
|
||||
)
|
||||
)
|
||||
error_dialog.run()
|
||||
error_dialog.destroy()
|
||||
sys.exit(1)
|
||||
@@ -292,16 +305,17 @@ scan profiles. Check for access to the directory and try again.\
|
||||
# Read the ~/.zenmap/zenmap.conf configuration file.
|
||||
zenmapCore.UmitConf.config_parser.read(Path.user_config_file)
|
||||
except ConfigParser.ParsingError, e:
|
||||
error_dialog = HIGAlertDialog(message_format = _("Error parsing the configuration file"),
|
||||
secondary_text = _("""\
|
||||
error_dialog = HIGAlertDialog(
|
||||
message_format=_("Error parsing the configuration file"),
|
||||
secondary_text=_("""\
|
||||
There was an error parsing the configuration file %s. \
|
||||
The specific error was\n\
|
||||
\n\
|
||||
%s\n\
|
||||
\n\
|
||||
The specific error was
|
||||
|
||||
%s
|
||||
|
||||
%s can continue without this file but any information in it will be ignored \
|
||||
until it is repaired.\
|
||||
""") % (Path.user_config_file, str(e), APP_DISPLAY_NAME))
|
||||
until it is repaired.""") % (Path.user_config_file, str(e), APP_DISPLAY_NAME)
|
||||
)
|
||||
error_dialog.run()
|
||||
error_dialog.destroy()
|
||||
|
||||
@@ -355,10 +369,13 @@ until it is repaired.\
|
||||
if main_is_frozen():
|
||||
gtk.gdk.threads_leave()
|
||||
|
||||
|
||||
class NonRootWarning (HIGAlertDialog):
|
||||
def __init__(self):
|
||||
warning_text = _('''You are trying to run %s with a non-root user!\n
|
||||
Some %s options need root privileges to work.''') % (APP_DISPLAY_NAME, NMAP_DISPLAY_NAME)
|
||||
warning_text = _('''You are trying to run %s with a non-root user!
|
||||
|
||||
Some %s options need root privileges to work.''') % (
|
||||
APP_DISPLAY_NAME, NMAP_DISPLAY_NAME)
|
||||
|
||||
HIGAlertDialog.__init__(self, message_format=_('Non-root user'),
|
||||
secondary_text=warning_text)
|
||||
|
||||
Reference in New Issue
Block a user