Пример #1
0
 def __init__(self, fn=None):
     self.registry = ApplicationRegistry(fn)
Пример #2
0
 def __init__(self, fn=None):
     self.registry = ApplicationRegistry(fn)
Пример #3
0
class CLIController(object):

    def __init__(self, fn=None):
        self.registry = ApplicationRegistry(fn)


    def do_list(self):
        self.registry.showAll()

    def do_add_app(self, id, hostname, ckey, csec, ssl=False):
        try:
            self.registry.addApp(id, hostname, ckey, csec, ssl)
            self.registry.save()
            print("OK")
        except ConfigParser.DuplicateSectionError:
            print("Duplicate app id")
            exit(1)



    def do_del_app(self, id):
        if not id in self.registry.getApps():
            print("Unknown app id")
            exit(1)
        # also remove every client for this app!
        for c in self.registry.getClients():
            self.registry.getClient(c)
            if c['app']['id'] == id:
                self.registry.removeClient(c)
        self.registry.removeApp(id)
        self.registry.save()
        print("OK")


    def do_del_client(self, id):
        if not id in self.registry.getClients():
            print("Unknown client id")
            exit(1)
        self.registry.removeClient(id)
        self.registry.save()
        print("OK")


    def do_add_client(self, id, app_id):
        if id in self.registry.getClients():
            print("Client id already taken")
            exit(1)
        try:
            app = self.registry.getApp(app_id)
            client = ZotonicClient(app)
            token = client.register_client()
            self.registry.addClient(id, app_id, token.key, token.secret)
            self.registry.save()
            print("OK")
        except ConfigParser.NoSectionError:
            print("No such app: "+app_id)
            exit(1)


    def do_request(self, client_id, method, *args):
        client = self.registry.getClient(client_id)
        client = ZotonicClient(client)
        params = dict((a.split("=",1) for a in args))
        result = client.doMethod(method, params, http_method="GET")
        print(json.dumps(result, sort_keys=True, indent=2))

    do_rq = do_request
Пример #4
0
class CLIController(object):
    def __init__(self, fn=None):
        self.registry = ApplicationRegistry(fn)

    def do_list(self):
        self.registry.showAll()

    def do_add_app(self, id, hostname, ckey, csec):
        try:
            self.registry.addApp(id, hostname, ckey, csec)
            self.registry.save()
            print("OK")
        except ConfigParser.DuplicateSectionError:
            print("Duplicate app id")
            exit(1)

    def do_del_app(self, id):
        if not id in self.registry.getApps():
            print("Unknown app id")
            exit(1)
        # also remove every client for this app!
        for c in self.registry.getClients():
            self.registry.getClient(c)
            if c['app']['id'] == id:
                self.registry.removeClient(c)
        self.registry.removeApp(id)
        self.registry.save()
        print("OK")

    def do_del_client(self, id):
        if not id in self.registry.getClients():
            print("Unknown client id")
            exit(1)
        self.registry.removeClient(id)
        self.registry.save()
        print("OK")

    def do_add_client(self, id, app_id):
        if id in self.registry.getClients():
            print("Client id already taken")
            exit(1)
        try:
            app = self.registry.getApp(app_id)
            client = ZotonicClient(app)
            token = client.register_client()
            self.registry.addClient(id, app_id, token.key, token.secret)
            self.registry.save()
            print("OK")
        except ConfigParser.NoSectionError:
            print("No such app: " + app_id)
            exit(1)

    def do_request(self, client_id, method, *args):
        client = self.registry.getClient(client_id)
        client = ZotonicClient(client)
        params = dict((a.split("=", 1) for a in args))
        result = client.doMethod(method, params, http_method="GET")
        print(json.dumps(result, sort_keys=True, indent=2))

    do_rq = do_request