Merge branch 'main' of https://github.com/jelmer/ognibuild
This commit is contained in:
commit
b4a73897eb
2 changed files with 53 additions and 2 deletions
|
@ -280,8 +280,20 @@ def get_package_for_paths(
|
|||
logging.warning(
|
||||
"More than 1 packages found that contain %r: %r", path, candidates
|
||||
)
|
||||
# Euhr. Pick the one with the shortest name?
|
||||
return sorted(candidates, key=len)[0]
|
||||
try:
|
||||
from .udd import UDD
|
||||
except ModuleNotFoundError:
|
||||
logging.warning('Unable to import UDD, not ranking by popcon')
|
||||
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:
|
||||
return candidates.pop()
|
||||
|
||||
|
|
39
ognibuild/debian/udd.py
Normal file
39
ognibuild/debian/udd.py
Normal 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]
|
Loading…
Add table
Reference in a new issue