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,6 +133,7 @@ from zenmapCore.Version import VERSION
|
||||
from zenmapCore.Name import APP_NAME
|
||||
from zenmapCore.UmitOptionParser import option_parser
|
||||
|
||||
|
||||
# Find out the prefix under which data files (interface definition XML,
|
||||
# pixmaps, etc.) are stored. This can vary depending on whether we are running
|
||||
# in an executable package and what type of package it is, which we check using
|
||||
@@ -161,6 +162,8 @@ MISC_DIR = join(prefix, "share", APP_NAME, "misc")
|
||||
PIXMAPS_DIR = join(prefix, "share", "zenmap", "pixmaps")
|
||||
DOCS_DIR = join(prefix, "share", APP_NAME, "docs")
|
||||
NMAPDATADIR = join(prefix, "..")
|
||||
|
||||
|
||||
def get_extra_executable_search_paths():
|
||||
"""Return a list of additional executable search paths as a convenience for
|
||||
platforms where the default PATH is inadequate."""
|
||||
@@ -170,6 +173,7 @@ def get_extra_executable_search_paths():
|
||||
return [dirname(sys.executable)]
|
||||
return []
|
||||
|
||||
|
||||
#######
|
||||
# Paths
|
||||
class Paths(object):
|
||||
@@ -194,7 +198,8 @@ class Paths(object):
|
||||
|
||||
def __init__(self):
|
||||
self.user_config_dir = option_parser.get_confdir()
|
||||
self.user_config_file = os.path.join(self.user_config_dir, base_paths['user_config_file'])
|
||||
self.user_config_file = os.path.join(
|
||||
self.user_config_dir, base_paths['user_config_file'])
|
||||
self.config_dir = CONFIG_DIR
|
||||
self.locale_dir = LOCALE_DIR
|
||||
self.pixmaps_dir = PIXMAPS_DIR
|
||||
@@ -207,10 +212,12 @@ class Paths(object):
|
||||
return self.__dict__[name]
|
||||
|
||||
elif name in self.config_files_list:
|
||||
return return_if_exists(join(self.user_config_dir, base_paths[name]))
|
||||
return return_if_exists(
|
||||
join(self.user_config_dir, base_paths[name]))
|
||||
|
||||
elif name in self.empty_config_files_list:
|
||||
return return_if_exists(join(self.user_config_dir, base_paths[name]), True)
|
||||
return return_if_exists(
|
||||
join(self.user_config_dir, base_paths[name]), True)
|
||||
|
||||
elif name in self.misc_files_list:
|
||||
return return_if_exists(join(self.misc_dir, base_paths[name]))
|
||||
@@ -223,15 +230,17 @@ class Paths(object):
|
||||
def __setattr__(self, name, value):
|
||||
self.__dict__[name] = value
|
||||
|
||||
|
||||
def create_dir(path):
|
||||
"""Create a directory with os.makedirs without raising an error if the
|
||||
directory already exists."""
|
||||
directory already exists."""
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError, e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
def create_user_config_dir(user_dir, template_dir):
|
||||
"""Create a user configuration directory by creating the directory if
|
||||
necessary, then copying all the files from the given template directory,
|
||||
@@ -253,6 +262,7 @@ def create_user_config_dir(user_dir, template_dir):
|
||||
shutil.copyfile(template_filename, user_filename)
|
||||
log.debug(">>> Copy %s to %s." % (template_filename, user_filename))
|
||||
|
||||
|
||||
def return_if_exists(path, create=False):
|
||||
path = os.path.abspath(path)
|
||||
if os.path.exists(path):
|
||||
|
||||
Reference in New Issue
Block a user