Beispiel #1
0
  def NextPendingMerge(self, rpc_controller, req, done):

    patchsets = []
    while not patchsets:
      branch = gql(models.Branch,
                  "WHERE status = 'NEEDS_MERGE'"
                  " ORDER BY merge_submitted").get()
      if branch is None:
        break
      patchsets = branch.begin_merge()

    rsp = PendingMergeResponse()
    if patchsets:
      first = patchsets[0].change
      rsp.status_code = PendingMergeResponse.MERGE_READY
      rsp.dest_project_name = str(first.dest_project.name)
      rsp.dest_project_key = str(first.dest_project.key())
      rsp.dest_branch_name = str(first.dest_branch.name)
      rsp.dest_branch_key = str(first.dest_branch.key())
      for ps in patchsets:
        pmi = rsp.change.add()
        pmi.patchset_key = str(ps.key())
        pmi.revision_id = str(ps.revision.id)
    else:
      rsp.status_code = PendingMergeResponse.QUEUE_EMPTY
    done(rsp)
Beispiel #2
0
    def PruneBundles(self, rpc_controller, req, done):
        rsp = PruneBundlesResponse()

        rb_list = []
        to_rm = []

        for m in [
                _AgedUploading,
                _AgedInvalid,
                _AgedSuspended,
                _AgedUnpacking,
                _AgedUnpacked,
        ]:
            rb_list.extend(m())
            if len(rb_list) >= MAX_PRUNE:
                break

        for rb in rb_list:
            segs = gql(ReceivedBundleSegment, 'WHERE ANCESTOR IS :1',
                       rb).fetch(MAX_SEGS_PER_PRUNE)
            if len(segs) < MAX_SEGS_PER_PRUNE:
                to_rm.append(rb)
            to_rm.extend(segs)

        if to_rm:
            db.delete(to_rm)
            rsp.status_code = PruneBundlesResponse.BUNDLES_PRUNED
        else:
            rsp.status_code = PruneBundlesResponse.QUEUE_EMPTY
        done(rsp)
  def PruneBundles(self, rpc_controller, req, done):
    rsp = PruneBundlesResponse()

    rb_list = []
    to_rm = []

    for m in [_AgedUploading,
              _AgedInvalid,
              _AgedSuspended,
              _AgedUnpacking,
              _AgedUnpacked,
              ]:
      rb_list.extend(m())
      if len(rb_list) >= MAX_PRUNE:
        break

    for rb in rb_list:
      segs = gql(ReceivedBundleSegment,
                'WHERE ANCESTOR IS :1',
                rb).fetch(MAX_SEGS_PER_PRUNE)
      if len(segs) < MAX_SEGS_PER_PRUNE:
        to_rm.append(rb)
      to_rm.extend(segs)

    if to_rm:
      db.delete(to_rm)
      rsp.status_code = PruneBundlesResponse.BUNDLES_PRUNED
    else:
      rsp.status_code = PruneBundlesResponse.QUEUE_EMPTY
    done(rsp)
Beispiel #4
0
    def NextPendingMerge(self, rpc_controller, req, done):

        patchsets = []
        while not patchsets:
            branch = gql(
                models.Branch, "WHERE status = 'NEEDS_MERGE'"
                " ORDER BY merge_submitted").get()
            if branch is None:
                break
            patchsets = branch.begin_merge()

        rsp = PendingMergeResponse()
        if patchsets:
            first = patchsets[0].change
            rsp.status_code = PendingMergeResponse.MERGE_READY
            rsp.dest_project_name = str(first.dest_project.name)
            rsp.dest_project_key = str(first.dest_project.key())
            rsp.dest_branch_name = str(first.dest_branch.name)
            rsp.dest_branch_key = str(first.dest_branch.key())
            for ps in patchsets:
                pmi = rsp.change.add()
                pmi.patchset_key = str(ps.key())
                pmi.revision_id = str(ps.revision.id)
        else:
            rsp.status_code = PendingMergeResponse.QUEUE_EMPTY
        done(rsp)
Beispiel #5
0
  def SyncProject(self, rpc_controller, req, done):
    rsp = SyncProjectResponse()

    proj = models.Project.get_project_for_name(req.project_name)
    if proj is None:
      proj = models.Project(name = req.project_name)
      proj.put()

    really_exists = set()
    for bs in req.branch:
      branch = models.Branch.get_or_insert_branch(proj, bs.branch_name)
      really_exists.add(branch.name)

    to_delete = []
    for b in list(gql(models.Branch, 'WHERE project = :1', proj)):
      if b.name not in really_exists:
        to_delete += gql(models.BuildAttempt, 'WHERE branch = :1', b)

    if to_delete:
      db.delete(to_delete)

    done(rsp)
Beispiel #6
0
def _AgedSuccess():
  aged = datetime.datetime.now() - datetime.timedelta(days=2)
  return gql(models.BuildAttempt,
             'WHERE success = :1 AND started <= :2',
             True, aged).fetch(MAX_PRUNE)
Beispiel #7
0
def _AgedFailed():
    aged = datetime.datetime.now() - datetime.timedelta(days=7)
    return gql(models.BuildAttempt, 'WHERE success = :1 AND started <= :2',
               False, aged).fetch(MAX_PRUNE)
def _AgedUnpacked():
  aged = datetime.datetime.now() - datetime.timedelta(hours=1)
  return gql(ReceivedBundle,
             'WHERE state = :1 AND created <= :2',
             ReceivedBundle.STATE_UNPACKED, aged).fetch(MAX_PRUNE)
def _AgedUnpacking():
  aged = datetime.datetime.now() - datetime.timedelta(days=7)
  return gql(ReceivedBundle,
             'WHERE state = :1 AND created <= :2',
             ReceivedBundle.STATE_UNPACKING, aged).fetch(MAX_PRUNE)
Beispiel #10
0
def _AgedSuspended():
  aged = datetime.datetime.now() - datetime.timedelta(days=7)
  return gql(ReceivedBundle,
             'WHERE state = :1 AND created <= :2',
             ReceivedBundle.STATE_SUSPENDED, aged).fetch(MAX_PRUNE)
Beispiel #11
0
def _AgedInvalid():
  aged = datetime.datetime.now() - datetime.timedelta(days=2)
  return gql(ReceivedBundle,
             'WHERE state = :1 AND created <= :2',
             ReceivedBundle.STATE_INVALID, aged).fetch(MAX_PRUNE)
Beispiel #12
0
def _AgedInvalid():
    aged = datetime.datetime.now() - datetime.timedelta(days=2)
    return gql(ReceivedBundle, 'WHERE state = :1 AND created <= :2',
               ReceivedBundle.STATE_INVALID, aged).fetch(MAX_PRUNE)
Beispiel #13
0
    def UploadPatchsetFile(self, rpc_controller, req, done):
        rsp = UploadPatchsetFileResponse()

        patchset = db.get(db.Key(req.patchset_key))
        if not patchset:
            rsp.status_code = UploadPatchsetFileResponse.UNKNOWN_PATCHSET
            done(rsp)
            return

        if patchset.complete or patchset.change.closed:
            rsp.status_code = UploadPatchsetFileResponse.CLOSED
            done(rsp)
            return

        if UploadPatchsetFileRequest.ADD == req.status:
            status = 'A'
        elif UploadPatchsetFileRequest.MODIFY == req.status:
            status = 'M'
        elif UploadPatchsetFileRequest.DELETE == req.status:
            status = 'D'
        else:
            status = '?'

        try:
            if req.base_id:
                old_data = models.DeltaContent.create_content(
                    id=req.base_id, text_z=req.base_z)
                new_data = models.DeltaContent.create_content(
                    id=req.final_id, text_z=req.patch_z, base=old_data)
                if new_data.text_z == req.patch_z:
                    diff_data = new_data
                else:
                    diff_data = models.DeltaContent.create_patch(
                        id=req.patch_id, text_z=req.patch_z)
            else:
                old_data = None
                new_data = None
                diff_data = models.DeltaContent.create_patch(
                    id=req.patch_id, text_z=req.patch_z)
        except models.DeltaPatchingException:
            logging.error("Patch error on change %s, patch set %s, file %s" %
                          (patchset.change.key().id(), str(
                              patchset.id), u(req.file_name)))
            rsp.status_code = UploadPatchsetFileResponse.PATCHING_ERROR
            done(rsp)
            return

        file_name = u(req.file_name)
        other_versions = []
        other_patches = []

        if patchset.id > 1:
            for ps in models.gql(models.PatchSet, 'WHERE change = :1'
                                 ' ORDER BY id', patchset.change).fetch(1000):
                if ps.id == patchset.id:
                    continue

                prior = models.Patch.get_patch_by_filename(ps, file_name)
                if prior and not prior.patch_equals(diff_data):
                    other_versions.append('%d %d %s' %
                                          (ps.key().id(), ps.id, prior.id))
                    other_patches.append(prior)

        patch = models.Patch.get_or_insert_patch(
            patchset=patchset,
            filename=file_name,
            status=status,
            multi_way_diff=req.multi_way_diff,
            n_comments=0,
            old_data=old_data,
            new_data=new_data,
            diff_data=diff_data,
            other_versions=other_versions)

        my_ovstr = '%d %d %s' % (patchset.key().id(), patchset.id, patch.id)

        def trans():
            for prior in other_patches:
                p = db.get(prior.key())
                p.other_versions.append(my_ovstr)
                p.put()

        db.run_in_transaction(trans)

        if old_data:
            models.CachedDeltaContent.get(old_data.key())
            models.CachedDeltaContent.get(new_data.key())
            if diff_data != new_data:
                models.CachedDeltaContent.get(diff_data.key())
        else:
            models.CachedDeltaContent.get(diff_data.key())

        rsp.status_code = UploadPatchsetFileResponse.CREATED
        done(rsp)
Beispiel #14
0
  def UploadPatchsetFile(self, rpc_controller, req, done):
    rsp = UploadPatchsetFileResponse()

    patchset = db.get(db.Key(req.patchset_key))
    if not patchset:
      rsp.status_code = UploadPatchsetFileResponse.UNKNOWN_PATCHSET
      done(rsp)
      return

    if patchset.complete or patchset.change.closed:
      rsp.status_code = UploadPatchsetFileResponse.CLOSED
      done(rsp)
      return

    if UploadPatchsetFileRequest.ADD == req.status:
      status = 'A'
    elif UploadPatchsetFileRequest.MODIFY == req.status:
      status = 'M'
    elif UploadPatchsetFileRequest.DELETE == req.status:
      status = 'D'
    else:
      status = '?'

    try:
      if req.base_id:
        old_data = models.DeltaContent.create_content(
                     id = req.base_id,
                     text_z = req.base_z)
        new_data = models.DeltaContent.create_content(
                     id = req.final_id,
                     text_z = req.patch_z,
                     base = old_data)
        if new_data.text_z == req.patch_z:
          diff_data = new_data
        else:
          diff_data = models.DeltaContent.create_patch(
                        id = req.patch_id,
                        text_z = req.patch_z)
      else:
        old_data = None
        new_data = None
        diff_data = models.DeltaContent.create_patch(
                      id = req.patch_id,
                      text_z = req.patch_z)
    except models.DeltaPatchingException:
      logging.error("Patch error on change %s, patch set %s, file %s"
        % (patchset.change.key().id(),
           str(patchset.id),
           u(req.file_name))
      )
      rsp.status_code = UploadPatchsetFileResponse.PATCHING_ERROR
      done(rsp)
      return

    file_name = u(req.file_name)
    other_versions = []
    other_patches = []

    if patchset.id > 1:
      for ps in models.gql(models.PatchSet,
                           'WHERE change = :1'
                           ' ORDER BY id',
                           patchset.change).fetch(1000):
        if ps.id == patchset.id:
          continue

        prior = models.Patch.get_patch_by_filename(ps, file_name)
        if prior and not prior.patch_equals(diff_data):
          other_versions.append('%d %d %s'
                                % (ps.key().id(), ps.id, prior.id))
          other_patches.append(prior)

    patch = models.Patch.get_or_insert_patch(
              patchset = patchset,
              filename = file_name,
              status = status,
              multi_way_diff = req.multi_way_diff,
              n_comments = 0,
              old_data = old_data,
              new_data = new_data,
              diff_data = diff_data,
              other_versions = other_versions)

    my_ovstr = '%d %d %s' % (patchset.key().id(),
                             patchset.id,
                             patch.id)
    def trans():
      for prior in other_patches:
        p = db.get(prior.key())
        p.other_versions.append(my_ovstr)
        p.put()
    db.run_in_transaction(trans)

    if old_data:
      models.CachedDeltaContent.get(old_data.key())
      models.CachedDeltaContent.get(new_data.key())
      if diff_data != new_data:
        models.CachedDeltaContent.get(diff_data.key())
    else:
      models.CachedDeltaContent.get(diff_data.key())

    rsp.status_code = UploadPatchsetFileResponse.CREATED
    done(rsp)
Beispiel #15
0
def _AgedUnpacked():
    aged = datetime.datetime.now() - datetime.timedelta(hours=1)
    return gql(ReceivedBundle, 'WHERE state = :1 AND created <= :2',
               ReceivedBundle.STATE_UNPACKED, aged).fetch(MAX_PRUNE)
Beispiel #16
0
def _AgedUnpacking():
    aged = datetime.datetime.now() - datetime.timedelta(days=7)
    return gql(ReceivedBundle, 'WHERE state = :1 AND created <= :2',
               ReceivedBundle.STATE_UNPACKING, aged).fetch(MAX_PRUNE)
Beispiel #17
0
def _AgedSuspended():
    aged = datetime.datetime.now() - datetime.timedelta(days=7)
    return gql(ReceivedBundle, 'WHERE state = :1 AND created <= :2',
               ReceivedBundle.STATE_SUSPENDED, aged).fetch(MAX_PRUNE)