File: commands.py

package info (click to toggle)
python-couchdbkit 0.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 640 kB
  • ctags: 1,257
  • sloc: python: 7,240; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -
#
# This file is part of couchdbkit released under the MIT license. 
# See the NOTICE for more information.

import os
from paste.deploy import loadapp
from paste.script.command import Command

from .db import sync_design, default_design_path

class SyncDbCommand(Command):
    """Syncs the CouchDB views on disk with the database.

    Example::

        $ paster syncdb my-development.ini

    This will also create the database if it does not exist
    """
    summary = __doc__.splitlines()[0]
    usage = '\n' + __doc__

    min_args = 1
    max_args = 1
    group_name = 'couchdbkit'
    default_verbosity = 3
    parser = Command.standard_parser(simulate=True)

    def command(self):
        """Main command to sync db"""
        config_file = self.args[0]

        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()

        if not self.options.quiet:
            # Configure logging from the config file
            self.logging_file_config(config_file)

        # Load the wsgi app first so that everything is initialized right
        wsgiapp = loadapp(config_name, relative_to=here_dir)
        try:
            design_path = wsgiapp.config['couchdb.design']
        except KeyError:
            design_path = default_design_path(wsgiapp.config)

        # This syncs the main database.
        sync_design(wsgiapp.config['couchdb.db'], design_path)