<commit_before>#!/usr/bin/python
# Copyright (C) 2013 <NAME> <<EMAIL>>
#
# Licensed under the GNU General Public License Version 3
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

import os
import sys
import apt_pkg
from optparse import OptionParser

from jenkinsctl import *
from pkginfo import *

class BuildJobUpdater:
    def __init__(self):
        self._jenkins = JenkinsBridge()
        self._pkginfo = PackageInfoRetriever()
        self.scheduleBuilds = True

        parser = SafeConfigParser()
        parser.read(['/etc/jenkins/jenkins-dak.conf', 'jenkins-dak.conf'])
        self._supportedArchs = parser.get('Archive', 'archs').split (" ")

    def syncPackages(self):
        pkgList = self._pkginfo.getAllPackages()
        # generate list of all package names, to make the Jenkins job builder
        # smarter in determining if a package was replaced or is still valid
        pkgNameList = []
        for pkg in pkgList:
            pkgNameList += [pkg.pkgname]
        self._jenkins.setRegisteredPackagesList(pkgNameList)

        for pkg in pkgList:
            # check if this is an arch:all package
            if pkg.archs == "all":
                 # our package is arch:all, schedule it on amd64 for build
                 self._jenkins.createUpdateJob(pkg.pkgname, pkg.version, pkg.component, pkg.dist, "all", pkg.info)
                 if not 'all' in pkg.installedArchs:
                     if self.scheduleBuilds:
                         self._jenkins.scheduleBuildIfNotFailed(pkg.pkgname, pkg.version, "all")
                 continue

            for arch in self._supportedArchs:
                if ('any' in pkg.archs) or ('linux-any' in pkg.archs) or (arch in pkg.archs):
                    # we add new packages for our binary architectures
                    self._jenkins.createUpdateJob(pkg.pkgname, pkg.version, pkg.component, pkg.dist, arch, pkg.info)
                    if not arch in pkg.installedArchs:
                        print("Package %s not built for %s!" % (pkg.pkgname, arch))
                        if self.scheduleBuilds:
                            self._jenkins.scheduleBuildIfNotFailed(pkg.pkgname, pkg.version, arch)

    def cruftReport(self):
        pkgList = self._pkginfo.getAllPackages()
        jobList = self._jenkins.currentJobs

        for pkg in pkgList:
            for arch in pkg.archs.split (", "):
                jobName = self._jenkins.getJobName(pkg.pkgname, pkg.version, arch)
                if jobName in jobList:
                    jobList.remove(jobName)

        for job in jobList:
            print("Cruft: %s" % (job))

def main():<commit_msg>Respect all architectures in cruft report<commit_after>#!/usr/bin/python
# Copyright (C) 2013 <NAME> <<EMAIL>>
#
# Licensed under the GNU General Public License Version 3
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

import os
import sys
import apt_pkg
from optparse import OptionParser

from jenkinsctl import *
from pkginfo import *

class BuildJobUpdater:
    def __init__(self):
        self._jenkins = JenkinsBridge()
        self._pkginfo = PackageInfoRetriever()
        self.scheduleBuilds = True

        parser = SafeConfigParser()
        parser.read(['/etc/jenkins/jenkins-dak.conf', 'jenkins-dak.conf'])
        self._supportedArchs = parser.get('Archive', 'archs').split (" ")

    def syncPackages(self):
        pkgList = self._pkginfo.getAllPackages()
        # generate list of all package names, to make the Jenkins job builder
        # smarter in determining if a package was replaced or is still valid
        pkgNameList = []
        for pkg in pkgList:
            pkgNameList += [pkg.pkgname]
        self._jenkins.setRegisteredPackagesList(pkgNameList)

        for pkg in pkgList:
            # check if this is an arch:all package
            if pkg.archs == "all":
                 # our package is arch:all, schedule it on amd64 for build
                 self._jenkins.createUpdateJob(pkg.pkgname, pkg.version, pkg.component, pkg.dist, "all", pkg.info)
                 if not 'all' in pkg.installedArchs:
                     if self.scheduleBuilds:
                         self._jenkins.scheduleBuildIfNotFailed(pkg.pkgname, pkg.version, "all")
                 continue

            for arch in self._supportedArchs:
                if ('any' in pkg.archs) or ('linux-any' in pkg.archs) or (arch in pkg.archs):
                    # we add new packages for our binary architectures
                    self._jenkins.createUpdateJob(pkg.pkgname, pkg.version, pkg.component, pkg.dist, arch, pkg.info)
                    if not arch in pkg.installedArchs:
                        print("Package %s not built for %s!" % (pkg.pkgname, arch))
                        if self.scheduleBuilds:
                            self._jenkins.scheduleBuildIfNotFailed(pkg.pkgname, pkg.version, arch)

    def cruftReport(self):
        pkgList = self._pkginfo.getAllPackages()
        jobList = self._jenkins.currentJobs

        for pkg in pkgList:
            if "," in pkg.archs:
                archs = pkg.archs.split(', ')
            else:
                archs = [pkg.archs]

            for arch in archs:
                jobName = self._jenkins.getJobName(pkg.pkgname, pkg.version, arch)
                if jobName in jobList:
                    jobList.remove(jobName)

        for job in jobList:
            print("Cruft: %s" % (job))

def main():
{'fraction_non_alphanumeric': 0.08531595696317625, 'fraction_numerical': 0.0024246097893620244, 'mean_word_length': 2.2624814631735046, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '942145', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1755, 'n_words': 620}