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()
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()
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()]
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()]
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)
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)