示例#1
0
文件: db.py 项目: govtmirror/FPA_Core
import codecs

from flask import current_app
import migrate.versioning.api as migrate_api
from migrate.exceptions import DatabaseNotControlledError

from openspending.core import db
from openspending.model import Dataset
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

log = logging.getLogger(__name__)

from sqlalchemy.sql import text

manager = create_submanager(description='Database operations')


# @manager.option('-g', '--geom-file', dest='geomfile_user', action='store_true',
#                 help="Path to .sql file for geometries (Optional)",
#                 required=False,
#                 default=None
@manager.option('geomfile_user', nargs=argparse.REMAINDER,
                help="Dataset file URLs")
@manager.command
def create_geometry(**args):
    """ Create the geometry tables necessary for cubes """

    print "sorry this is not currently possible with sqlalchemy"
    print "looking for alternatives like subprocess or just a batch file"
示例#2
0
import logging
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
from webassets.script import BuildCommand, CommandLineEnvironment


log = logging.getLogger(__name__)

manager = create_submanager(description='Build the static files')


@manager.command
def build(silent = False):
    """ Build the static Files"""
    env = current_app.jinja_env.assets_environment

    cmd = CommandLineEnvironment(env, log)

    directory = env.get_directory()

    mybuild = BuildCommand(cmd)
    mybuild(directory=directory)





示例#3
0
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
import flask_whooshalchemy as whoo
from openspending.command.geometry import create as createCountries

manager = create_submanager(description='User operations')


@manager.command
def reindex():
    """ Grant admin privileges to given user """
    from openspending.core import db
    from openspending.model import Dataset
    from openspending.model.country import Country

    index = whoo.whoosh_index(current_app, Dataset)

    with index.writer() as writer:

        for dataset in Dataset.all():
            primary_field = dataset.pure_whoosh.primary_key_name
            searchable = dataset.__searchable__
            attrs = {}
            for key in searchable:
                try:
                    attrs[key] = unicode(getattr(dataset, key))
                except AttributeError:
                    raise AttributeError('{0} does not have {1} field {2}'
                            .format("Dataset", __searchable__, key))
示例#4
0
文件: db.py 项目: fucc1/FPA_Core
import codecs

from flask import current_app
import migrate.versioning.api as migrate_api
from migrate.exceptions import DatabaseNotControlledError

from openspending.core import db
from openspending.model import Dataset
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

log = logging.getLogger(__name__)

from sqlalchemy.sql import text

manager = create_submanager(description="Database operations")


# @manager.option('-g', '--geom-file', dest='geomfile_user', action='store_true',
#                 help="Path to .sql file for geometries (Optional)",
#                 required=False,
#                 default=None
@manager.option("geomfile_user", nargs=argparse.REMAINDER, help="Dataset file URLs")
@manager.command
def create_geometry(**args):
    """ Create the geometry tables necessary for cubes """

    print "sorry this is not currently possible with sqlalchemy"
    print "looking for alternatives like subprocess or just a batch file"

    print "until then load the fixtures/goemetry_file.backup using pgadmin"
示例#5
0
import logging
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
from webassets.script import BuildCommand, CommandLineEnvironment

log = logging.getLogger(__name__)

manager = create_submanager(description='Build the static files')


@manager.command
def build(silent=False):
    """ Build the static Files"""
    env = current_app.jinja_env.assets_environment

    cmd = CommandLineEnvironment(env, log)

    directory = env.get_directory()

    mybuild = BuildCommand(cmd)
    mybuild(directory=directory)
示例#6
0
import logging
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
import flask_whooshalchemy as whoo

log = logging.getLogger(__name__)

manager = create_submanager(
    description='Create model geometries to be used for country pages')


@manager.command
def create(silent=False):
    """ Create the geometry model from the geometry__country_level0 table """
    from openspending.core import db
    from openspending.model.country import Country

    result = db.engine.execute("SELECT \
                        country_level0.gid as gid \
                        FROM public.geometry__country_level0 as country_level0;"
                               )

    for row in result:
        gid = row['gid']

        #check if it already exists and don't overwrite
        if Country.by_gid(gid):
            if not silent:
                log.info("Found existing gid " + str(gid) +
示例#7
0
import logging
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
import flask_whooshalchemy as whoo

log = logging.getLogger(__name__)

manager = create_submanager(description='Create model geometries to be used for country pages')


@manager.command
def create(silent = False):
    """ Create the geometry model from the geometry__country_level0 table """
    from openspending.core import db
    from openspending.model.country import Country

    result = db.engine.execute("SELECT \
                        country_level0.gid as gid \
                        FROM public.geometry__country_level0 as country_level0;")


    for row in result:
        gid = row['gid']

        #check if it already exists and don't overwrite
        if Country.by_gid(gid):
            if not silent:
                log.info("Found existing gid " + str(gid) + ".  Will not replace.")
            continue
示例#8
0
from openspending.command.util import create_submanager
from openspending.command.util import CommandException

from flask import current_app
import flask_whooshalchemy as whoo
from openspending.command.geometry import create as createCountries

manager = create_submanager(description='User operations')


@manager.command
def reindex():
    """ Grant admin privileges to given user """
    from openspending.core import db
    from openspending.model import Dataset
    from openspending.model.country import Country

    index = whoo.whoosh_index(current_app, Dataset)

    with index.writer() as writer:

        for dataset in Dataset.all():
            primary_field = dataset.pure_whoosh.primary_key_name
            searchable = dataset.__searchable__
            attrs = {}
            for key in searchable:
                try:
                    attrs[key] = unicode(getattr(dataset, key))
                except AttributeError:
                    raise AttributeError(
                        '{0} does not have {1} field {2}'.format(