mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 06:01:28 +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:
@@ -175,8 +175,8 @@ if isinstance(umitdb, str):
|
||||
fs_enc = "UTF-8"
|
||||
umitdb = umitdb.decode(fs_enc)
|
||||
|
||||
# pyslite 2.4.0 doesn't handle a unicode database name, though earlier and later
|
||||
# versions do. Encode to UTF-8 as pysqlite would do internally anyway.
|
||||
# pyslite 2.4.0 doesn't handle a unicode database name, though earlier and
|
||||
# later versions do. Encode to UTF-8 as pysqlite would do internally anyway.
|
||||
umitdb = umitdb.encode("UTF-8")
|
||||
|
||||
connection = sqlite.connect(umitdb)
|
||||
@@ -192,6 +192,7 @@ except AttributeError:
|
||||
# However, text_factory is available only in pysqlite 2.1.0 and later.
|
||||
pass
|
||||
|
||||
|
||||
class Table(object):
|
||||
def __init__(self, table_name):
|
||||
self.table_name = table_name
|
||||
@@ -203,9 +204,11 @@ class Table(object):
|
||||
if self.__getattribute__("_%s" % item_name):
|
||||
return self.__getattribute__("_%s" % item_name)
|
||||
|
||||
sql = "SELECT %s FROM %s WHERE %s_id = %s" % (item_name, self.table_name,
|
||||
self.table_name,
|
||||
self.__getattribute__(self.table_id))
|
||||
sql = "SELECT %s FROM %s WHERE %s_id = %s" % (
|
||||
item_name,
|
||||
self.table_name,
|
||||
self.table_name,
|
||||
self.__getattribute__(self.table_id))
|
||||
|
||||
self.cursor.execute(sql)
|
||||
|
||||
@@ -216,9 +219,11 @@ class Table(object):
|
||||
if item_value == self.__getattribute__("_%s" % item_name):
|
||||
return None
|
||||
|
||||
sql = "UPDATE %s SET %s = ? WHERE %s_id = %s" % (self.table_name, item_name,
|
||||
self.table_name,
|
||||
self.__getattribute__(self.table_id))
|
||||
sql = "UPDATE %s SET %s = ? WHERE %s_id = %s" % (
|
||||
self.table_name,
|
||||
item_name,
|
||||
self.table_name,
|
||||
self.__getattribute__(self.table_id))
|
||||
self.cursor.execute(sql, (item_value,))
|
||||
connection.commit()
|
||||
self.__setattr__("_%s" % item_name, item_value)
|
||||
@@ -247,31 +252,30 @@ class Table(object):
|
||||
self.cursor.execute(sql)
|
||||
return self.cursor.fetchall()[0][0]
|
||||
|
||||
|
||||
class UmitDB(object):
|
||||
def __init__(self):
|
||||
self.cursor = connection.cursor()
|
||||
|
||||
def create_db(self):
|
||||
drop_string = ("DROP TABLE scans;",)
|
||||
drop_string = "DROP TABLE scans;"
|
||||
|
||||
try:
|
||||
for d in drop_string:
|
||||
self.cursor.execute(d)
|
||||
self.cursor.execute(drop_string)
|
||||
except:
|
||||
connection.rollback()
|
||||
else:
|
||||
connection.commit()
|
||||
|
||||
creation_string = """CREATE TABLE scans (
|
||||
scans_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
scan_name TEXT,
|
||||
nmap_xml_output TEXT,
|
||||
digest TEXT,
|
||||
date INTEGER)"""
|
||||
|
||||
creation_string = ("""CREATE TABLE scans (scans_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
scan_name TEXT,
|
||||
nmap_xml_output TEXT,
|
||||
digest TEXT,
|
||||
date INTEGER)""",)
|
||||
|
||||
for c in creation_string:
|
||||
self.cursor.execute(c)
|
||||
connection.commit()
|
||||
self.cursor.execute(creation_string)
|
||||
connection.commit()
|
||||
|
||||
def add_scan(self, **kargs):
|
||||
return Scans(**kargs)
|
||||
@@ -289,11 +293,13 @@ class UmitDB(object):
|
||||
def cleanup(self, save_time):
|
||||
log.debug(">>> Cleaning up data base.")
|
||||
log.debug(">>> Removing results olders than %s seconds" % save_time)
|
||||
self.cursor.execute("SELECT scans_id FROM scans WHERE date < ?", (time() - save_time,))
|
||||
self.cursor.execute("SELECT scans_id FROM scans WHERE date < ?",
|
||||
(time() - save_time,))
|
||||
|
||||
for sid in [sid[0] for sid in self.cursor.fetchall()]:
|
||||
log.debug(">>> Removing results with scans_id %s" % sid)
|
||||
self.cursor.execute("DELETE FROM scans WHERE scans_id = ?", (sid, ))
|
||||
self.cursor.execute("DELETE FROM scans WHERE scans_id = ?",
|
||||
(sid, ))
|
||||
else:
|
||||
connection.commit()
|
||||
log.debug(">>> Data base successfully cleaned up!")
|
||||
@@ -310,25 +316,30 @@ class Scans(Table, object):
|
||||
|
||||
for k in kargs.keys():
|
||||
if k not in fields:
|
||||
raise Exception("Wrong table field passed to creation method. '%s'" % k)
|
||||
raise Exception(
|
||||
"Wrong table field passed to creation method. "
|
||||
"'%s'" % k)
|
||||
|
||||
if "nmap_xml_output" not in kargs.keys() or not kargs["nmap_xml_output"]:
|
||||
if ("nmap_xml_output" not in kargs.keys() or
|
||||
not kargs["nmap_xml_output"]):
|
||||
raise Exception("Can't save result without xml output")
|
||||
|
||||
if not self.verify_digest(md5(kargs["nmap_xml_output"]).hexdigest()):
|
||||
if not self.verify_digest(
|
||||
md5(kargs["nmap_xml_output"]).hexdigest()):
|
||||
raise Exception("XML output registered already!")
|
||||
|
||||
self.scans_id = self.insert(**kargs)
|
||||
|
||||
def verify_digest(self, digest):
|
||||
self.cursor.execute("SELECT scans_id FROM scans WHERE digest = ?", (digest, ))
|
||||
self.cursor.execute(
|
||||
"SELECT scans_id FROM scans WHERE digest = ?", (digest, ))
|
||||
result = self.cursor.fetchall()
|
||||
if result:
|
||||
return False
|
||||
return True
|
||||
|
||||
def add_host(self, **kargs):
|
||||
kargs.update({self.table_id:self.scans_id})
|
||||
kargs.update({self.table_id: self.scans_id})
|
||||
return Hosts(**kargs)
|
||||
|
||||
def get_hosts(self):
|
||||
|
||||
Reference in New Issue
Block a user