Esempio n. 1
0
def _series_supersede_previous_patches(series):
    total_series_revs = len(Series(series).revisions())
    # If there is only one revision for the series, we have nothing to do
    if total_series_revs < 2:
        return
    # process all patches in series
    processed_patches = []
    for i in range(0, (total_series_revs)):
        total_rev_patches = len(
            Series(series).revisions()[i].ordered_patches())
        # process all patches in current revision
        for l in range(0, total_rev_patches):
            patch_id = Series(series).revisions()[i].ordered_patches()[l].pk
            patch_name = Series(series).revisions()[i]\
                .ordered_patches()[l].name
            # don't process v# or [##/##] in patch name
            striped_name = re.sub(
                '(\[.*\]\s*)?(\s*\(?v\d+\)?\s*)?(.*)(v\d+$)?', r'\3',
                patch_name, flags=re.IGNORECASE)
            # add patch revision-name-id to list
            processed_patches.append(("rev_%s" % (i + 1), striped_name,
                                     patch_id, i, l))
    total_processed = len(processed_patches)
    for p in range(0, total_processed):
        # Use only patches from latest revision as base for comparisons
        if processed_patches[p][0] == 'rev_%s' % total_series_revs:
            # Compare names with patches from all previous revisions
            for q in range(0, total_processed):
                if not processed_patches[q][0] == 'rev_%s' % total_series_revs:
                    processed_patch = Patch.objects.get(
                        pk=processed_patches[q][2])
                    # if patches have the same name AND different ID
                    # AND are in a state different than Superseded
                    if processed_patches[p][1] == processed_patches[q][1] and \
                            processed_patches[q][2] != processed_patches[p][2]\
                            and processed_patch.state.name != 'Superseded':
                        # mark patch from previous revision as Superseded
                        processed_patch = Patch.objects.get(
                            pk=processed_patches[q][2])
                        new_state = State.objects.get(name='Superseded')
                        processed_patch.state = new_state
                        processed_patch.save()
                        # Detail the state change as a comment
                        # in superseded patch
                        content = "This is a system generated Comment: Patch \
%s was automatically marked as superseded by patch %s." % (processed_patch.id,
                                  processed_patches[p][2])
                        msgid = "%s: System generated by patch %s" % (datetime
                                .datetime.now().strftime("%d%b%Y.%H:%M:%S.%f"),
                                processed_patches[p][2])
                        sbmtr = threadlocalrequest.get_current_user()
                        if sbmtr is None:
                            sbmtr = Patch.objects.get(pk=processed_patches
                                                      [p][2]).submitter
                        new_comment = Comment(pk=None, patch=processed_patch,
                                              headers=msgid, content=content,
                                              date=datetime.datetime.now(),
                                              submitter=sbmtr, msgid=msgid)
                        new_comment.save()
Esempio n. 2
0
def _patch_change_callback(sender, instance, **kwargs):
    # we only want notification of modified patches
    if instance.pk is None:
        return

    if instance.project is None:
        return

    try:
        orig_patch = Patch.objects.get(pk=instance.pk)
    except Patch.DoesNotExist:
        return

    # If there's no interesting changes, abort without creating the
    # notification or log
    if orig_patch.state == instance.state:
        return

    # If state changed, log the event
    event_state_change = Event.objects.get(name='patch-state-change')
    curr_user = threadlocalrequest.get_current_user()
    previous_state = str(orig_patch.state)
    new_state = str(instance.state)
    changed_patch = Patch.objects.get(pk=instance.pk)

    # Do not log patch-state-change events for Patches that are not part of a
    # Series (ie patches older than the introduction of Series)
    series = find_series_for_patch(orig_patch)
    if series:
        log = EventLog(event=event_state_change,
                       user=curr_user,
                       series_id=series.id,
                       patch=changed_patch,
                       parameters={
                           'previous_state': previous_state,
                           'new_state': new_state,
                       })
        log.save()

    if not instance.project.send_notifications:
        return

    notification = None
    try:
        notification = PatchChangeNotification.objects.get(patch=instance)
    except PatchChangeNotification.DoesNotExist:
        pass

    if notification is None:
        notification = PatchChangeNotification(patch=instance,
                                               orig_state=orig_patch.state)

    elif notification.orig_state == instance.state:
        # If we're back at the original state, there is no need to notify
        notification.delete()
        return

    notification.last_modified = datetime.datetime.now()
    notification.save()
Esempio n. 3
0
def _series_supersede_previous_patches(series):
    total_series_revs = len(Series(series).revisions())
    # If there is only one revision for the series, we have nothing to do
    if total_series_revs < 2:
        return
    # process all patches in series
    processed_patches = []
    for i in range(0, (total_series_revs)):
        total_rev_patches = len(
            Series(series).revisions()[i].ordered_patches())
        # process all patches in current revision
        for l in range(0, total_rev_patches):
            patch_id = Series(series).revisions()[i].ordered_patches()[l].pk
            patch_name = Series(series).revisions()[i]\
                .ordered_patches()[l].name
            # don't process v# or [##/##] in patch name
            striped_name = re.sub(
                '(\[.*\]\s*)?(\s*\(?v\d+\)?\s*)?(.*)(v\d+$)?', r'\3',
                patch_name, flags=re.IGNORECASE)
            # add patch revision-name-id to list
            processed_patches.append(("rev_%s" % (i + 1), striped_name,
                                     patch_id, i, l))
    total_processed = len(processed_patches)
    for p in range(0, total_processed):
        # Use only patches from latest revision as base for comparisons
        if processed_patches[p][0] == 'rev_%s' % total_series_revs:
            # Compare names with patches from all previous revisions
            for q in range(0, total_processed):
                if not processed_patches[q][0] == 'rev_%s' % total_series_revs:
                    processed_patch = Patch.objects.get(
                        pk=processed_patches[q][2])
                    # if patches have the same name AND different ID
                    # AND are in a state different than Superseded
                    if processed_patches[p][1] == processed_patches[q][1] and \
                            processed_patches[q][2] != processed_patches[p][2]\
                            and processed_patch.state.name != 'Superseded':
                        # mark patch from previous revision as Superseded
                        processed_patch = Patch.objects.get(
                            pk=processed_patches[q][2])
                        new_state = State.objects.get(name='Superseded')
                        processed_patch.state = new_state
                        processed_patch.save()
                        # Detail the state change as a comment
                        # in superseded patch
                        content = "This is a system generated Comment: Patch \
%s was automatically marked as superseded by patch %s." % (processed_patch.id,
                                  processed_patches[p][2])
                        msgid = "%s: System generated by patch %s" % (datetime
                                .datetime.now().strftime("%d%b%Y.%H:%M:%S.%f"),
                                processed_patches[p][2])
                        sbmtr = threadlocalrequest.get_current_user()
                        if sbmtr is None:
                            sbmtr = Patch.objects.get(pk=processed_patches
                                                      [p][2]).submitter
                        new_comment = Comment(pk=None, patch=processed_patch,
                                              headers=msgid, content=content,
                                              date=datetime.datetime.now(),
                                              submitter=sbmtr, msgid=msgid)
                        new_comment.save()
Esempio n. 4
0
def _patch_change_callback(sender, instance, **kwargs):
    # we only want notification of modified patches
    if instance.pk is None:
        return

    if instance.project is None:
        return

    try:
        orig_patch = Patch.objects.get(pk=instance.pk)
    except Patch.DoesNotExist:
        return

    # If there's no interesting changes, abort without creating the
    # notification or log
    if orig_patch.state == instance.state:
        return

    # If state changed, log the event
    event_state_change = Event.objects.get(name='patch-state-change')
    curr_user = threadlocalrequest.get_current_user()
    previous_state = str(orig_patch.state)
    new_state = str(instance.state)
    changed_patch = Patch.objects.get(pk=instance.pk)

    # Do not log patch-state-change events for Patches that are not part of a
    # Series (ie patches older than the introduction of Series)
    series = find_series_for_patch(orig_patch)
    if series:
        log = EventLog(event=event_state_change,
                      user=curr_user,
                      series_id=series.id,
                      patch=changed_patch,
                      parameters={'previous_state': previous_state,
                                  'new_state': new_state,
                                 })
        log.save()

    if not instance.project.send_notifications:
        return

    notification = None
    try:
        notification = PatchChangeNotification.objects.get(patch=instance)
    except PatchChangeNotification.DoesNotExist:
        pass

    if notification is None:
        notification = PatchChangeNotification(patch=instance,
                                               orig_state=orig_patch.state)

    elif notification.orig_state == instance.state:
        # If we're back at the original state, there is no need to notify
        notification.delete()
        return

    notification.last_modified = datetime.datetime.now()
    notification.save()
Esempio n. 5
0
def _patch_change_log_event(old_patch, new_patch):
    # If state changed, log the event
    event_state_change = Event.objects.get(name='patch-state-change')
    curr_user = threadlocalrequest.get_current_user()
    previous_state = str(old_patch.state)
    new_state = str(new_patch.state)

    # Do not log patch-state-change events for Patches that are not part of a
    # Series (ie patches older than the introduction of Series)
    series = find_series_for_patch(old_patch)
    if series:
        log = EventLog(event=event_state_change,
                       user=curr_user,
                       series_id=series.id,
                       patch=old_patch,
                       parameters={'previous_state': previous_state,
                                   'new_state': new_state,
                                  })
        log.save()
Esempio n. 6
0
def _patch_change_log_event(old_patch, new_patch):
    # If state changed, log the event
    event_state_change = Event.objects.get(name='patch-state-change')
    curr_user = threadlocalrequest.get_current_user()
    previous_state = str(old_patch.state)
    new_state = str(new_patch.state)

    # Do not log patch-state-change events for Patches that are not part of a
    # Series (ie patches older than the introduction of Series)
    series = find_series_for_patch(old_patch)
    if series:
        log = EventLog(event=event_state_change,
                       user=curr_user,
                       series_id=series.id,
                       patch=old_patch,
                       parameters={'previous_state': previous_state,
                                   'new_state': new_state,
                                  })
        log.save()