Exemplo n.º 1
0
    def __init__(self, commit_obj=None, ctx=None, meta=None):
        """
        @param commit_obj: serializable blob

        @return: old_head, new_head, new_head.hash_value
        """
        super(DBO_block_chain__commit, self).__init__()

        blob = RZCommit.blob_from_diff_obj(commit_obj)
        hash_value = self.calc_blob_hash(blob)

        l_id = generate_random_id__uuid()

        q_arr = [
            'match (old_head:%s:%s)' % (neo4j_schema.META_LABEL__VC_HEAD,
                                        neo4j_schema.META_LABEL__VC_COMMIT),
            'create (new_head:%s:%s {commit_attr})' %
            (neo4j_schema.META_LABEL__VC_HEAD,
             neo4j_schema.META_LABEL__VC_COMMIT),
            'create (new_head)-[r:%s {link_attr}]->(old_head)' %
            (neo4j_schema.META_LABEL__VC_PARENT),
            'remove old_head:%s' % (neo4j_schema.META_LABEL__VC_HEAD),
            'set new_head.ts_created=timestamp()',
            'return {head_parent_commit: old_head, head_commit: new_head, ts_created: new_head.ts_created}'
        ]

        q_param_set = {
            'commit_attr': {
                'blob': blob,
                'hash': hash_value,
                'id': hash_value
            },
            'link_attr': {
                'id': l_id
            },
        }

        self.add_statement(q_arr, q_param_set)

        # cache values necessary to generate op result
        self.commit_obj = commit_obj
        self.n_id = hash_value
        self.l_id = l_id

        # create commit-[:__Authored-by]->__User link if possible
        if None != ctx and None != ctx.user_name:
            self.add_statement(self._add_statement__authored_by(ctx.user_name))

        if None != meta and 'sentence' in meta and meta['sentence'] != '':
            result_of_param_set = {
                'result_of_attr': {
                    'sentence': meta['sentence']
                }
            }
            self.add_statement(
                self._add_statement__result_of_sentence(ctx.user_name),
                result_of_param_set)
Exemplo n.º 2
0
    def __init__(self, commit_obj=None, ctx=None, meta=None):
        """
        @param commit_obj: serializable blob

        @return: old_head, new_head, new_head.hash_value
        """
        super(DBO_block_chain__commit, self).__init__()

        blob = RZCommit.blob_from_diff_obj(commit_obj)
        hash_value = self.calc_blob_hash(blob)

        l_id = generate_random_id__uuid()

        q_arr = ['match (old_head:%s:%s)' % (neo4j_schema.META_LABEL__VC_HEAD,
                                             neo4j_schema.META_LABEL__VC_COMMIT),
                 'create (new_head:%s:%s {commit_attr})' % (neo4j_schema.META_LABEL__VC_HEAD,
                                                            neo4j_schema.META_LABEL__VC_COMMIT),
                 'create (new_head)-[r:%s {link_attr}]->(old_head)' % (neo4j_schema.META_LABEL__VC_PARENT),
                 'remove old_head:%s' % (neo4j_schema.META_LABEL__VC_HEAD),
                 'set new_head.ts_created=timestamp()',
                 'return {head_parent_commit: old_head, head_commit: new_head, ts_created: new_head.ts_created}'
                 ]

        q_param_set = {'commit_attr': {'blob': blob,
                                       'hash': hash_value,
                                       'id': hash_value},
                       'link_attr': {'id': l_id},
                       }

        self.add_statement(q_arr, q_param_set)

        # cache values necessary to generate op result
        self.commit_obj = commit_obj
        self.n_id = hash_value
        self.l_id = l_id

        # create commit-[:__Authored-by]->__User link if possible
        if None != ctx and None != ctx.user_name:
            self.add_statement(self._add_statement__authored_by(ctx.user_name))

        if None != meta and 'sentence' in meta and meta['sentence'] != '':
            result_of_param_set = {'result_of_attr': {'sentence': meta['sentence']}}
            self.add_statement(self._add_statement__result_of_sentence(ctx.user_name),
                               result_of_param_set)
Exemplo n.º 3
0
 def process_result_set(self):
     ret = []
     # break out the blobs, return them - binary all the way home
     for _, _, r_set in self.iter__r_set():
         for row in r_set:
             pairs = row.items()[0]  # see query return statement
             for commit, operation, user_node_attrs in pairs:
                 if commit['blob'] == '':
                     # root commit, done
                     break
                 diff = RZCommit.diff_obj_from_blob(commit['blob'])
                 user_name = self._lookup_user_name(user_node_attrs['user_name'] if user_node_attrs else None)
                 diff['meta'] = dict(ts_created=commit['ts_created'],
                                     author=user_name,
                                     commit=commit['hash'],
                                     )
                 if None is not operation and 'sentence' in operation:
                     diff['meta']['sentence'] = operation['sentence']
                 ret.append(diff)
     return ret
Exemplo n.º 4
0
 def process_result_set(self):
     ret = []
     # break out the blobs, return them - binary all the way home
     for _, _, r_set in self.iter__r_set():
         for row in r_set:
             pairs = row.items()[0]  # see query return statement
             for commit, operation, user_node_attrs in pairs:
                 if commit['blob'] == '':
                     # root commit, done
                     break
                 diff = RZCommit.diff_obj_from_blob(commit['blob'])
                 user_name = self._lookup_user_name(
                     user_node_attrs['user_name']
                     if user_node_attrs else None)
                 diff['meta'] = dict(
                     ts_created=commit['ts_created'],
                     author=user_name,
                     commit=commit['hash'],
                 )
                 if None is not operation and 'sentence' in operation:
                     diff['meta']['sentence'] = operation['sentence']
                 ret.append(diff)
     return ret