From 74dddfd9fbe562304f9b152a8523e38bb9456ac4 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 2 May 2023 10:57:35 +0200 Subject: [PATCH] refactor App.get_last_build() to checkupdates This function is only used in checkupdates, and removing it from the App class moves the App class one step closer to being a plain dict, which is a more Pythonic style. --- fdroidserver/checkupdates.py | 18 +++++++++++------- fdroidserver/metadata.py | 6 ------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/fdroidserver/checkupdates.py b/fdroidserver/checkupdates.py index b00ec572..d5a136ad 100644 --- a/fdroidserver/checkupdates.py +++ b/fdroidserver/checkupdates.py @@ -110,7 +110,7 @@ def check_tags(app, pattern): vcs.gotorevision(None) - last_build = app.get_last_build() + last_build = get_last_build_from_app(app) try_init_submodules(app, last_build, vcs) @@ -252,10 +252,7 @@ def check_repomanifest(app, branch=None): elif repotype == 'bzr': vcs.gotorevision(None) - last_build = metadata.Build() - if app.get('Builds', []): - last_build = app.get('Builds', [])[-1] - + last_build = get_last_build_from_app(app) try_init_submodules(app, last_build, vcs) hpak = None @@ -364,7 +361,7 @@ def possible_subdirs(app): else: build_dir = Path('build') / app.id - last_build = app.get_last_build() + last_build = get_last_build_from_app(app) for d in dirs_with_manifest(build_dir): m_paths = common.manifest_paths(d, last_build.gradle) @@ -399,7 +396,7 @@ def fetch_autoname(app, tag): except VCSException: return None - last_build = app.get_last_build() + last_build = get_last_build_from_app(app) logging.debug("...fetch auto name from " + str(build_dir)) new_name = None @@ -579,6 +576,13 @@ def checkupdates_app(app): raise FDroidException("Git commit failed") +def get_last_build_from_app(app): + if app.get('Builds'): + return app['Builds'][-1] + else: + return metadata.Build() + + def status_update_json(processed, failed): """Output a JSON file with metadata about this run.""" logging.debug(_('Outputting JSON')) diff --git a/fdroidserver/metadata.py b/fdroidserver/metadata.py index f5302f05..1298f255 100644 --- a/fdroidserver/metadata.py +++ b/fdroidserver/metadata.py @@ -174,12 +174,6 @@ class App(dict): else: raise AttributeError("No such attribute: " + name) - def get_last_build(self): - if len(self.Builds) > 0: - return self.Builds[-1] - else: - return Build() - TYPE_STRING = 2 TYPE_BOOL = 3