From 719f8d6cce2b28d80ea1f2557c3aedee52556bb3 Mon Sep 17 00:00:00 2001 From: Jiri Popelka Date: Wed, 7 Jun 2017 15:09:04 +0200 Subject: [PATCH] [PackagePostgres] add get_analysis_count(ecosystem, package) --- cucoslib/storages/package_postgres.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cucoslib/storages/package_postgres.py b/cucoslib/storages/package_postgres.py index a6c798c1e..6e574681a 100644 --- a/cucoslib/storages/package_postgres.py +++ b/cucoslib/storages/package_postgres.py @@ -45,3 +45,21 @@ def get_analysis_by_id(self, analysis_id): one() return found + + def get_analysis_count(self, ecosystem, package): + """Get count of previously scheduled analyses for given ecosystem-package. + + :param ecosystem: str, Ecosystem name + :param package: str, Package name + :return: analysis count + """ + if ecosystem == 'maven': + package = MavenCoordinates.normalize_str(package) + + count = self.session.query(PackageAnalysis).\ + join(Package).join(Ecosystem).\ + filter(Ecosystem.name == ecosystem).\ + filter(Package.name == package).\ + count() + + return count