# Path: pytrainer/util/color.py
# def color_from_hex_string(hex_string):
#     return Color(int(hex_string, 16))
# 
# Path: pytrainer/lib/singleton.py
# class Singleton (object):
#     def __new__(cls, *args, **kwargs): 
#         if not hasattr(cls, 'self'):
#             cls.self = object.__new__(cls)
#         return cls.self


import logging
import os
import warnings
            import urlparse
            import urllib.parse as urlparse
            import datetime
            import gzip
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import TypeDecorator
from sqlalchemy import Integer, Table, Column, ForeignKey
from pytrainer.util.color import color_from_hex_string
from pytrainer.lib.singleton import Singleton
        from pytrainer.core.sport import Sport
        from pytrainer.core.equipment import Equipment
        from pytrainer.waypoint import Waypoint
        from pytrainer.core.activity import Lap
        from pytrainer.athlete import Athletestat
            from urllib import url2pathname
            from urllib.request import url2pathname
            self.url = url

        if not self.engine:
            self.engine = create_engine(self.url, logging_name='db')
            self.sessionmaker.configure(bind=self.engine)
        logging.info("DDBB created with url %s", self.url)

    def get_connection_url(self):
        return self.url

    def connect(self):
        self.session = self.sessionmaker()

    def disconnect(self):
        self.session.close()

    def select(self,table,cells,condition=None, mod=None):
        warnings.warn("Deprecated call to ddbb.select", DeprecationWarning, stacklevel=2)
        sql = "select %s from %s" %(cells,table)
        if condition is not None:
            sql = "%s where %s" % (sql, condition)
        if mod is not None:
            sql = "%s %s" % (sql, mod)
        return list(self.session.execute(sql))

    def create_tables(self, add_default=True):
        """Initialise the database schema from an empty database."""
        logging.info("Creating database tables")
        DeclarativeBase.metadata.create_all(self.engine)
        if add_default:

# Path: pytrainer/util/color.py
# def color_from_hex_string(hex_string):
#     return Color(int(hex_string, 16))
# 
# Path: pytrainer/lib/singleton.py
# class Singleton (object):
#     def __new__(cls, *args, **kwargs): 
#         if not hasattr(cls, 'self'):
#             cls.self = object.__new__(cls)
#         return cls.self


# Path: pytrainer/lib/ddbb.py
import logging
import os
import warnings
            import urlparse
            import urllib.parse as urlparse
            import datetime
            import gzip
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import TypeDecorator
from sqlalchemy import Integer, Table, Column, ForeignKey
from pytrainer.util.color import color_from_hex_string
from pytrainer.lib.singleton import Singleton
        from pytrainer.core.sport import Sport
        from pytrainer.core.equipment import Equipment
        from pytrainer.waypoint import Waypoint
        from pytrainer.core.activity import Lap
        from pytrainer.athlete import Athletestat
            from urllib import url2pathname
            from urllib.request import url2pathname

            self.url = url

        if not self.engine:
            self.engine = create_engine(self.url, logging_name='db')
            self.sessionmaker.configure(bind=self.engine)
        logging.info("DDBB created with url %s", self.url)

    def get_connection_url(self):
        return self.url

    def connect(self):
        self.session = self.sessionmaker()

    def disconnect(self):
        self.session.close()

    def select(self,table,cells,condition=None, mod=None):
        warnings.warn("Deprecated call to ddbb.select", DeprecationWarning, stacklevel=2)
        sql = "select %s from %s" %(cells,table)
        if condition is not None:
            sql = "%s where %s" % (sql, condition)
        if mod is not None:
            sql = "%s %s" % (sql, mod)
        return list(self.session.execute(sql))

    def create_tables(self, add_default=True):
        """Initialise the database schema from an empty database."""
        logging.info("Creating database tables")
        DeclarativeBase.metadata.create_all(self.engine)
        if add_default:

            for item in [Sport(name=u"Mountain Bike", weight=0.0, color=color_from_hex_string("0000ff")),