chiark / gitweb /
App.get_last_build() method to replace duplicated code
authorHans-Christoph Steiner <hans@eds.org>
Fri, 18 Nov 2016 22:17:19 +0000 (23:17 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 5 Dec 2016 19:16:54 +0000 (20:16 +0100)
Look @mvdan, I added a method to the App class!

fdroidserver/checkupdates.py
fdroidserver/metadata.py

index 43447ca8f46fe682a14cfdf339a6f7be454a5199..7f5314b8d72b44ee754fcffcf6a43665f9866849 100644 (file)
@@ -109,9 +109,7 @@ def check_tags(app, pattern):
 
         vcs.gotorevision(None)
 
-        last_build = metadata.Build()
-        if len(app.builds) > 0:
-            last_build = app.builds[-1]
+        last_build = app.get_last_build()
 
         if last_build.submodules:
             vcs.initsubmodules()
@@ -322,9 +320,7 @@ def possible_subdirs(app):
     else:
         build_dir = os.path.join('build', app.id)
 
-    last_build = metadata.Build()
-    if len(app.builds) > 0:
-        last_build = app.builds[-1]
+    last_build = app.get_last_build()
 
     for d in dirs_with_manifest(build_dir):
         m_paths = common.manifest_paths(d, last_build.gradle)
@@ -351,9 +347,7 @@ def fetch_autoname(app, tag):
     except VCSException:
         return None
 
-    last_build = metadata.Build()
-    if len(app.builds) > 0:
-        last_build = app.builds[-1]
+    last_build = app.get_last_build()
 
     logging.debug("...fetch auto name from " + build_dir)
     new_name = None
index 198bdea23864b9af8b3c01cde179585e9b623296..212128f38998fca7802e1073d898f5357c63b941 100644 (file)
@@ -239,6 +239,12 @@ class App():
                 self.__dict__[k] = v
                 self._modified.add(k)
 
+    def get_last_build(self):
+        if len(self.builds) > 0:
+            return self.builds[-1]
+        else:
+            return Build()
+
 
 TYPE_UNKNOWN = 0
 TYPE_OBSOLETE = 1