# -*- coding: utf8 -*-
import os
import sys
import transaction
import time
import lxml.etree as ET
from datetime import datetime
from sqlalchemy import engine_from_config
from sqlalchemy import create_engine
import unicodedata
import urllib
# Usefull tools
from slugify import slugify
from sqlite3 import dbapi2 as sqlite
from os import path

from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
    
    
from jm2l.models import *

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)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        admin = User(nom=u'jm2l', prenom='contact', slug='contact jm2l', password=u'jm2l', mail=u'contact@jm2l.linux-azur.org')
        DBSession.add(admin)