Esempio n. 1
0
def log(session, package, topic, message):
    """ Take a partial fedmsg topic and message.

    Publish the message and log it in the db.
    """

    # To avoid a circular import.
    import pkgdb2.lib.model as model
    from pkgdb2.lib.notifications import fedmsg_publish, email_publish

    # A big lookup of fedmsg topics to model.Log template strings.
    templates = {
        'acl.update': 'user: %(agent)s set acl: %(acl)s of package: '
                      '%(package_name)s from: '
                      '%(previous_status)s to: '
                      '%(status)s on branch: '
                      '%(package_listing.collection.branchname)s',
        'owner.update': 'user: %(agent)s changed poc of package: '
                        '%(package_name)s from: '
                        '%(previous_owner)s to: '
                        '%(username)s on branch: '
                        '%(package_listing.collection.branchname)s',
        'branch.start': 'user: %(agent)s started branching from '
                        '%(collection_from.branchname)s to '
                        '%(collection_to.branchname)s',
        'branch.complete': 'user: %(agent)s finished branching from '
                           '%(collection_from.branchname)s to '
                           '%(collection_to.branchname)s',
        'package.new': 'user: %(agent)s created package: '
                       '%(package_name)s on branch: '
                       '%(package_listing.collection.branchname)s for poc: '
                       '%(package_listing.point_of_contact)s',
        'package.update': 'user: %(agent)s updated package: '
                          '%(package.name)s',
        'package.update.status': 'user: %(agent)s updated package: '
                          '%(package_name)s status from: '
                          '%(prev_status)s to '
                          '%(status)s on branch: '
                          '%(package_listing.collection.branchname)s',
        'collection.new': 'user: %(agent)s created collection: '
                          '%(collection.name)s',
        'collection.update': 'user: %(agent)s edited collection: '
                             '%(collection.name)s',
    }
    substitutions = _construct_substitutions(message)
    final_msg = templates[topic] % substitutions

    model.Log.insert(session, message['agent'], package, final_msg)

    if pkgdb2.APP.config.get('PKGDB2_FEDMSG_NOTIFICATION', True):
        fedmsg_publish(topic, message)
    if pkgdb2.APP.config.get('PKGDB2_EMAIL_NOTIFICATION', False):
        email_publish(message['agent'], package, final_msg)
    return final_msg
Esempio n. 2
0
def log(session, package, topic, message):
    """ Take a partial fedmsg topic and message.

    Publish the message and log it in the db.
    """

    # To avoid a circular import.
    import pkgdb2.lib.model as model
    from pkgdb2.lib.notifications import fedmsg_publish, email_publish

    if pkgdb2.APP.config.get('PKGDB2_FEDMSG_NOTIFICATION', True):
        fedmsg_publish(topic, message)

    # A big lookup of fedmsg topics to model.Log template strings.
    templates = {
        'acl.update': 'user: %(agent)s set for %(username)s acl: %(acl)s of'
                      ' package: %(package_name)s from: '
                      '%(previous_status)s to: '
                      '%(status)s on branch: '
                      '%(package_listing.collection.branchname)s',
        'acl.delete': 'user: %(agent)s deleted acl: %(acl.acl)s of '
                      'package: %(acl.packagelist.package.name)s of user: '
                      '%(acl.fas_name)s on: '
                      '%(acl.packagelist.collection.branchname)s',
        'owner.update': 'user: %(agent)s changed point of contact of package: '
                        '%(package_name)s from: '
                        '%(previous_owner)s to: '
                        '%(username)s on branch: '
                        '%(package_listing.collection.branchname)s',
        'branch.start': 'user: %(agent)s started branching from '
                        '%(collection_from.branchname)s to '
                        '%(collection_to.branchname)s',
        'branch.complete': 'user: %(agent)s finished branching from '
                           '%(collection_from.branchname)s to '
                           '%(collection_to.branchname)s',
        'package.branch.delete': 'user: %(agent)s deleted branch: '
                                 '%(package_listing.collection.'
                                 'branchname)s '
                                 'for package %(package_listing.'
                                 'package.name)s ',
        'package.branch.new': 'user: %(agent)s created branch '
                              '%(package_listing.collection.'
                              'branchname)s on package %(package.name)s',
        'package.branch.request': 'user: %(agent)s requested branch: '
                                 '%(collection_to.branchname)s '
                                 'for package %(package.name)s',
        'package.new.request': 'user: %(agent)s request package: '
                               '%(info.pkg_name)s on branch '
                               '%(collection.branchname)s',
        'package.delete': 'user: %(agent)s deleted package %(package.name)s',
        'package.new': 'user: %(agent)s created package: '
                       '%(package_name)s on branch: '
                       '%(package_listing.collection.branchname)s for point'
                       ' of contact: %(package_listing.point_of_contact)s',
        'package.critpath.update': 'user: %(agent)s updated critpath status'
                                   'for package: %(package.name)s on '
                                   'branches %(branches)s',
        'package.unretire.request': 'user: %(agent)s requested branch: '
                                    '%(collection.branchname)s to be '
                                    'unretired for package %(package.name)s',
        'package.update': 'user: %(agent)s updated %(fields)s package: '
                          '%(package.name)s',
        'package.update.status': 'user: %(agent)s updated package: '
                          '%(package_name)s status from: '
                          '%(prev_status)s to '
                          '%(status)s on branch: '
                          '%(package_listing.collection.branchname)s',
        'collection.new': 'user: %(agent)s created collection: '
                          '%(collection.name)s',
        'collection.update': 'user: %(agent)s edited collection: '
                             '%(collection.name)s',
        'package.monitor.update': 'user: %(agent)s updated the monitoring '
                               'status of %(package.name)s to %(status)s',
        'admin.action.status.update': 'user: %(agent)s updated action: '
                               '%(action.id)s of %(action.package.name)s '
                               'from `%(old_status)s` to `%(new_status)s`',
        'package.koschei.update': 'user: %(agent)s updated the Koschei '
                               'monitoring status of %(package.name)s to '
                               '%(status)s',
        'namespace.new': 'user: %(agent)s added a new namespace: '
                               '%(namespace)s',
        'namespace.drop': 'user: %(agent)s removed a namespace: %(namespace)s',
    }
    subject_templates = {
        'acl.update': '%(agent)s:%(package_name)s %(acl)s  set to %(status)s',
        'owner.update': '%(agent)s:%(package_name)s set point of contact to: '
                        '%(username)s',
        'package.branch.request': '%(agent)s:%(package.name)s requested new '
                                  'branch %(collection_to.branchname)s',
        'package.unretire.request': '%(agent)s:%(package.name)s requested '
                                    'that branch %(collection.branchname)s '
                                    'be unretired',
        'package.update': '%(agent)s updated package: '
                          '%(package.name)s',
        'package.update.status': '%(agent)s updated package: '
                          '%(package_name)s status to '
                          '%(status)s ['
                          '%(package_listing.collection.branchname)s]',
    }
    substitutions = _construct_substitutions(message)

    if topic == 'admin.action.status.update' \
            and 'action' in message \
            and 'info' in message['action'] \
            and 'pkg_name' in message['action']['info'] \
            and message['action']['info']['pkg_name']:
        templates[topic] = 'user: %(agent)s updated action: ' \
           '%(action.id)s of %(action.info.pkg_name)s ' \
           'from `%(old_status)s` to `%(new_status)s`'

    if topic == 'admin.action.status.update' \
            and 'action' in message \
            and 'message' in message['action'] \
            and message['action']['message']:
        templates[topic] += ' with message: %(action.message)s'

    final_msg = templates[topic] % substitutions
    subject = None
    if topic in subject_templates:
        subject = subject_templates[topic] % substitutions

    model.Log.insert(session, message['agent'], package, final_msg)

    if pkgdb2.APP.config.get(
            'PKGDB2_EMAIL_NOTIFICATION', False):  # pragma: no cover
        body_email = final_msg
        if package:
            body_email = '{0}\n\nTo make changes to this package see:\n' \
                '{1}/package/{2}'.format(
                    final_msg, pkgdb2.APP.config.get('SITE_URL'),
                    package.name)
        email_publish(
            message['agent'], package, body_email, subject=subject)

    return final_msg
Esempio n. 3
0
def log(session, package, topic, message):
    """ Take a partial fedmsg topic and message.

    Publish the message and log it in the db.
    """

    # To avoid a circular import.
    import pkgdb2.lib.model as model
    from pkgdb2.lib.notifications import fedmsg_publish, email_publish

    if pkgdb2.APP.config.get("PKGDB2_FEDMSG_NOTIFICATION", True):
        fedmsg_publish(topic, message)

    # A big lookup of fedmsg topics to model.Log template strings.
    templates = {
        "acl.update": "user: %(agent)s set for %(username)s acl: %(acl)s of"
        " package: %(package_name)s from: "
        "%(previous_status)s to: "
        "%(status)s on branch: "
        "%(package_listing.collection.branchname)s",
        "acl.delete": "user: %(agent)s deleted acl: %(acl.acl)s of "
        "package: %(acl.packagelist.package.name)s of user: "
        "%(acl.fas_name)s on: "
        "%(acl.packagelist.collection.branchname)s",
        "owner.update": "user: %(agent)s changed point of contact of package: "
        "%(package_name)s from: "
        "%(previous_owner)s to: "
        "%(username)s on branch: "
        "%(package_listing.collection.branchname)s",
        "branch.start": "user: %(agent)s started branching from "
        "%(collection_from.branchname)s to "
        "%(collection_to.branchname)s",
        "branch.complete": "user: %(agent)s finished branching from "
        "%(collection_from.branchname)s to "
        "%(collection_to.branchname)s",
        "package.branch.delete": "user: %(agent)s deleted branch: "
        "%(package_listing.collection."
        "branchname)s "
        "for package %(package_listing."
        "package.name)s ",
        "package.delete": "user: %(agent)s deleted package %(package.name)s",
        "package.new": "user: %(agent)s created package: "
        "%(package_name)s on branch: "
        "%(package_listing.collection.branchname)s for point"
        " of contact: %(package_listing.point_of_contact)s",
        "package.critpath.update": "user: %(agent)s updated critpath status"
        "for package: %(package.name)s on "
        "branches %(branches)s",
        "package.update": "user: %(agent)s updated %(fields)s package: " "%(package.name)s",
        "package.update.status": "user: %(agent)s updated package: "
        "%(package_name)s status from: "
        "%(prev_status)s to "
        "%(status)s on branch: "
        "%(package_listing.collection.branchname)s",
        "collection.new": "user: %(agent)s created collection: " "%(collection.name)s",
        "collection.update": "user: %(agent)s edited collection: " "%(collection.name)s",
    }
    subject_templates = {
        "acl.update": "%(agent)s:%(package_name)s %(acl)s  set to %(status)s",
        "owner.update": "%(agent)s:%(package_name)s set point of contact to: " "%(username)s",
        "package.update": "%(agent)s updated package: " "%(package.name)s",
        "package.update.status": "%(agent)s updated package: "
        "%(package_name)s status to "
        "%(status)s ["
        "%(package_listing.collection.branchname)s]",
    }
    substitutions = _construct_substitutions(message)
    final_msg = templates[topic] % substitutions
    subject = None
    if topic in subject_templates:
        subject = subject_templates[topic] % substitutions

    model.Log.insert(session, message["agent"], package, final_msg)

    if pkgdb2.APP.config.get("PKGDB2_EMAIL_NOTIFICATION", False):  # pragma: no cover
        body_email = final_msg
        if package:
            body_email = "{0}\n\nTo make changes to this package see:\n" "{1}/package/{2}".format(
                final_msg, pkgdb2.APP.config.get("SITE_URL"), package.name
            )
        email_publish(message["agent"], package, body_email, subject=subject)

    return final_msg
Esempio n. 4
0
def log(session, package, topic, message):
    """ Take a partial fedmsg topic and message.

    Publish the message and log it in the db.
    """

    # To avoid a circular import.
    import pkgdb2.lib.model as model
    from pkgdb2.lib.notifications import fedmsg_publish, email_publish

    if pkgdb2.APP.config.get('PKGDB2_FEDMSG_NOTIFICATION', True):
        fedmsg_publish(topic, message)

    # A big lookup of fedmsg topics to model.Log template strings.
    templates = {
        'acl.update': 'user: %(agent)s set for %(username)s acl: %(acl)s of'
                      ' package: %(package_name)s from: '
                      '%(previous_status)s to: '
                      '%(status)s on branch: '
                      '%(package_listing.collection.branchname)s',
        'acl.delete': 'user: %(agent)s deleted acl: %(acl.acl)s of '
                      'package: %(acl.packagelist.package.name)s of user: '
                      '%(acl.fas_name)s on: '
                      '%(acl.packagelist.collection.branchname)s',
        'owner.update': 'user: %(agent)s changed point of contact of package: '
                        '%(package_name)s from: '
                        '%(previous_owner)s to: '
                        '%(username)s on branch: '
                        '%(package_listing.collection.branchname)s',
        'branch.start': 'user: %(agent)s started branching from '
                        '%(collection_from.branchname)s to '
                        '%(collection_to.branchname)s',
        'branch.complete': 'user: %(agent)s finished branching from '
                           '%(collection_from.branchname)s to '
                           '%(collection_to.branchname)s',
        'package.branch.delete': 'user: %(agent)s deleted branch: '
                                 '%(package_listing.collection.'
                                 'branchname)s '
                                 'for package %(package_listing.'
                                 'package.name)s ',
        'package.delete': 'user: %(agent)s deleted package %(package.name)s',
        'package.new': 'user: %(agent)s created package: '
                       '%(package_name)s on branch: '
                       '%(package_listing.collection.branchname)s for point'
                       ' of contact: %(package_listing.point_of_contact)s',
        'package.update': 'user: %(agent)s updated package: '
                          '%(package.name)s',
        'package.update.status': 'user: %(agent)s updated package: '
                          '%(package_name)s status from: '
                          '%(prev_status)s to '
                          '%(status)s on branch: '
                          '%(package_listing.collection.branchname)s',
        'collection.new': 'user: %(agent)s created collection: '
                          '%(collection.name)s',
        'collection.update': 'user: %(agent)s edited collection: '
                             '%(collection.name)s',
    }
    subject_templates = {
        'acl.update': '%(agent)s:%(package_name)s %(acl)s  set to %(status)s',
        'owner.update': '%(agent)s:%(package_name)s set point of contact to: '
                        '%(username)s',
        'package.update': '%(agent)s updated package: '
                          '%(package.name)s',
        'package.update.status': '%(agent)s updated package: '
                          '%(package_name)s status to '
                          '%(status)s ['
                          '%(package_listing.collection.branchname)s]',
    }
    substitutions = _construct_substitutions(message)
    final_msg = templates[topic] % substitutions
    subject = None
    if topic in subject_templates:
        subject = subject_templates[topic] % substitutions

    model.Log.insert(session, message['agent'], package, final_msg)

    if pkgdb2.APP.config.get('PKGDB2_EMAIL_NOTIFICATION', False):
        body_email = '{0}\n\nTo make changes to this package see:\n' \
            '{1}/package/{2}'.format(
                final_msg, pkgdb2.APP.config.get('SITE_URL'),
                package.name)
        email_publish(
            message['agent'], package, body_email, subject=subject)

    return final_msg