# Path: groundstation/objects/update_object.py
# class UpdateObject(base_object.BaseObject):
#     data_members = ["parents", "data"]
# 
#     def __init__(self, parents, data):
#         self.parents = parents
#         self.data = data
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.ParseFromString(obj)
#         return UpdateObject(protobuf.parents, protobuf.data)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.parents.extend(self.parents)
#         protobuf.data = self.data
#         return protobuf.SerializeToString()
# 
# Path: groundstation/objects/root_object.py
# class RootObject(base_object.BaseObject):
#     data_members = ["id", "channel", "protocol"]
# 
#     def __init__(self, id, channel, protocol):
#         self.id = id
#         self.channel = channel
#         self.protocol = protocol
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = root_object_pb2.RootObject()
#         protobuf.ParseFromString(obj)
#         return RootObject(protobuf.id, protobuf.channel, protobuf.protocol)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = root_object_pb2.RootObject()
#         for member in self.data_members:
#             setattr(protobuf, member, getattr(self, member))
#         return protobuf.SerializeToString()
# 
#     def as_json(self):
#         return {
#                 "id": self.id,
#                 "channel": self.channel,
#                 "protocol": self.protocol
#                 }


import os
import groundstation.objects.object_factory as object_factory
import logger
from collections import namedtuple
from groundstation.objects.update_object import UpdateObject
from groundstation.objects.root_object import RootObject
    def tip_path(self, tip):
        return os.path.join(self.node_path(), tip)

    def __iter__(self):
        return os.listdir(self.node_path()).__iter__()

    def get_signature(self, tip):
        try:
            with open(self.tip_path(tip), 'r') as fh:
                data = fh.read()
                if not data:
                    return ""
                return (int(data),)
        except IOError:
            return ""

    def remove_tip(self, tip, silent=False):
        try:
            os.unlink(os.path.join(self.tip_path(tip)))
        except:
            if not silent:
                raise

    def direct_parents(self, tip):
        """Return all parents of `tip` in the order they're written into the
        object"""
        obj = object_factory.hydrate_object(self.store[tip].data)
        if isinstance(obj, RootObject):
            # Roots can't have parents
            return []

# Path: groundstation/objects/update_object.py
# class UpdateObject(base_object.BaseObject):
#     data_members = ["parents", "data"]
# 
#     def __init__(self, parents, data):
#         self.parents = parents
#         self.data = data
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.ParseFromString(obj)
#         return UpdateObject(protobuf.parents, protobuf.data)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.parents.extend(self.parents)
#         protobuf.data = self.data
#         return protobuf.SerializeToString()
# 
# Path: groundstation/objects/root_object.py
# class RootObject(base_object.BaseObject):
#     data_members = ["id", "channel", "protocol"]
# 
#     def __init__(self, id, channel, protocol):
#         self.id = id
#         self.channel = channel
#         self.protocol = protocol
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = root_object_pb2.RootObject()
#         protobuf.ParseFromString(obj)
#         return RootObject(protobuf.id, protobuf.channel, protobuf.protocol)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = root_object_pb2.RootObject()
#         for member in self.data_members:
#             setattr(protobuf, member, getattr(self, member))
#         return protobuf.SerializeToString()
# 
#     def as_json(self):
#         return {
#                 "id": self.id,
#                 "channel": self.channel,
#                 "protocol": self.protocol
#                 }


# Path: groundstation/gref.py
import os
import groundstation.objects.object_factory as object_factory
import logger
from collections import namedtuple
from groundstation.objects.update_object import UpdateObject
from groundstation.objects.root_object import RootObject

    def tip_path(self, tip):
        return os.path.join(self.node_path(), tip)

    def __iter__(self):
        return os.listdir(self.node_path()).__iter__()

    def get_signature(self, tip):
        try:
            with open(self.tip_path(tip), 'r') as fh:
                data = fh.read()
                if not data:
                    return ""
                return (int(data),)
        except IOError:
            return ""

    def remove_tip(self, tip, silent=False):
        try:
            os.unlink(os.path.join(self.tip_path(tip)))
        except:
            if not silent:
                raise

    def direct_parents(self, tip):
        """Return all parents of `tip` in the order they're written into the
        object"""
        obj = object_factory.hydrate_object(self.store[tip].data)
        if isinstance(obj, RootObject):
            # Roots can't have parents
            return []

        elif isinstance(obj, UpdateObject):