# Path: ringo/lib/helpers/appinfo.py
# def get_app_location(name=None):
#     if not name:
#         name = get_app_name()
#     return pkg_resources.get_distribution(name).location
# 
# Path: ringo/lib/helpers/misc.py
# def dynamic_import(cl):
#     d = cl.rfind(".")
#     classname = cl[d + 1:len(cl)]
#     m = __import__(cl[0:d], globals(), locals(), [classname])
#     return getattr(m, classname)
# 
# Path: ringo/scripts/db.py
# def get_session(config_file, transactional=True):
#     """Will return a database session based on the application
#     configuration"""
#     engine = get_engine(config_file)
#     if transactional:
#         DBSession.configure(bind=engine)
#         return DBSession
#     else:
#         NTDBSession.configure(bind=engine)
#         return NTDBSession
# 
# def create_new_revision(args, msg=None):
#     """Will create a new autogenerated revision file. An returns the
#     path of the new generated file."""
#     cfg = get_alembic_config(args)
#     command.revision(cfg, message=msg, autogenerate=True)
#     revision_file = get_last_revision_file(args)
#     while is_locked(revision_file):
#         time.sleep(1)
#     return revision_file


import os
import fnmatch
import json
import subprocess
import uuid
import transaction
import pkg_resources
from sqlalchemy import func
from mako.lookup import TemplateLookup
from ringo.lib.helpers import get_app_location, dynamic_import
from ringo.scripts.db import (
    get_session, create_new_revision
)
from ringo.model.modul import ModulItem, ActionItem, ACTIONS

# Directory with templates to generate views and models
base_dir = pkg_resources.get_distribution("ringo").location
modul_template_dir = os.path.join(base_dir, 'ringo', 'scripts', 'templates')
template_lookup = TemplateLookup(directories=[modul_template_dir],
                                 default_filters=['h'])

mixinmap = {
    'owned': 'Owned',
    'meta': 'Meta',
    'state': 'StateMixin',
    'blobform': 'Blobform',
    'blob': 'Blob',
    'versioned': 'Versioned',
    'nested': 'Nested'
}


def get_modul_fixture(name, package, session):
    id = get_next_modulid(package, session)
    fixture = {}
    fixture["id"] = id
    fixture["name"] = name + "s"

# Path: ringo/lib/helpers/appinfo.py
# def get_app_location(name=None):
#     if not name:
#         name = get_app_name()
#     return pkg_resources.get_distribution(name).location
# 
# Path: ringo/lib/helpers/misc.py
# def dynamic_import(cl):
#     d = cl.rfind(".")
#     classname = cl[d + 1:len(cl)]
#     m = __import__(cl[0:d], globals(), locals(), [classname])
#     return getattr(m, classname)
# 
# Path: ringo/scripts/db.py
# def get_session(config_file, transactional=True):
#     """Will return a database session based on the application
#     configuration"""
#     engine = get_engine(config_file)
#     if transactional:
#         DBSession.configure(bind=engine)
#         return DBSession
#     else:
#         NTDBSession.configure(bind=engine)
#         return NTDBSession
# 
# def create_new_revision(args, msg=None):
#     """Will create a new autogenerated revision file. An returns the
#     path of the new generated file."""
#     cfg = get_alembic_config(args)
#     command.revision(cfg, message=msg, autogenerate=True)
#     revision_file = get_last_revision_file(args)
#     while is_locked(revision_file):
#         time.sleep(1)
#     return revision_file


# Path: ringo/scripts/modul.py
import os
import fnmatch
import json
import subprocess
import uuid
import transaction
import pkg_resources
from sqlalchemy import func
from mako.lookup import TemplateLookup
from ringo.lib.helpers import get_app_location, dynamic_import
from ringo.scripts.db import (
    get_session, create_new_revision
)
from ringo.model.modul import ModulItem, ActionItem, ACTIONS


# Directory with templates to generate views and models
base_dir = pkg_resources.get_distribution("ringo").location
modul_template_dir = os.path.join(base_dir, 'ringo', 'scripts', 'templates')
template_lookup = TemplateLookup(directories=[modul_template_dir],
                                 default_filters=['h'])

mixinmap = {
    'owned': 'Owned',
    'meta': 'Meta',
    'state': 'StateMixin',
    'blobform': 'Blobform',
    'blob': 'Blob',
    'versioned': 'Versioned',
    'nested': 'Nested'
}


def get_modul_fixture(name, package, session):
    id = get_next_modulid(package, session)
    fixture = {}
    fixture["id"] = id
    fixture["name"] = name + "s"

    fixture["label"] = name.capitalize()