2013-02-23 18:43:43 +01:00
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from gentoolkit.package import Package
|
2013-02-26 09:33:25 +01:00
|
|
|
from dateutil.parser import parse
|
2013-02-23 18:43:43 +01:00
|
|
|
|
2013-03-09 12:07:47 +01:00
|
|
|
from django.db.models import Q
|
|
|
|
|
|
|
|
from gentoolkit.errors import GentoolkitFatalError
|
|
|
|
|
2013-02-23 18:43:43 +01:00
|
|
|
from djeuscan.processing import FakeLogger
|
|
|
|
from djeuscan.models import Version
|
|
|
|
|
|
|
|
|
|
|
|
def get_version_date(version, date_limit):
|
|
|
|
"""
|
2013-02-26 09:33:25 +01:00
|
|
|
Returns the datetime when the version was added to Portage,
|
|
|
|
if less than date_limit
|
2013-02-23 18:43:43 +01:00
|
|
|
"""
|
2013-02-26 09:33:25 +01:00
|
|
|
changelog_path = os.path.join(
|
|
|
|
os.path.dirname(version.ebuild_path),
|
|
|
|
"ChangeLog"
|
|
|
|
)
|
2013-02-23 18:43:43 +01:00
|
|
|
if not os.path.exists(changelog_path):
|
|
|
|
return
|
|
|
|
|
|
|
|
with open(changelog_path) as changelog:
|
|
|
|
for line in changelog:
|
2013-02-26 09:33:25 +01:00
|
|
|
match = re.match(
|
|
|
|
r"^\*([^\(]+) \((\d\d \w\w\w \d\d\d\d)\)\s*$", line
|
|
|
|
)
|
2013-02-23 18:43:43 +01:00
|
|
|
if match:
|
|
|
|
version_date = parse(match.group(2)).date()
|
|
|
|
if version_date < date_limit:
|
|
|
|
return version_date
|
|
|
|
|
|
|
|
|
2013-02-26 09:33:25 +01:00
|
|
|
def stabilization_candidates(days_to_candidate=30, logger=None):
|
2013-02-23 18:43:43 +01:00
|
|
|
"""
|
|
|
|
Collect stabilization candidates
|
|
|
|
"""
|
|
|
|
|
|
|
|
if logger is None:
|
|
|
|
logger = FakeLogger()
|
|
|
|
|
2013-02-26 09:33:25 +01:00
|
|
|
date_diff = (datetime.utcnow() - timedelta(days=days_to_candidate))
|
|
|
|
date_limit = date_diff.date()
|
2013-02-23 18:43:43 +01:00
|
|
|
|
2013-02-26 09:33:25 +01:00
|
|
|
logger.info("Collecting stabilization candidates - date_limit=%s",
|
|
|
|
str(date_limit))
|
2013-02-23 18:43:43 +01:00
|
|
|
|
|
|
|
# Set all versions to not be stabilization_candidates
|
|
|
|
#Version.objects.update(stabilization_candidate=False)
|
|
|
|
|
|
|
|
# For every version check if it's unstable.
|
|
|
|
# If it is then check if can be a stabilization candidate
|
2013-03-09 12:07:47 +01:00
|
|
|
versions = Version.objects.filter(overlay='gentoo').filter(
|
|
|
|
Q(vtype='release') | Q(vtype='p'))
|
2013-02-26 09:33:25 +01:00
|
|
|
for version in versions:
|
2013-02-23 18:43:43 +01:00
|
|
|
pkg = Package(version.cpv())
|
2013-03-09 12:07:47 +01:00
|
|
|
try:
|
|
|
|
keywords = pkg.environment("KEYWORDS").split()
|
|
|
|
except GentoolkitFatalError:
|
|
|
|
logger.warning("Error while processing %s!", version)
|
|
|
|
continue
|
2013-02-23 18:43:43 +01:00
|
|
|
if all([x.startswith("~") for x in keywords]):
|
|
|
|
version_date = get_version_date(version, date_limit)
|
|
|
|
if version_date:
|
|
|
|
logger.info('+ [s] %s @ %s', version, version_date)
|
2013-02-26 09:33:25 +01:00
|
|
|
# XXX: What should we save? A flag and the date?Just the date?
|
|
|
|
version.stabilization_candidate = version_date
|
|
|
|
version.save()
|
2013-02-23 18:43:43 +01:00
|
|
|
|
|
|
|
logger.info("Finished collecting stabilization candidates")
|