示例#1
0
    def __init__(self, uri, create=True, **client_opts):
        if uri.endswith("/"):
            uri = uri[:-1]

        self.raw_uri = uri
        if uri.startswith("desktopcouch://"):
            if not desktopcouch:
                raise AppError("Desktopcouch isn't available on this" +
                               "machine. You can't access to %s" % uri)
            uri = "http://localhost:%s/%s" % (
                desktopcouch.find_port(), uri[15:])
            ctx = local_files.DEFAULT_CONTEXT
            oauth_tokens = local_files.get_oauth_tokens(ctx)

            consumer = oauth.Consumer(oauth_tokens["consumer_key"],
                                      oauth_tokens["consumer_secret"])
            token = oauth.Token(oauth_tokens["token"],
                                oauth_tokens["token_secret"])

            oauth_filter = OAuthFilter("*", consumer, token)
            filters = client_opts.get("filters") or []
            filters.append(oauth_filter)
            client_opts["filters"] = filters

        self.res = CouchdbResource(uri=uri, **client_opts)
        self.server_uri, self.dbname = uri.rsplit('/', 1)

        self.uuids = Uuids(self.server_uri, **client_opts)

        if create:
            # create the db
            try:
                self.res.head()
            except ResourceNotFound:
                self.res.put()
示例#2
0
    def __init__(self, uri, create=True, **client_opts):
        if uri.endswith("/"):
            uri = uri[:-1]

        self.raw_uri = uri
        if uri.startswith("desktopcouch://"):
            if not desktopcouch:
                raise AppError("Desktopcouch isn't available on this" +
                               "machine. You can't access to %s" % uri)
            uri = "http://localhost:%s/%s" % (desktopcouch.find_port(),
                                              uri[15:])
            ctx = local_files.DEFAULT_CONTEXT
            oauth_tokens = local_files.get_oauth_tokens(ctx)

            consumer = oauth.Consumer(oauth_tokens["consumer_key"],
                                      oauth_tokens["consumer_secret"])
            token = oauth.Token(oauth_tokens["token"],
                                oauth_tokens["token_secret"])

            oauth_filter = OAuthFilter("*", consumer, token)
            filters = client_opts.get("filters") or []
            filters.append(oauth_filter)
            client_opts["filters"] = filters

        self.res = CouchdbResource(uri=uri, **client_opts)
        self.server_uri, self.dbname = uri.rsplit('/', 1)

        self.uuids = Uuids(self.server_uri, **client_opts)

        if create:
            # create the db
            try:
                self.res.head()
            except ResourceNotFound:
                self.res.put()
示例#3
0
文件: model.py 项目: lshmenor/IMTAphy
def deleteDB(dbname):
    import desktopcouch.records.server
    import couchdb.client
    port = desktopcouch.find_port()
    db = desktopcouch.records.server.OAuthCapableServer('http://localhost:%s/' % port)

    del db[dbname.lower()]
示例#4
0
def deleteDB(dbname):
    import desktopcouch.records.server
    import couchdb.client
    port = desktopcouch.find_port()
    db = desktopcouch.records.server.OAuthCapableServer(
        'http://localhost:%s/' % port)

    del db[dbname.lower()]
示例#5
0
    def browse_url(self, url):
        if url.startswith("desktopcouch://"):
            if not desktopcouch:
                raise AppError("Desktopcouch isn't available on this" + "machine. You can't access to %s" % url)
            ctx = local_files.DEFAULT_CONTEXT
            bookmark_file = os.path.join(ctx.db_dir, "couchdb.html")
            try:
                username, password = re.findall("<!-- !!([^!]+)!!([^!]+)!! -->", open(bookmark_file).read())[-1]
            except ValueError:
                raise IOError("Bookmark file is corrupt." + "Username/password are missing.")

            url = "http://%s:%s@localhost:%s/%s" % (username, password, desktopcouch.find_port(), url[15:])
        webbrowser.open_new_tab(url)
示例#6
0
    def browse_url(self, url):
        if url.startswith("desktopcouch://"):
            if not desktopcouch:
                raise AppError("Desktopcouch isn't available on this"+
                    "machine. You can't access to %s" % url)
            ctx = local_files.DEFAULT_CONTEXT
            bookmark_file = os.path.join(ctx.db_dir, "couchdb.html")
            try:
                username, password = re.findall("<!-- !!([^!]+)!!([^!]+)!! -->", 
                        open(bookmark_file).read())[-1]
            except ValueError:
                raise IOError("Bookmark file is corrupt."+
                        "Username/password are missing.")

            url = "http://%s:%s@localhost:%s/%s" % (username, password,
                desktopcouch.find_port(), url[15:])
        webbrowser.open_new_tab(url)