This commit is contained in:
Jelmer Vernooij 2021-03-20 14:02:54 +00:00
commit b4a73897eb
No known key found for this signature in database
GPG key ID: 579C160D4C9E23E8
2 changed files with 53 additions and 2 deletions

View file

@ -280,8 +280,20 @@ def get_package_for_paths(
logging.warning( logging.warning(
"More than 1 packages found that contain %r: %r", path, candidates "More than 1 packages found that contain %r: %r", path, candidates
) )
# Euhr. Pick the one with the shortest name? try:
from .udd import UDD
except ModuleNotFoundError:
logging.warning('Unable to import UDD, not ranking by popcon')
return sorted(candidates, key=len)[0] return sorted(candidates, key=len)[0]
udd = UDD()
udd.connect()
winner = udd.get_most_popular(candidates)
if winner is None:
logging.warning(
'No relevant popcon information found, not ranking by popcon')
return sorted(candidates, key=len)[0]
logging.info('Picked winner using popcon')
return winner
else: else:
return candidates.pop() return candidates.pop()

39
ognibuild/debian/udd.py Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/python3
# Copyright (C) 2021 Jelmer Vernooij
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Support for accessing UDD."""
class UDD(object):
def connect(self):
import psycopg2
self._conn = psycopg2.connect(
database="udd",
user="udd-mirror",
password="udd-mirror",
port=5432,
host="udd-mirror.debian.net",
)
def get_most_popular(self, packages):
cursor = self._conn.cursor()
cursor.execute(
'SELECT package FROM popcon WHERE package IN %s ORDER BY insts DESC LIMIT 1',
(tuple(packages), ))
return cursor.fetchone()[0]