def handle_describechannels_for_missing_tip(self):
        test_id = u"tests/1"
        test_channel = u"test_channel"
        test_protocol = u"test_protocol"

        gref = Gref(self.station.station.store, test_channel, test_id)

        root_obj = RootObject(test_id, test_channel, test_protocol)
        root_oid = self.station.station.write(root_obj.as_object())
        current_oid = [root_oid]

        for i in xrange(10):
            update_obj = UpdateObject([current_oid.pop()], "loldata")
            current_oid.append(self.station.station.write(update_obj.as_object()))

        update_obj = UpdateObject([current_oid.pop()], "loldata")
        current_oid.append(binascii.hexlify(pygit2.hash(update_obj.as_object())))

        self.station.station.update_gref(gref, [root_oid])
        self.assertEqual([root_oid], gref.tips())
        current_oid = current_oid.pop()

        self.station.payload = _payload(update_obj, gref, [current_oid])
        handle_describechannels(self.station)
        self.assertEqual([current_oid], gref.tips())
Ejemplo n.º 2
0
 def test_hydate_update_with_2_parent(self):
     update = UpdateObject([
         "d41e2dadaf624319518a9dfa8ef4cb0dde055b5c",
         "d41e2dadaf624319518a9dfa8ef4cb0dde055bff"
     ], "Lol I r update data")
     hydrated_update = object_factory.hydrate_object(update.as_object())
     self.assertTrue(isinstance(hydrated_update, UpdateObject))
Ejemplo n.º 3
0
    def create_gref(channel):
        def _write_object(obj):
            return station.write(obj.as_object())

        name = request.form["name"]
        protocol = request.form["protocol"]
        user = request.form["user"]
        body = request.form["body"]
        title = request.form["title"]
        gref = Gref(station.store, channel, name)
        root = RootObject(name, channel, protocol)
        root_oid = _write_object(root)

        _title = UpdateObject([root_oid],
                              json.dumps({
                                  "type": "title",
                                  "id": None,
                                  "body": title,
                                  "user": user
                              }))
        title_oid = _write_object(_title)

        _body = UpdateObject([title_oid],
                             json.dumps({
                                 "type": "body",
                                 "id": None,
                                 "body": body
                             }))
        body_oid = _write_object(_body)

        _update_gref(gref, [Tip(body_oid, "")], [])
        return ""
Ejemplo n.º 4
0
 def test_hydate_update_with_1_parent(self):
     update = UpdateObject(
             ["d41e2dadaf624319518a9dfa8ef4cb0dde055b5c"],
             "Lol I r update data"
         )
     hydrated_update = object_factory.hydrate_object(update.as_object())
     self.assertTrue(isinstance(hydrated_update, UpdateObject))
Ejemplo n.º 5
0
def main():
    myself = Node()
    station = Station.from_env(myself)
    filename = sys.argv[1]
    log("Stealing %s" % filename)

    with open(filename) as fh:
        obj = UpdateObject([],
                           os.path.basename(filename) + chr(0x00) +
                           bz2.compress(fh.read()))
        name = station.write(obj.as_object())
        log("Wrote %s into stationdb" % name)
Ejemplo n.º 6
0
 def update_gref(channel, identifier):
     # adaptor = github_protocol.GithubWriteAdaptor(station, channel)
     gref = Gref(station.store, channel, identifier)
     # Ugly type coercion
     user = request.form["user"]
     body = request.form["body"]
     parents = map(str, json.loads(request.form["parents"]))
     payload = {"type": "comment", "id": None, "body": body, "user": user}
     update_object = UpdateObject(parents, json.dumps(payload))
     oid = station.write(update_object.as_object())
     _update_gref(gref, [Tip(oid, "")], parents)
     return jsonate({"response": "ok"}, False)
Ejemplo n.º 7
0
def main():
    myself = Node()
    station = Station.from_env(myself)
    filename = sys.argv[1]
    log("Stealing %s" % filename)

    with open(filename) as fh:
        obj = UpdateObject([],
            os.path.basename(filename) +
            chr(0x00) +
            bz2.compress(fh.read())
            )
        name = station.write(obj.as_object())
        log("Wrote %s into stationdb" % name)
Ejemplo n.º 8
0
def hydrate_object(protobuf):
    # Test if it's strongly typed first
    _type = type_of(protobuf)
    if _type == TYPE_ROOT:
        return RootObject.from_object(protobuf)
    elif _type == TYPE_UPDATE:
        return UpdateObject.from_object(protobuf)
    elif _type == TYPE_UNSET:
        # Use existing heuristic
        obj = RootObject.from_object(protobuf)
        if not obj.protocol:
            obj = UpdateObject.from_object(protobuf)
        return obj
    else:
        raise Exception("Unknown type; %s" % (str(_type)))
Ejemplo n.º 9
0
 def update_gref(channel, identifier):
     # adaptor = github_protocol.GithubWriteAdaptor(station, channel)
     gref = Gref(station.store, channel, identifier)
     # Ugly type coercion
     user = request.form["user"]
     body = request.form["body"]
     parents = map(str, json.loads(request.form["parents"]))
     payload = {
             "type": "comment",
             "id": None,
             "body": body,
             "user": user
             }
     update_object = UpdateObject(parents, json.dumps(payload))
     oid = station.write(update_object.as_object())
     _update_gref(gref, [Tip(oid,"")], parents)
     return jsonate({"response": "ok"}, False)
Ejemplo n.º 10
0
    def test_handle_describechannels(self):
        test_id = u"tests/1"
        test_channel = u"test_channel"
        test_protocol = u"test_protocol"

        gref = Gref(self.station.station.store, test_channel, test_id)

        root_obj = RootObject(test_id, test_channel, test_protocol)
        root_oid = self.station.station.write(root_obj.as_object())
        current_oid = [root_oid]

        for i in xrange(10):
            update_obj = UpdateObject([current_oid.pop()], "loldata")
            current_oid.append(self.station.station.write(update_obj.as_object()))
        self.station.station.update_gref(gref, [Tip(root_oid, "")])
        self.assertEqual([root_oid], gref.tips())
        current_oid = current_oid.pop()

        self.station.payload = _payload(update_obj, gref, [current_oid])
        handle_describechannels(self.station)
        self.assertEqual([current_oid], gref.tips())
Ejemplo n.º 11
0
def main():
    myself = Node()
    station = Station.from_env(myself)

    for obj in station.objects():
        try:
            data = station[obj]
            o = UpdateObject.from_object(data.read_raw())
            filename, body = o.data.split(chr(0x00), 1)
            log("%s: %s" % (obj, filename))
            print(bz2.decompress(body))
        except Exception as e:
            log("Failed to decode %s: %s" % map(repr, (obj, e)))
Ejemplo n.º 12
0
def main():
    myself = Node()
    station = Station.from_env(myself)

    for obj in station.objects():
        try:
            data = station[obj]
            o = UpdateObject.from_object(data.read_raw())
            filename, body = o.data.split(chr(0x00), 1)
            log("%s: %s" % (obj, filename))
            print(bz2.decompress(body))
        except Exception as e:
            log("Failed to decode %s: %s" % map(repr, (obj, e)))
Ejemplo n.º 13
0
    def write_issue(self, issue):
        parents = []
        issue_id = self._issue_id(issue)
        gref = self.issue_gref(issue)

        def _write_new_tip(obj):
            our_parents = []
            while parents:
                our_parents.append(parents.pop())
            log.debug("Creating new object with parents: %s" %
                      (str(our_parents)))

            oid = self.station.write(obj.as_object())
            self.station.update_gref(gref, [Tip(oid, "")], our_parents)
            parents.append(oid)
            log.debug("Setting parents to: %s" % (str(parents)))

        def _parents():
            return copy.copy(parents)

        if gref.exists():
            log.info("Not creating any objects, a gref already exists at: %s" %
                     str(gref))
            return False

        log.info(("Creating a new root_object with:\n" + "id: %s\n" +
                  "channel: %s\n" + "protocol: %s") %
                 (issue_id, self.channel, self.protocol))

        root_object = RootObject(issue_id, self.channel, self.protocol)
        _write_new_tip(root_object)

        # Write out the initial state
        # Creating lots of tiny objects should make deduping easier later
        if issue.fields.reporter:
            reporter = issue.fields.reporter.name
        else:
            reporter = "Anonymous"
        title_payload = {
            "type": "title",
            "id": None,
            "body": issue.fields.summary,
            "user": reporter
        }
        update_object = UpdateObject(_parents(), json.dumps(title_payload))
        _write_new_tip(update_object)

        # Write out the body of the issue
        body_payload = {
            "type": "body",
            "id": None,
            "body": issue.fields.description
        }
        update_object = UpdateObject(_parents(), json.dumps(body_payload))
        _write_new_tip(update_object)

        everything = []
        for comment in issue.fields.comment.comments:
            comment.type = "comment"
            everything.append(comment)
        for history in issue.changelog.histories:
            history.type = "event"
            everything.append(history)
        everything.sort(key=lambda x: x.created)
        for item in everything:
            if item.type == "comment":
                payload = {
                    "type": "comment",
                    "id": int(item.id),
                    "body": item.body,
                    "user": item.author.name
                }
            elif item.type == "event":
                stateChange = ", ".join([
                    "%s from %s to %s" % (x.field, x.fromString, x.toString)
                    for x in item.items
                ])
                payload = {
                    "type": "event",
                    "id": item.id,
                    "state": stateChange,
                    "user": item.author.name
                }
            else:
                raise Exception("Unhandled type")

            update_object = UpdateObject(_parents(), json.dumps(payload))
            _write_new_tip(update_object)
Ejemplo n.º 14
0
    def write_issue(self, issue):
        # Stupid implementation, blindly write with no deduping or merge
        # resolution.
        parents = []
        issue_id = self._issue_id(issue.number)
        gref = self.issue_gref(issue.number)

        def _write_new_tip(obj):
            our_parents = []
            while parents:
                our_parents.append(parents.pop())
            log.debug("Creating new object with parents: %s" %
                      (str(our_parents)))

            oid = self.station.write(obj.as_object())
            self.station.update_gref(gref, [Tip(oid, "")], our_parents)
            parents.append(oid)
            log.debug("Setting parents to: %s" % (str(parents)))

        def _parents():
            return copy.copy(parents)

        # Bail out if we've already written:
        if gref.exists():
            log.info("Not creating any objects, a gref already exists at: %s" %
                     str(gref))
            return False

        # Write out a root object
        log.info(("Creating a new root_object with:\n" + "id: %s\n" +
                  "channel: %s\n" + "protocol: %s") %
                 (issue_id, self.channel, self.protocol))

        root_object = RootObject(issue_id, self.channel, self.protocol)
        _write_new_tip(root_object)

        # Write out the initial state
        # Creating lots of tiny objects should make deduping easier later
        title_payload = {
            "type": "title",
            "id": None,
            "body": issue.title,
            "user": issue.user.login
        }
        update_object = UpdateObject(_parents(), json.dumps(title_payload))
        _write_new_tip(update_object)

        # Write out the body of the issue
        body_payload = {"type": "body", "id": None, "body": issue.body}
        update_object = UpdateObject(_parents(), json.dumps(body_payload))
        _write_new_tip(update_object)

        # Write out all of the comments and events
        everything = []
        everything.extend(issue.get_comments())
        everything.extend(issue.get_events())
        everything.sort(key=lambda x: x.created_at)
        for item in everything:
            if isinstance(item, github.IssueComment.IssueComment):
                payload = {
                    "type": "comment",
                    "id": item.id,
                    "body": item.body,
                    "user": item.user.login
                }
            elif isinstance(item, github.IssueEvent.IssueEvent):
                payload = {
                    "type": "event",
                    "id": item.id,
                    "state": item.event,
                    "user": item.actor.login
                }
            else:
                raise Exception("Unhandled item %s" % (repr(item)))

            update_object = UpdateObject(_parents(), json.dumps(payload))
            _write_new_tip(update_object)
Ejemplo n.º 15
0
def hydrate_object(protobuf):
    obj = RootObject.from_object(protobuf)
    if not obj.protocol:
        obj = UpdateObject.from_object(protobuf)
    return obj
Ejemplo n.º 16
0
# Creates a thread in the current groundstation context

import uuid

import stricken

from groundstation.node import Node
from groundstation.station import Station
from groundstation.objects.root_object import RootObject
from groundstation.objects.update_object import UpdateObject
from groundstation.gref import Gref

node = Node()
station = Station.from_env(node)

CHANNEL = "messages"

thread_id = str(uuid.uuid1())
gref = Gref(station.store, CHANNEL, thread_id)

root = RootObject(thread_id, CHANNEL, stricken.PROTOCOL)
oid = station.write(root.as_object())
print("Root id: %s" % (oid))

update = UpdateObject([oid], "Post content")
oid = station.write(update.as_object())
print("Update id: %s" % (oid))

gref.write_tip(oid, "")
Ejemplo n.º 17
0
 def create_update_object(self, parents, data):
     return UpdateObject(parents, data)
Ejemplo n.º 18
0
def update_object(data, parents=[]):
    return UpdateObject(parents, data)