Changeset 238529 in webkit


Ignore:
Timestamp:
Nov 26, 2018 4:21:37 PM (5 years ago)
Author:
aakash_jain@apple.com
Message:

[ews-app] Add methods to save patch to database
https://bugs.webkit.org/show_bug.cgi?id=191928

Reviewed by Lucas Forschler.

  • BuildSlaveSupport/ews-app/ews/models/patch.py:

(Patch.save_patch): Method to save the patch to database.
(Patch.save_patches): Method to save multiple patches to database.
(Patch.is_valid_patch_id): Checks if the patch id is valid.
(Patch.is_existing_patch_id): Checks if the patch id already exists in database.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/models/patch.py

    r238517 r238529  
    2323from __future__ import unicode_literals
    2424
     25import logging
     26
    2527from django.db import models
     28
     29from ews.config import *
     30
     31_log = logging.getLogger(__name__)
    2632
    2733
    2834class Patch(models.Model):
    29     patchid = models.IntegerField(primary_key=True)
    30     bugid = models.IntegerField()
     35    patch_id = models.IntegerField(primary_key=True)
     36    bug_id = models.IntegerField()
    3137    obsolete = models.BooleanField(default=False)
    3238    created = models.DateTimeField(auto_now_add=True)
     
    3440
    3541    def __str__(self):
    36         return str(self.patchid)
     42        return str(self.patch_id)
     43
     44    @classmethod
     45    def save_patch(cls, patch_id, bug_id=-1, obsolete=False):
     46        if not Patch.is_valid_patch_id(patch_id):
     47            return ERR_INVALID_PATCH_ID
     48
     49        if Patch.is_existing_patch_id(patch_id):
     50            _log.info("Patch id {} already exists in database. Skipped saving.".format(patch_id))
     51            return ERR_EXISTING_PATCH
     52        Patch(patch_id, bug_id, obsolete).save()
     53        _log.info('Saved patch in database, id: {}'.format(patch_id))
     54        return SUCCESS
     55
     56    @classmethod
     57    def save_patches(cls, patch_id_list):
     58        for patch_id in patch_id_list:
     59            Patch.save_patch(patch_id)
     60
     61    @classmethod
     62    def is_valid_patch_id(cls, patch_id):
     63        if not patch_id or type(patch_id) != int or patch_id < 1:
     64            _log.warn('Invalid patch id: {}'.format(patch_id))
     65            return False
     66        return True
     67
     68    @classmethod
     69    def is_existing_patch_id(cls, patch_id):
     70        return bool(Patch.objects.filter(patch_id=patch_id))
  • trunk/Tools/ChangeLog

    r238527 r238529  
     12018-11-26  Aakash Jain  <aakash_jain@apple.com>
     2
     3        [ews-app] Add methods to save patch to database
     4        https://bugs.webkit.org/show_bug.cgi?id=191928
     5
     6        Reviewed by Lucas Forschler.
     7
     8        * BuildSlaveSupport/ews-app/ews/models/patch.py:
     9        (Patch.save_patch): Method to save the patch to database.
     10        (Patch.save_patches): Method to save multiple patches to database.
     11        (Patch.is_valid_patch_id): Checks if the patch id is valid.
     12        (Patch.is_existing_patch_id): Checks if the patch id already exists in database.
     13
    1142018-11-26  Alex Christensen  <achristensen@webkit.org>
    215
Note: See TracChangeset for help on using the changeset viewer.