How to use the patchman.signals.error_message function in patchman

To help you get started, we’ve selected a few patchman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github furlongm / patchman / repos / utils.py View on Github external
def checksum_is_valid(sha, checksum, mirror):
    """ Compares the computed checksum and the provided checksum. Returns True
        if both match.
    """

    if sha == checksum:
        return True
    else:
        text = 'Checksum failed for mirror {0!s}'.format(mirror.id)
        text += ', not refreshing package metadata'
        error_message.send(sender=None, text=text)
        text = 'Found sha = {0!s}\nExpected  = {1!s}'.format(sha, checksum)
        error_message.send(sender=None, text=text)
        mirror.last_access_ok = False
        return False
github furlongm / patchman / reports / utils.py View on Github external
host_repos = HostRepo.objects.filter(host=host)
        repos = parse_repos(report.repos)

        progress_info_s.send(sender=None,
                             ptext='{0!s} repos'.format(str(host)[0:25]),
                             plen=len(repos))
        for i, repo_str in enumerate(repos):
            repo, priority = process_repo(repo_str, report.arch)
            if repo:
                repo_ids.append(repo.id)
                try:
                    with transaction.atomic():
                        hostrepo, c = host_repos.get_or_create(host=host,
                                                               repo=repo)
                except IntegrityError as e:
                    error_message.send(sender=None, text=e)
                    hostrepo = host_repos.get(host=host, repo=repo)
                try:
                    if hostrepo.priority != priority:
                        hostrepo.priority = priority
                        with transaction.atomic():
                            hostrepo.save()
                except IntegrityError as e:
                    error_message.send(sender=None, text=e)
            progress_update_s.send(sender=None, index=i + 1)

        for hostrepo in host_repos:
            if hostrepo.repo.id not in repo_ids:
                hostrepo.delete()
github furlongm / patchman / hosts / models.py View on Github external
if mirror.repo.security:
                security = True
        try:
            updates = PackageUpdate.objects.all()
            with transaction.atomic():
                update, c = updates.get_or_create(
                    oldpackage=package,
                    newpackage=highest_package,
                    security=security)
        except IntegrityError as e:
            error_message.send(sender=None, text=e)
            update = updates.get(oldpackage=package,
                                 newpackage=highest_package,
                                 security=security)
        except DatabaseError as e:
            error_message.send(sender=None, text=e)
        try:
            with transaction.atomic():
                self.updates.add(update)
            info_message.send(sender=None, text='{0!s}'.format(update))
            return update.id
        except IntegrityError as e:
            error_message.send(sender=None, text=e)
        except DatabaseError as e:
            error_message.send(sender=None, text=e)
github furlongm / patchman / util / __init__.py View on Github external
def gunzip(contents):
    """ gunzip contents in memory and return the data
    """
    try:
        wbits = zlib.MAX_WBITS | 32
        return zlib.decompress(contents, wbits)
    except zlib.error as e:
        error_message.send(sender=None, text='gunzip: ' + str(e))
github furlongm / patchman / reports / models.py View on Github external
if find_updates:
                if verbose:
                    text = 'Finding updates for report '
                    text += '{0!s} - {1!s}'.format(self.id, self.host)
                    info_message.send(sender=None, text=text)
                host.find_updates()
        else:
            if self.processed:
                text = 'Report {0!s} '.format(self.id)
                text += 'has already been processed'
                info_message.send(sender=None, text=text)
            else:
                text = 'Error: OS, kernel or arch not sent '
                text += 'with report {0!s}'.format(self.id)
                error_message.send(sender=None, text=text)
github furlongm / patchman / reports / models.py View on Github external
host.ipaddress = self.report_ip
            host.kernel = self.kernel
            host.arch = arch
            host.os = os
            host.domain = domain
            host.lastreport = self.created
            host.tags = self.tags
            if self.reboot == 'True':
                host.reboot_required = True
            else:
                host.reboot_required = False
            try:
                with transaction.atomic():
                    host.save()
            except IntegrityError as e:
                error_message.send(sender=None, text=e)
            except DatabaseError as e:
                error_message.send(sender=None, text=e)
            host.check_rdns()

            if verbose:
                text = 'Processing report '
                text += '{0!s} - {1!s}'.format(self.id, self.host)
                info_message.send(sender=None, text=text)

            from reports.utils import process_packages, \
                process_repos, process_updates
            with transaction.atomic():
                process_repos(report=self, host=host)
            with transaction.atomic():
                process_packages(report=self, host=host)
            with transaction.atomic():
github furlongm / patchman / packages / utils.py View on Github external
package_arches = PackageArchitecture.objects.all()
    with transaction.atomic():
        p_arch, c = package_arches.get_or_create(name=arch)

    try:
        with transaction.atomic():
            packages = Package.objects.all()
            package, c = packages.get_or_create(name=p_name,
                                                arch=p_arch,
                                                epoch=epoch,
                                                version=version,
                                                release=release,
                                                packagetype=p_type)
    except IntegrityError as e:
        error_message.send(sender=None, text=e)
        package = packages.get(name=p_name,
                               arch=p_arch,
                               epoch=epoch,
                               version=version,
                               release=release,
                               packagetype=p_type)
    except DatabaseError as e:
        error_message.send(sender=None, text=e)
    return package
github furlongm / patchman / repos / models.py View on Github external
def fail(self):
        """ Records that the mirror has failed
            Disables refresh on a mirror if it fails more than 28 times
        """
        text = 'No usable mirror found at {0!s}'.format(self.url)
        error_message.send(sender=None, text=text)
        self.fail_count = self.fail_count + 1
        if self.fail_count > 28:
            self.refresh = False
            text = 'Mirror has failed more than 28 times, disabling refresh'
            error_message.send(sender=None, text=text)
github furlongm / patchman / util / __init__.py View on Github external
def get_url(url):
    """ Perform a http GET on a URL. Return None on error.
    """
    res = None
    try:
        res = requests.get(url, stream=True)
    except requests.exceptions.Timeout:
        error_message.send(sender=None, text='Timeout - {0!s}'.format(url))
    except requests.exceptions.TooManyRedirects:
        error_message.send(sender=None,
                           text='Too many redirects - {0!s}'.format(url))
    except requests.exceptions.RequestException as e:
        error_message.send(sender=None,
                           text='Error ({0!s}) - {1!s}'.format(e, url))
    return res
github furlongm / patchman / patchman / receivers.py View on Github external
@receiver(error_message)
def print_error_message(**kwargs):
    """ Receiver to print an error message in red text
    """
    text = kwargs.get('text')
    if text:
        print(Style.BRIGHT + Fore.RED + text)