def share(self, project_id, new_contributor):
     """Allow another person to contribute to your project."""
     msg = client.serialize("share", project_id, new_contributor)
     reply = self.__client.send(msg)
     if DEBUG:
         print(reply)
     return server.deserialize(reply)
 def unsubscribe(self, cookie):
     """Unsubscribe to updates to a project."""
     msg = client.serialize("unsubscribe", cookie)
     reply = self.__client.send(msg)
     if DEBUG:
         print(reply)
     return server.deserialize(reply)
 def register(self, uname, pword, email):
     """Attempt to register a new user's username password email."""
     msg = client.serialize("register", uname, pword, email)
     reply = self.__client.send(msg)
     if DEBUG:
         print(reply)
     return server.deserialize(reply)
 def login(self, uname, pword):
     """Attempt to login with a username and password."""
     msg = client.serialize("login", uname, pword)
     reply = self.__client.send(msg)
     # status, reason = reply
     if DEBUG:
         print(reply)
     return server.deserialize(reply)
示例#5
0
    def retrieve_project_listings_for(self, uname):
        """
        list-projects username

        Get a list of all projects this user is a collaborator on
        """
        msg = client.serialize("list_projects", uname)
        reply = self.__client.send(msg)
        return server.deserialize(reply)
 def subscribe(self, uname, project_id):
     """Subscribe to updates to a project."""
     msg = client.serialize("subscribe", uname, project_id)
     reply = self.__client.send(msg)
     # print(reply)
     j = json.loads(reply)
     if DEBUG:
         print(j[1][0])
     return server.deserialize(reply)
 def __version_handshake(self):
     """Perform a version handshake with the remote Composte server."""
     msg = client.serialize("handshake", misc.get_version())
     reply = self.__client.send(msg)
     if DEBUG:
         print(reply)
     reply = server.deserialize(reply)
     if reply[0] == "fail":
         status, reason = reply
         version = reason[0]
         raise GenericError(version)
示例#8
0
    def update(self, pid, fname, args, partIndex=None, offset=None):
        """
        update project-id update-type args partIndex = None offset = None

        Send a music related update for the remote backend to process. args is
        a tuple of arguments
        """
        args = json.dumps(args)
        msg = client.serialize("update", pid, fname, args, partIndex, offset)
        reply = self.__client.send(msg)
        if DEBUG: print(reply)
        return server.deserialize(reply)
 def get_project(self, project_id):
     """Given a uuid, get the project to work on."""
     msg = client.serialize("get_project", project_id)
     reply = server.deserialize(self.__client.send(msg))
     if DEBUG:
         print(reply)
     status, ret = reply
     if status == "ok":
         print(type(ret))
         realProj = json.loads(ret[0])
         self.__project = util.composteProject.deserializeProject(realProj)
     return reply
示例#10
0
    def __handle(self, _, rpc):
        """
        Dispatch to handle messages
        """
        self.get_db_connections()

        def fail(*args):
            return ("fail", "I don't know what you want me to do")

        def unimplemented(*args):
            return ("?", "?")

        rpc_funs = {
            "register": self.register,
            "login": self.login,
            "create_project": self.create_project,
            "list_projects": self.list_projects_by_user,
            "get_project": self.get_project_over_the_wire,
            "subscribe": self.subscribe,
            "unsubscribe": self.unsubscribe,
            "update": self.do_update,
            "handshake": self.compare_versions,
            "share": self.share,
        }

        self.__server.debug(rpc)
        f = rpc["fName"]

        do_rpc = rpc_funs.get(f, fail)

        try:
            # This is expected to be a tuple of things to send back
            (status, other) = do_rpc(*rpc["args"])
        except GenericError as e:
            return ("fail", "Internal server error")
        except:
            self.__server.error(traceback.format_exc())
            return ("fail", "Internal server error (Developer error)")

        # Only broadcast successful updates
        if f == "update" and status == "ok":
            self.__server.broadcast(
                client.serialize(rpc["fName"], *rpc["args"]))

        return (status, other)
示例#11
0
    def create_project(self, uname, pname, metadata):
        """
        create-project username project-name metadata

        Attempt to create a project. Metdata must have the form of a json
        object, eg "{ "owner": username }"
        """
        if type(metadata) == str:
            metadata = json.loads(metadata)
        metadata["owner"] = uname
        metadata["name"] = pname
        metadata = json.dumps(metadata)
        msg = client.serialize("create_project", uname, pname, metadata)
        reply = self.__client.send(msg)
        if DEBUG: print(reply)
        try:
            return server.deserialize(reply)
        except:
            print(reply)
            return ("fail", "Mangled reply")