# Path: scribeui_pyramid/modules/app/sqla.py
# def get_session(request):
# def init_sqla(settings):
#     def __props__(self, convert_date=False):
#     def __todict__(self):
#         def convert_datetime(value):
#     def __iter__(self):
#     def __json__(self, request):
#     def fromdict(self, values):
#     def all(cls, page=None, limit=None):
#     def by_id(cls, id):
# def includeme(config):
# class BaseMixin(object):
# 
# Path: scribeui_pyramid/modules/workspaces/models.py
# class Workspace(Base, BaseMixin):
# 
#     __tablename__ = 'workspaces'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False, unique=True)
#     password = sa.Column(sa.Unicode(256))
# 
# 
#     def __repr__(self):
#         return u"<Workspace('{0}')>".format(self.name)
# 
# 
#     @staticmethod
#     def password_manager():
#         return DelegatingPasswordManager(preferred=BCRYPTPasswordManager())
# 
# 
#     @staticmethod
#     def encode_password(raw):
#         return Workspace.password_manager().encode(raw)
# 
# 
#     @staticmethod
#     def check_password(hashed, raw):
#         return Workspace.password_manager().check(
#             hashed,
#             raw,
#             setter=Workspace.encode_password
#         )
# 
# 
#     @classmethod
#     def authenticate(cls, name, password):
#         workspace = DBSession.query(cls)\
#             .filter_by(name=name)\
#             .first()
# 
#         if workspace:
#             if workspace.password and password and Workspace.check_password(workspace.password, password):
#                 return workspace
#             elif not workspace.password and not password:
#                 return workspace
#         return None
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# 
#     def get_maps(self, type=None):
#         q = Map.query.filter(Map.workspace_id == self.id)
# 
#         if type:
#             q = q.filter(Map.type == type)
# 
#         return q.all()
# 
# 
#     def get_map_by_name(self, name):
#         q = DBSession.query(Map)\
#             .filter(Map.name == name.lower(), Map.workspace_id == self.id)
# 
#         return q.first()
# 
# Path: scribeui_pyramid/modules/maps/models.py
# class Map(Base, BaseMixin):
# 
#     __tablename__ = 'maps'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False)
#     type = sa.Column(sa.Unicode(30), nullable=False)
#     description = sa.Column(sa.Unicode())
#     projection = sa.Column(sa.Unicode())
#     extent = sa.Column(sa.Unicode(50))
#     git_url = sa.Column(sa.Unicode())
# 
#     workspace_id = sa.Column(sa.Integer, sa.ForeignKey('workspaces.id'),
#                              nullable=False)
# 
#     def __repr__(self):
#         return u"<Map('{0}')>".format(self.name)
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()


import os
import sys
from fixture import SQLAlchemyFixture
from dataset import (
    WorkspaceData,
    MapData
)
from sqlalchemy import (
    engine_from_config,
    MetaData
)
from pyramid.paster import (
    get_appsettings,
    setup_logging
)
from ..modules.app.sqla import DBSession
from scribeui_pyramid.modules.workspaces.models import Workspace
from scribeui_pyramid.modules.maps.models import Map
# -*- coding: utf-8 -*-






def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri>\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)


def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]

# Path: scribeui_pyramid/modules/app/sqla.py
# def get_session(request):
# def init_sqla(settings):
#     def __props__(self, convert_date=False):
#     def __todict__(self):
#         def convert_datetime(value):
#     def __iter__(self):
#     def __json__(self, request):
#     def fromdict(self, values):
#     def all(cls, page=None, limit=None):
#     def by_id(cls, id):
# def includeme(config):
# class BaseMixin(object):
# 
# Path: scribeui_pyramid/modules/workspaces/models.py
# class Workspace(Base, BaseMixin):
# 
#     __tablename__ = 'workspaces'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False, unique=True)
#     password = sa.Column(sa.Unicode(256))
# 
# 
#     def __repr__(self):
#         return u"<Workspace('{0}')>".format(self.name)
# 
# 
#     @staticmethod
#     def password_manager():
#         return DelegatingPasswordManager(preferred=BCRYPTPasswordManager())
# 
# 
#     @staticmethod
#     def encode_password(raw):
#         return Workspace.password_manager().encode(raw)
# 
# 
#     @staticmethod
#     def check_password(hashed, raw):
#         return Workspace.password_manager().check(
#             hashed,
#             raw,
#             setter=Workspace.encode_password
#         )
# 
# 
#     @classmethod
#     def authenticate(cls, name, password):
#         workspace = DBSession.query(cls)\
#             .filter_by(name=name)\
#             .first()
# 
#         if workspace:
#             if workspace.password and password and Workspace.check_password(workspace.password, password):
#                 return workspace
#             elif not workspace.password and not password:
#                 return workspace
#         return None
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()
# 
# 
#     def get_maps(self, type=None):
#         q = Map.query.filter(Map.workspace_id == self.id)
# 
#         if type:
#             q = q.filter(Map.type == type)
# 
#         return q.all()
# 
# 
#     def get_map_by_name(self, name):
#         q = DBSession.query(Map)\
#             .filter(Map.name == name.lower(), Map.workspace_id == self.id)
# 
#         return q.first()
# 
# Path: scribeui_pyramid/modules/maps/models.py
# class Map(Base, BaseMixin):
# 
#     __tablename__ = 'maps'
#     id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
#     name = sa.Column(sa.Unicode(30), nullable=False)
#     type = sa.Column(sa.Unicode(30), nullable=False)
#     description = sa.Column(sa.Unicode())
#     projection = sa.Column(sa.Unicode())
#     extent = sa.Column(sa.Unicode(50))
#     git_url = sa.Column(sa.Unicode())
# 
#     workspace_id = sa.Column(sa.Integer, sa.ForeignKey('workspaces.id'),
#                              nullable=False)
# 
#     def __repr__(self):
#         return u"<Map('{0}')>".format(self.name)
# 
# 
#     @classmethod
#     def by_name(cls, name):
#         q = DBSession.query(cls)\
#             .filter(sa.func.lower(cls.name) == name.lower())
# 
#         return q.first()


# Path: scribeui_pyramid/scripts/loaddata.py
import os
import sys
from fixture import SQLAlchemyFixture
from dataset import (
    WorkspaceData,
    MapData
)
from sqlalchemy import (
    engine_from_config,
    MetaData
)
from pyramid.paster import (
    get_appsettings,
    setup_logging
)
from ..modules.app.sqla import DBSession
from scribeui_pyramid.modules.workspaces.models import Workspace
from scribeui_pyramid.modules.maps.models import Map

# -*- coding: utf-8 -*-






def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri>\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)


def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]

    setup_logging(config_uri)