Refactor file handling and update comparison logic

Fix file handling and comparison operators in update_handler.py.
This commit is contained in:
OMORJEEVAN
2026-07-05 00:19:04 -04:00
committed by GitHub
parent 0240654b8f
commit 128b322aa8
+7 -6
View File
@@ -43,7 +43,7 @@ class Updater:
Get current malwareDB version and see if we need an update Get current malwareDB version and see if we need an update
''' '''
try: try:
with file(globals.vars.maldb_ver_file) as f: with open(globals.vars.maldb_ver_file) as f:
return f.read() return f.read()
except IOError: except IOError:
print( print(
@@ -55,11 +55,11 @@ class Updater:
Just update the database from GitHub Just update the database from GitHub
:return: :return:
''' '''
if globals.vars.DEBUG_LEVEL is 1: if globals.vars.DEBUG_LEVEL == 1:
print(locals()) print(locals())
response = urlopen( response = urlopen(
globals.vars.giturl_dl + globals.vars.maldb_ver_file) globals.vars.giturl_dl + globals.vars.maldb_ver_file)
new_maldb_ver = response.read() new_maldb_ver = response.read().decode("utf-8").strip()
if new_maldb_ver == curr_db_version: if new_maldb_ver == curr_db_version:
print(green('[+]') + " theZoo is up to date.\n" + green('[+]') + " You are at " + new_maldb_ver + " which is the latest version.") print(green('[+]') + " theZoo is up to date.\n" + green('[+]') + " You are at " + new_maldb_ver + " which is the latest version.")
return return
@@ -100,13 +100,14 @@ class Updater:
print(bold(green("[+]")) + " Successfully downloaded a new friend.\n") print(bold(green("[+]")) + " Successfully downloaded a new friend.\n")
def download_from_repo(self, filepath, suffix=''): def download_from_repo(self, filepath, suffix=''):
if globals.vars.DEBUG_LEVEL is 1: if globals.vars.DEBUG_LEVEL == 1:
print(locals()) print(locals())
file_name = filepath.rsplit('/')[-1] + suffix file_name = filepath.rsplit('/')[-1] + suffix
# Dirty way to check if we're downloading a malware # Dirty way to check if we're downloading a malware
if suffix is not '': if suffix != '':
url = globals.vars.giturl_dl + filepath + '/' + file_name url = globals.vars.giturl_dl + filepath + '/' + file_name
else: else:
url = globals.vars.giturl_dl + filepath url = globals.vars.giturl_dl + filepath
@@ -119,7 +120,7 @@ class Updater:
f = open(file_name, 'wb') f = open(file_name, 'wb')
meta = u.info() meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0]) file_size = int(meta.get("Content-Length", 0))
print("Downloading: %s Bytes: %s" % (file_name, file_size)) print("Downloading: %s Bytes: %s" % (file_name, file_size))
file_size_dl = 0 file_size_dl = 0
block_sz = 8192 block_sz = 8192