def deserialize(data):
     '''From dictionary to object FinderResult'''
     ret = FinderResult()
     if data == None:
         return ret
     ret.unresolved = SetDeserializer(Declaration).deserialize(data[FinderResult.SERIAL_UNRESOLVED_KEY])
     ret.resolved = ReferencedDependencies.deserialize(data[FinderResult.SERIAL_RESOLVED_KEY])
     ret.updated = ReferencedDependencies.deserialize(data[FinderResult.SERIAL_UPDATED_KEY])
     return ret
示例#2
0
 def deserialize(data):
     '''From dictionary to object FinderResult'''
     ret = FinderResult()
     if data == None:
         return ret
     ret.unresolved = SetDeserializer(Declaration).deserialize(
         data[FinderResult.SERIAL_UNRESOLVED_KEY])
     ret.resolved = ReferencedDependencies.deserialize(
         data[FinderResult.SERIAL_RESOLVED_KEY])
     ret.updated = ReferencedDependencies.deserialize(
         data[FinderResult.SERIAL_UPDATED_KEY])
     return ret
示例#3
0
 def build_update_request(self, block_version, block_cell_name):
     request = FinderRequest()
     existing = ReferencedDependencies()
     existing[block_version][CPPDeclaration(block_cell_name)].add(
         block_cell_name)
     request.existing = existing
     request.policy = Policy.default()
     request.find = False
     request.update = True
     return request
示例#4
0
 def __init__(self, policy=None):
     self.unresolved = set()  # Unresolved declarations to be found
     self.block_names = set()  # Current hive src blocks, to forbid cycles
     self.existing = ReferencedDependencies()  # Current resolved deps
     self.existing_common_table = BlockVersionTable()
     self.policy = policy
     self.find = True  # To find for UNRESOLVED
     self.update = False  # To activate UPDATES
     self.downgrade = False  # To activate DOWNGRADES
     self.modify = False  # Allow changing deps to non-descendant branches
示例#5
0
 def deserialize(data):
     '''From dictionary to object FinderRequest'''
     ret = FinderRequest()
     ret.block_names = SetDeserializer(BlockName).deserialize(data[FinderRequest.SERIAL_TRACKING_KEY])
     ret.existing = ReferencedDependencies.deserialize(data[FinderRequest.SERIAL_EXISTING_KEY])
     ret.unresolved = SetDeserializer(Declaration).deserialize(data[FinderRequest.SERIAL_UNRESOLVED_KEY])
     ret.policy = Policy.deserialize(data[FinderRequest.SERIAL_POLICY])
     criteria = data[FinderRequest.SERIAL_CRITERIA]
     ret.find, ret.update, ret.downgrade, ret.modify = criteria
     ret.existing_common_table = BlockVersionTable.deserialize(data[FinderRequest.SERIAL_DEP_COMMON_TABLE])
     return ret
示例#6
0
    def check_result(self,
                     result,
                     resolved=None,
                     unresolved=None,
                     updated=None):
        unresolved = unresolved or []
        unresolved = {CPPDeclaration(str(u)) for u in unresolved}
        self.assertEqual(result.unresolved, unresolved)

        resolved = resolved or []
        refs = ReferencedDependencies()
        for brl, time, block_cell_names in resolved:
            for name in block_cell_names:
                refs[BlockVersion(
                    brl, time)][CPPDeclaration(name)] = {BlockCellName(name)}
        self.assertEqual(result.resolved, refs)

        updated = updated or []
        refs = ReferencedDependencies()
        for brl, time, block_cell_names in updated:
            for name in block_cell_names:
                refs[BlockVersion(
                    brl, time)][CPPDeclaration(name)] = {BlockCellName(name)}
        self.assertEqual(result.updated, refs)
示例#7
0
    def test_fiunder_request_existing(self):
        f = FinderRequest()
        self.assertFalse(f)
        existing = ReferencedDependencies()
        version = BlockVersion('user/user/block/master', 1)
        existing[version][CPPDeclaration("file.h")].add(CellName("file.h"))
        f.existing = existing
        f.update = True
        f.policy = Policy.default()
        #print f
        s = f.serialize()
        #print s
        f2 = FinderRequest.deserialize(s)

        self.assertEquals(f, f2)
        self.assertTrue(f2)
示例#8
0
 def external_dependencies(self):
     result = ReferencedDependencies()
     blocks = self.blocks
     for block_holder in self.block_holders:
         dep_table = block_holder.requirements
         for block_name, version in dep_table.iteritems():
             if block_name not in blocks:
                 result[version]  # defaultdict will create empty item
         for resource in block_holder.simple_resources:
             cell = resource.cell
             for declaration in cell.dependencies.resolved:
                 targets = declaration.match(cell.dependencies.explicit)
                 if targets:
                     block = declaration.block()
                     if block not in blocks:
                         block_version = dep_table[block]
                         result[block_version][declaration].update(targets)
     return result
示例#9
0
    def test_apply_result(self):
        # TODO: this is actually a test of find result, move away
        files = {
            self.block_name + 'main.cpp': '#include "user2/block/sphere.h"'
        }
        self.hive_manager.process(None, files)

        find_result = FinderResult()
        version = BRLBlock('user2/user2/block/branch') + 3
        d = ReferencedDependencies()
        decl = CPPDeclaration('user2/block/sphere.h')
        d[version][decl].add(BlockCellName('user2/block/sphere.h'))
        find_result.resolved = d

        hive_holder = self.hive_manager.hive_holder
        update_hive_with_find_result(hive_holder, find_result)

        self.assertEqual(2, len(hive_holder.resources))
        self.assertEqual(BlockVersionTable([version]),
                         hive_holder[self.block_name].requirements)
示例#10
0
class FinderResult(object):

    SERIAL_RESOLVED_KEY = "r"
    SERIAL_UNRESOLVED_KEY = "u"
    SERIAL_UPDATED_KEY = "a"
    SERIAL_RESPONSE_KEY = "f"

    def __init__(self):
        self.resolved = ReferencedDependencies()
        self.unresolved = set()
        self.updated = ReferencedDependencies()

    def __repr__(self):
        builder = ['FindResult']
        if self.resolved:
            builder.append('Resolved %s' % self.resolved)
        if self.unresolved:
            builder.append('UnResolved %s' % self.unresolved)
        if self.updated:
            builder.append("Updated: %s\n" % self.updated)
        return '\n'.join(builder)

    def __len__(self):
        return len(self.resolved) + len(self.updated)

    @staticmethod
    def deserialize(data):
        '''From dictionary to object FinderResult'''
        ret = FinderResult()
        if data == None:
            return ret
        ret.unresolved = SetDeserializer(Declaration).deserialize(
            data[FinderResult.SERIAL_UNRESOLVED_KEY])
        ret.resolved = ReferencedDependencies.deserialize(
            data[FinderResult.SERIAL_RESOLVED_KEY])
        ret.updated = ReferencedDependencies.deserialize(
            data[FinderResult.SERIAL_UPDATED_KEY])
        return ret

    def serialize(self):
        return Serializer().build(
            (FinderResult.SERIAL_UNRESOLVED_KEY, self.unresolved),
            (FinderResult.SERIAL_RESOLVED_KEY, self.resolved),
            (FinderResult.SERIAL_UPDATED_KEY, self.updated))

    def __eq__(self, other):
        if self is other:
            return True
        return isinstance(other, self.__class__) \
            and (other.resolved == self.resolved) \
            and (other.unresolved == self.unresolved) \
            and (other.updated == self.updated)

    def __ne__(self, other):
        return not self == other

    @property
    def update_renames(self):
        renames = {}
        for dep_dict in self.updated.itervalues():
            for declaration, block_cell_names in dep_dict.iteritems():
                if not '*' in declaration.name:
                    #TODO: What to do with python multiple imports
                    new_declaration = declaration.normalize(block_cell_names)
                    if new_declaration:
                        v = [
                            v for v in block_cell_names
                            if '__init__.py' not in v
                        ]
                        if len(v) == 1:
                            renames[declaration] = new_declaration
        return renames
示例#11
0
 def __init__(self):
     self.resolved = ReferencedDependencies()
     self.unresolved = set()
     self.updated = ReferencedDependencies()
示例#12
0
class FinderResult(object):

    SERIAL_RESOLVED_KEY = "r"
    SERIAL_UNRESOLVED_KEY = "u"
    SERIAL_UPDATED_KEY = "a"
    SERIAL_RESPONSE_KEY = "f"

    def __init__(self):
        self.resolved = ReferencedDependencies()
        self.unresolved = set()
        self.updated = ReferencedDependencies()

    def __repr__(self):
        builder = ['FindResult']
        if self.resolved:
            builder.append('Resolved %s' % self.resolved)
        if self.unresolved:
            builder.append('UnResolved %s' % self.unresolved)
        if self.updated:
            builder.append("Updated: %s\n" % self.updated)
        return '\n'.join(builder)

    def __len__(self):
        return len(self.resolved) + len(self.updated)

    @staticmethod
    def deserialize(data):
        '''From dictionary to object FinderResult'''
        ret = FinderResult()
        if data == None:
            return ret
        ret.unresolved = SetDeserializer(Declaration).deserialize(data[FinderResult.SERIAL_UNRESOLVED_KEY])
        ret.resolved = ReferencedDependencies.deserialize(data[FinderResult.SERIAL_RESOLVED_KEY])
        ret.updated = ReferencedDependencies.deserialize(data[FinderResult.SERIAL_UPDATED_KEY])
        return ret

    def serialize(self):
        return  Serializer().build((FinderResult.SERIAL_UNRESOLVED_KEY, self.unresolved),
                                 (FinderResult.SERIAL_RESOLVED_KEY, self.resolved),
                                 (FinderResult.SERIAL_UPDATED_KEY, self.updated))

    def __eq__(self, other):
        if self is other:
            return True
        return isinstance(other, self.__class__) \
            and (other.resolved == self.resolved) \
            and (other.unresolved == self.unresolved) \
            and (other.updated == self.updated)

    def __ne__(self, other):
        return not self == other

    @property
    def update_renames(self):
        renames = {}
        for dep_dict in self.updated.itervalues():
            for declaration, block_cell_names in dep_dict.iteritems():
                if not '*' in declaration.name:
                    #TODO: What to do with python multiple imports
                    new_declaration = declaration.normalize(block_cell_names)
                    if new_declaration:
                        v = [v for v in block_cell_names if '__init__.py' not in v]
                        if len(v) == 1:
                            renames[declaration] = new_declaration
        return renames
示例#13
0
 def __init__(self):
     self.resolved = ReferencedDependencies()
     self.unresolved = set()
     self.updated = ReferencedDependencies()