Skip to content

Commit

Permalink
Deprecate python3-debian dependency by a using simple parser
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Jan 19, 2024
1 parent 10c6988 commit 1f9282f
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions backend/globaleaks/jobs/update_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from debian import deb822
from pkg_resources import parse_version
from twisted.internet.defer import inlineCallbacks

Expand All @@ -17,6 +16,31 @@
DEB_PACKAGE_URL = b'https://deb.globaleaks.org/bookworm/Packages'


import re

def get_latest_version(packages_file):
# Split the Packages file into individual package entries
package_entries = packages_file.split('\n\n')

latest_version = ""

for entry in package_entries:
# Extract package name and version using regular expressions
match_name = re.search(r'^Package: (.+)$', entry, re.MULTILINE)
match_version = re.search(r'^Version: (.+)$', entry, re.MULTILINE)

if match_name and match_version:
package_name = match_name.group(1)
package_version = parse_version(match_version.group(1))

# Update the dictionary with the latest version for each package
if not latest_version or package_version > latest_version:
latest_version = package_version

return str(latest_version)



@transact
def evaluate_update_notification(session, state, latest_version):
priv_fact = ConfigFactory(session, 1)
Expand Down Expand Up @@ -62,11 +86,7 @@ def operation(self):
try:
log.debug('Fetching latest GlobaLeaks version from repository')
packages_file = yield self.fetch_packages_file()
packages_file = packages_file.decode()
versions = [p['Version'] for p in deb822.Deb822.iter_paragraphs(packages_file) if p['Package'] == 'globaleaks']
versions.sort(key=parse_version)

latest_version = versions[-1]
latest_version = get_latest_version(packages_file.decode())

if not self.state.tenants[1].cache.notification.enable_notification_emails_admin:
yield evaluate_update_notification(self.state, latest_version)
Expand Down

0 comments on commit 1f9282f

Please sign in to comment.