Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues/2830 #2833

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions zenmap/zenmapCore/ScriptMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def __init__(self, script_db_path=None):

self.lineno = 1
self.line = ""
with open(script_db_path, "r", encoding="utf-8") as self.f:

with open(script_db_path, "r",encoding='utf-8') as self.f:
self.entries_list = self.parse()

def syntax_error(self, message):
Expand Down Expand Up @@ -296,20 +297,20 @@ def get_metadata(self, filename):
self.get_string_variable(filename, "author")]

filepath = os.path.join(self.scripts_dir, filename)
with open(filepath, "r", encoding="utf-8") as f:
with open(filepath, "r",encoding='utf-8') as f:
for tag_name, tag_text in nsedoc_tags_iter(f):
if tag_name == "output" and not entry.output:
entry.output = tag_text
elif tag_name == "usage" and not entry.usage:
entry.usage = tag_text
except (IOError, UnicodeError) as e:
except IOError as e:
entry.description = "Error getting metadata: {}".format(e)

return entry

@staticmethod
def get_file_contents(filename):
with open(filename, "r", encoding="utf-8") as f:
with open(filename, "r",encoding='utf-8') as f:
contents = f.read()
return contents

Expand Down Expand Up @@ -343,7 +344,7 @@ def get_list_variable(self, filename, varname):

@staticmethod
def get_requires(filename):
with open(filename, "r", encoding="utf-8") as f:
with open(filename, "r",encoding='utf-8') as f:
requires = ScriptMetadata.get_requires_from_file(f)
return requires

Expand All @@ -359,7 +360,7 @@ def get_requires_from_file(f):

@staticmethod
def get_script_args(filename):
with open(filename, "r", encoding="utf-8") as f:
with open(filename, "r",encoding='utf-8') as f:
args = ScriptMetadata.get_script_args_from_file(f)
return args

Expand Down Expand Up @@ -414,11 +415,8 @@ def construct_library_arguments(self):
else:
libname = filename

try:
self.library_arguments[libname] = self.get_script_args(filepath)
self.library_requires[libname] = self.get_requires(filepath)
except (IOError, UnicodeError) as e:
log.debug("Unable to process {}: {}".format(libname, e))
self.library_arguments[libname] = self.get_script_args(filepath)
self.library_requires[libname] = self.get_requires(filepath)


def get_script_entries(scripts_dir, nselib_dir):
Expand All @@ -427,8 +425,7 @@ def get_script_entries(scripts_dir, nselib_dir):
metadata = ScriptMetadata(scripts_dir, nselib_dir)
try:
scriptdb = ScriptDB(os.path.join(scripts_dir, "script.db"))
except (IOError, UnicodeError) as e:
log.debug("Unable to process script.db: {}".format(e))
except IOError:
return []
entries = []
for dbentry in scriptdb.get_entries_list():
Expand Down