Ejemplo n.º 1
0
def install_designs():
    from couchdbkit import *
    from couchdbkit.loaders import FileSystemDocsLoader
    server = Server(settings.SERVER_URI)
    loader = FileSystemDocsLoader(settings.DESIGN_PATH)
    db = server[settings.DATABASE_NAME]
    loader.sync(db, verbose=True)
Ejemplo n.º 2
0
	def __init__(self, database_uri=None, dbname=None):
		'''
		Create a Server object, initiate connection and set up the databse URI 
		(Not particulary in that order :-)
		Oh and also sync up the views from the on disk storage onto CouchDB
		so we can use them for our maintainance operations.
		'''
		self.logger = configuration.get_logger(logging_instance=conflictlogging,
							system_name='dbmaintainer')
		configuration.info(self.logger)
		self.logger.info('Database maintainer starting.')
		if not database_uri:
			database_uri = "http://127.0.0.1:5984"
		if not dbname:
			dbname = 'session_store'
		self.dbname = dbname
		self.db_uri = database_uri
		self.dbserver = Server(self.db_uri)
		loader = FileSystemDocsLoader('/root/relaxession/_design/')
		try:
			self.db = self.dbserver.get_or_create_db(self.dbname)
			loader.sync(self.db, verbose=True)
		except Exception as e:
			self.logger.info('Init error: %s' % e)
			sys.exit(1)
		self.db.res.put('/_revs_limit',str(configuration.REVS_LIMIT))
Ejemplo n.º 3
0
def setup_app(command, conf, vars):
    """Place any commands to setup whatcouch_pylons here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Add design docs to CouchDB.
    loader = FileSystemDocsLoader(sys.path[0] + '/whatcouch_pylons/_design')
    loader.sync(Session.auth)

    # Add a user, group, and permission to CouchDB.
    user_name = 'admin'
    user_password = '******'
    group_name = 'administrators'
    perm_name = 'superpowers'

    if len(User.view('whatcouch/user_list', key=user_name)) > 0:
        raise Exception('User already exists.')
    if len(Group.view('whatcouch/group_list', key=group_name)) > 0:
        raise Exception('Group already exists.')
    if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0:
        raise Exception('Permission already exists.')

    perm = Permission(name=perm_name)
    perm.save()
    group = Group(name=group_name)
    group.permissions.append(perm)
    group.save()
    user = User.create(user_name, user_password)
    user.groups.append(group)
    user.save()
Ejemplo n.º 4
0
def setup_app(settings):
    # Init CouchDB model.
    print "initializing model"
    init_model(settings)

    # Add design docs to CouchDB.
    path = sys.path[0] + '/_design'
    print "loading views at %s" % path
    loader = FileSystemDocsLoader(path)
    loader.sync(Session.auth)

    # Add a user, group, and permission to CouchDB.
    user_name = 'admin'
    user_password = '******'
    group_name = 'administrators'
    perm_name = 'superpowers'

    if len(User.view('whatcouch/user_list', key=user_name)) > 0:
        raise Exception('User already exists.')
    if len(Group.view('whatcouch/group_list', key=group_name)) > 0:
        raise Exception('Group already exists.')
    if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0:
        raise Exception('Permission already exists.')

    print "loading data"
    perm = Permission(name=perm_name)
    perm.save()
    group = Group(name=group_name)
    group.permissions.append(perm)
    group.save()
    user = User.create(user_name, user_password)
    user.groups.append(group)
    user.save()
Ejemplo n.º 5
0
def setup_app(settings):
    # intialize our tornado instance
    app = tornado.web.Application([
        (r"/", views.IndexHandler),
        (r"/signup", views.SignupHandler),
        (r"/signup/complete", views.SignupCompleteHandler),
        ], **settings)

    # couchdb setup
    if settings['db_user']:
        from restkit import BasicAuth
        server = Server(
            uri=settings['db_uri'],
            filters=[
                BasicAuth(settings['db_user'], settings['db_pass'])
                ],
            )
        db = server.get_or_create_db(settings['db_name'])
        # now attach our couchdb instance to the tornado app instance
        app.couchdb = db

        # setup couchdb views
        loader = FileSystemDocsLoader(path.join(
            path.dirname(__file__),
            '_design'
            ) )
        loader.sync(db, verbose=True)

    return app
Ejemplo n.º 6
0
 def load_views(self, lp):
     self.loadpath = lp
     print "Loading design docs from %s" % lp
     loader = FileSystemDocsLoader(self.loadpath)
     loader.sync(self.db, verbose=True)
     print "Design docs loaded"
     return 0
Ejemplo n.º 7
0
def setup_app(settings):
    """Set up the application."""
    # Init CouchDB model.
    print("initializing model")
    init_model(settings)

    # Add design docs to CouchDB.
    path = sys.path[0] + "/_design"
    print("loading views at %s" % path)
    loader = FileSystemDocsLoader(path)
    loader.sync(Session.auth)

    # Add a user, group, and permission to CouchDB.
    user_name = "admin"
    user_password = "******"
    group_name = "administrators"
    perm_name = "superpowers"

    print("loading data")
    perm = Permission(name=perm_name)
    perm.save()
    group = Group(name=group_name)
    group.permissions.append(perm)
    group.save()
    user = User.create(user_name, user_password)
    user.groups.append(group)
    user.save()
Ejemplo n.º 8
0
def main(views_directory, server_uri):
    directory = os.path.abspath(views_directory)
    server = Server(server_uri)
    db = server.get_or_create_db("v1")

    loader = FileSystemDocsLoader(directory)
    loader.sync(db, debug=True, verbose=True)
Ejemplo n.º 9
0
 def setup(self):
     """
     Creates the test database and loads the design documents.
     """
     self.server = couchdbkit.Server()
     self.db = self.server.create_db(self.db_name)
     loader = FileSystemDocsLoader(self.design_path)
     loader.sync(self.db)
Ejemplo n.º 10
0
 def sync(self, app=None):
     """Sync the local views with CouchDB server."""
     app = app or self.app
     if app is None:
         return  #XXX
     local_path = app.config.get('COUCHDB_VIEWS')
     design_path = os.path.join(app.root_path, local_path)
     loader = FileSystemDocsLoader(design_path)
     loader.sync(app.extensions['couchdbkit'].db)
Ejemplo n.º 11
0
 def sync(self, app=None):
     """Sync the local views with CouchDB server."""
     app = app or self.app
     if app is None:
         return #XXX
     local_path = app.config.get('COUCHDB_VIEWS')
     design_path = os.path.join(app.root_path, local_path)
     loader = FileSystemDocsLoader(design_path)
     loader.sync(app.extensions['couchdbkit'].db)
Ejemplo n.º 12
0
    def handle(self, *args, **options):
        for dbname in ('couchflow', 'couchauth',
                 'couchsessions', 'circulation'):
            db  = get_db(dbname)
            path = settings.PROJECT_PATH + '/apps/'+dbname+'/_design/' 
            loader = FileSystemDocsLoader(path)
            loader.sync(db)

            sys.stdout.write('Successfully updated "%s"\n' % dbname)
Ejemplo n.º 13
0
def couch_sync():
	couch_db = couch.init(app.config)
	path = os.getcwd()  
	path = path.replace('/manage.py','')
	if not path:
		return "You must provide the path to PonyExpress"
	dir = '%s/ponyexpress/_design' % path
	print "Syncronizing Couchdb Views from %s" % dir
	loader = FileSystemDocsLoader(dir)
	loader.sync(couch_db, verbose=True)
Ejemplo n.º 14
0
def couch_sync():
    couch_db = couch.init(app.config)
    path = os.getcwd()
    path = path.replace('/manage.py', '')
    if not path:
        return "You must provide the path to PonyExpress"
    dir = '%s/ponyexpress/_design' % path
    print("Syncronizing Couchdb Views from %s" % dir)
    loader = FileSystemDocsLoader(dir)
    loader.sync(couch_db, verbose=True)
Ejemplo n.º 15
0
 def load_views(self, lp):
     self.loadpath = lp
     try:
         print "Loading design docs from %s" % lp
         loader = FileSystemDocsLoader(self.loadpath)
         loader.sync(self.db, verbose=True)
         print "Design docs loaded"
         return 0
     except:
         raise VogelerPersistenceException("Document load path not found: %s" % lp)
Ejemplo n.º 16
0
 def load_views(self, lp):
     self.loadpath = lp
     try:
         print "Loading design docs from %s" % lp
         loader = FileSystemDocsLoader(self.loadpath)
         loader.sync(self.db, verbose=True)
         print "Design docs loaded"
         return 0
     except:
         log.fatal("Document load path not found: %s" % lp)
         raise exceptions.VogelerPersistenceException()
Ejemplo n.º 17
0
def setup(dbstring, path):
    server_uri, db_name, docid = parse_uri(dbstring)
    if "@" in server_uri:
        username, password, server_uri = parse_auth(server_uri) 
        server = Server(server_uri)
        server.res.add_authorization(httpc.BasicAuth((uri.username, uri.password)))
    else:
        server = Server(server_uri)
    db = server.get_or_create_db("couchdbproxy")
    loader = FileSystemDocsLoader(path)
    loader.sync(db, verbose=True)
Ejemplo n.º 18
0
Archivo: utils.py Proyecto: fk-lx/mygpo
def sync_design_docs():
    """ synchronize the design docs for all databases """

    base_dir = settings.BASE_DIR

    for part, label in settings.COUCHDB_DDOC_MAPPING.items():
            path = os.path.join(base_dir, '..', 'couchdb', part, '_design')

            logger.info('syncing ddocs for "%s" from "%s"', label, path)

            db = loading.get_db(label)
            loader = FileSystemDocsLoader(path)
            loader.sync(db, verbose=True)
Ejemplo n.º 19
0
class Couch(object):
    """
    """
    
    def sync(self):
        path = join_path(dirname(__file__), '_design')
        self.loader = FileSystemDocsLoader(path)
        self.loader.sync(self.db)
        
    
    
    def __init__(self, sync=config.debug):
        self.db = Server().get_or_create_db('thruflo')
        if sync:
            self.sync()
Ejemplo n.º 20
0
def migrate(dbstring, path):
    server_uri, db_name, docid = parse_uri(dbstring)
    if "@" in server_uri:
        username, password, server_uri = parse_auth(server_uri) 
        server = Server(server_uri)
        server.res.add_authorization(httpc.BasicAuth((uri.username, uri.password)))
    else:
        server = Server(server_uri)
    db = server.get_or_create_db("couchdbproxy")
    
    # make sure design docs are here
    loader = FileSystemDocsLoader(path)
    loader.sync(db, verbose=True)
    
    
    nodes = db.view("api01/nodes", include_docs=True)
    nodes_docs = []
    for node in nodes:
        doc = node["doc"]
        doc["type"] = "machine"
        doc["name"] = doc["nodename"]
        del doc["nodename"]
        nodes_docs.append(doc)
    db.bulk_save(nodes_docs, use_uuids=False)
    
    aliases = db.view("api01/aliases", include_docs=True)
    aliases_docs = []
    for alias in aliases:
        doc = alias["doc"]
        user = db.view("api01/users", include_docs=True).one()
        if user:
            doc["nodename"] = user['doc']["username"]
        del doc["port"]
        aliases_docs.append(doc)
    db.bulk_save(aliases_docs, use_uuids=False)
    
    users = db.view("api01/users", include_docs=True)
    users_docs = []
    for user in users:
        doc = user["doc"]
        doc["type"] = "node"
        doc["machine"] = doc["nodename"]
        doc["nodename"] = doc["username"]
        users_docs.append(doc)
    db.bulk_save(users_docs, use_uuids=False)
Ejemplo n.º 21
0
	def get(self):
		'''
		GET verb call
		
		returns the template for the admin landing page,
		nothing fancy here just a few links to the areas.
		
		Args:
			None
			
		Returns:
			HTML template, see adminView and templates.py for more info.
			
		'''
		loader = FileSystemDocsLoader('_design')
		loader.sync(database, verbose=True)
		newAdminDoc = adminDoc(id=0)
		newAdminDoc.save()
Ejemplo n.º 22
0
class Couch(object):
    """Convenience wrapper around the ``couchdbkit``
      ``Server`` and ``FileSystemDocsLoader`` internals.
      
      Provides the ``couchdbkit.Database`` called "thruflo"
      as ``self.db``.
    """
    
    def sync(self):
        path = join_path(dirname(__file__), '_design')
        self.loader = FileSystemDocsLoader(path)
        self.loader.sync(self.db)
        
    
    
    def __init__(self, dbname='thruflo', settings={}):
        self.server = Server()
        self.db = self.server.get_or_create_db(dbname)
        self.app_settings = settings
Ejemplo n.º 23
0
 def __init__(self, db_url=cfg['COUCHDB_URL'],
               db_username=cfg['COUCHDB_USER'],
               db_password=cfg['COUCHDB_PASSWORD']):
     """Sets up the database connection and starts loading songs."""
     # Initiate a connection to the database server
     self.shutting_down = threading.Event()
     self.building_cache = threading.Event()
     logger.debug("Initiating the database connection.")
     filters = []
     if db_username or db_password:
         filters.append(BasicAuth(db_username, db_password))
     self._server = Server(db_url, filters=filters)
     connect_retries = 0
     while True:
         try:
             # Get a reference to our database
             self.db = self._server.get_or_create_db(cfg['DATABASE_NAME'])
             break
         except Exception as e:
             logger.error(str(e))
             if connect_retries < 3:
                 logger.error("Error connecting to CouchDB.")
                 connect_retries += 1
                 sleep(3)
             else:
                 logger.error("Could not connect to CouchDB. Quitting.")
                 sys.exit(1)
     logger.debug("Loading database design documents.")
     # Load our database views from the filesystem
     loader = FileSystemDocsLoader(os.path.join(cfg['ASSETS_DIR'],
                                   'views/_design'))
     try:
         loader.sync(self.db, verbose=True)
     except:
         pass
     logger.debug("Initializing the database cache.")
     self.cache = BlofeldCache(self.db)
     self.scanner = Scanner(cfg['MUSIC_PATH'], self.db)
     self.update()
Ejemplo n.º 24
0
from couchdbkit.loaders import FileSystemDocsLoader
from couchdbkit import Server, Database
import sys, os


path_to_design = sys.argv[1]
uri = sys.argv[2]
dbname = sys.argv[3]
print 'upload views from directory root:\t%s \t to db:\t%s/%s' % (path_to_design, uri,dbname)
server = Server(uri)
db = server.get_or_create_db(dbname)

loader = FileSystemDocsLoader(path_to_design)
loader.sync(db, verbose=True)
Ejemplo n.º 25
0
    def handle(self, *args, **options):

        path = os.path.join(settings.BASE_DIR, '..', 'couchdb', '_design')
        db = get_main_database()
        loader = FileSystemDocsLoader(path)
        loader.sync(db, verbose=True)
Ejemplo n.º 26
0
 def run(self):
     server = Server(self.settings.couchdb_uri)
     db = server.get_or_create_db(self.settings.couchdb_db)
     loader = FileSystemDocsLoader('./_design')
     loader.sync(db, verbose=True)
def sync_ddocs(dburl):
    auth_filters = get_credentials()
    db = Database(dburl, filters=auth_filters)

    loader = FileSystemDocsLoader('_design')
    loader.sync(db, verbose=True)
Ejemplo n.º 28
0
 def sync(self):
     """Sync the local views with CouchDB server."""
     local_path = self.app.config.get('COUCHDB_VIEWS')
     design_path = os.path.join(self.app.root_path, local_path)
     loader = FileSystemDocsLoader(design_path)
     loader.sync(self.db)
 def sync(self):
     """Sync the local views with CouchDB server."""
     local_path = self.app.config.get('COUCHDB_VIEWS')
     design_path = os.path.join(self.app.root_path, local_path)
     loader = FileSystemDocsLoader(design_path)
     loader.sync(self.db)
Ejemplo n.º 30
0
from couchdbkit.loaders import FileSystemDocsLoader
from couchdbkit import Server, Database
import sys, os

path_to_design = sys.argv[1]
uri = sys.argv[2]
dbname = sys.argv[3]
print 'upload views from directory root:\t%s \t to db:\t%s/%s' % (
    path_to_design, uri, dbname)
server = Server(uri)
db = server.get_or_create_db(dbname)

loader = FileSystemDocsLoader(path_to_design)
loader.sync(db, verbose=True)
Ejemplo n.º 31
0
 def sync(self):
     path = join_path(dirname(__file__), '_design')
     self.loader = FileSystemDocsLoader(path)
     self.loader.sync(self.db)
def sync_ddocs(dburl):
    auth_filters = get_credentials()
    db = Database(dburl, filters=auth_filters)

    loader = FileSystemDocsLoader('_design')
    loader.sync(db, verbose=True)
Ejemplo n.º 33
0
if __name__ == '__main__':
    fname = sys.argv[1]
    uri = sys.argv[2]
    dbname = sys.argv[3]

    print 'Upload contents of %s to %s/%s' % (fname, uri, dbname)
    if (fname.endswith('.gz')):
        fname = gunzip(fname)

    # #connect to the db
    cloudant = Server(uri)
    db = cloudant.get_or_create_db(dbname)
    print db.info()

    #sync the views for prebuilt indices
    loader = FileSystemDocsLoader('_design/')
    loader.sync(db, verbose=True)

    #loop on file for upload
    reader = DictReader(open(fname), delimiter='|')

    #used for bulk uploading
    docs = list()
    checkpoint = 1000
    n = 0
    start = time.time()

    for doc in reader:
        n += 1
        docs.append(doc)
        if (len(docs) % checkpoint == 0):
Ejemplo n.º 34
0
def design_sync(type):
    "sync the documents in _design"
    loader = FileSystemDocsLoader(type+'_design')
    loader.sync(Model.database, verbose=True)
Ejemplo n.º 35
0
        return self.name or u''


# You don't need a try/except. This is just to allow to run FA's tests without
# couchdb installed. Btw this have to be in another place in your app. eg: you
# don't need to sync views each time the controller is loaded.
try:
    server = Server()
    if server: pass
except:
    server = None
else:
    db = server.get_or_create_db('formalchemy_test')

    design_docs = os.path.join(os.path.dirname(pylonsapp.__file__), '_design')
    loader = FileSystemDocsLoader(design_docs)
    loader.sync(db, verbose=True)

    contain(db, Pet, Person)


class CouchdbController(BaseController):

    # override default classes to use couchdb fieldsets
    FieldSet = couchdb.FieldSet
    Grid = couchdb.Grid
    model = [Person, Pet]

    def Session(self):
        """return a formalchemy.ext.couchdb.Session"""
        return couchdb.Session(db)
Ejemplo n.º 36
0
def sync_views():
    from couchdbkit.loaders import FileSystemDocsLoader
    server = Server('http://localhost/couchdb/')
    db = get_db()
    loader = FileSystemDocsLoader('romnyweb/model/couch/_design')
    loader.sync(db, verbose=True)