# Path: gips/utils.py
# class Colors():
#     _c = '\033['
#     OFF     = _c + '0m'
#     # Font styles
#     BOLD    = _c + '1m'
#     UNDER   = _c + '4m'
#     REV     = _c + '7m'
#     # Text colors
#     BLACK   = _c + '30m'
#     RED     = _c + '31m'
#     GREEN   = _c + '32m'
#     YELLOW  = _c + '33m'
#     BLUE    = _c + '34m'
#     PURPLE  = _c + '35m'
#     CYAN    = _c + '36m'
#     WHITE   = _c + '37m'
#     # Background colors
#     _BLACK  = _c + '40m'
#     _RED    = _c + '41m'
#     _GREEN  = _c + '42m'
#     _YELLOW = _c + '43m'
#     _BLUE   = _c + '44m'
#     _PURPLE = _c + '45m'
#     _CYAN   = _c + '46m'
#     _WHITE  = _c + '47m'
# 
# def open_vector(fname, key="", where=''):
#     """ Open vector or feature """
#     parts = fname.split(':')
#     if len(parts) == 1:
#         vector = GeoVector(fname)
#         vector.SetPrimaryKey(key)
#     else:
#         # or it is a database
#         if parts[0] not in settings().DATABASES.keys():
#             raise Exception("%s is not a valid database" % parts[0])
#         try:
#             db = settings().DATABASES[parts[0]]
#             filename = ("PG:dbname=%s host=%s port=%s user=%s password=%s" %
#                         (db['NAME'], db['HOST'], db['PORT'], db['USER'], db['PASSWORD']))
#             vector = GeoVector(filename, parts[1])
#             vector.SetPrimaryKey(key)
# 
#         except Exception, e:
#             VerboseOut(traceback.format_exc(), 4)
#     if where != '':
#         # return array of features
#         return vector.where(where)
#         features = []
#     else:
#         return vector


import datetime
import calendar
from gips.utils import Colors, open_vector
        # default to all tiles if none provided
        if tiles is None and feature is None:
            tiles = self.repo.find_tiles()

        if feature is not None:
            tiles = self.repo.vector2tiles(feature, pcov, ptile, tiles)
            self.feature = (feature.Filename(), feature.LayerName(), feature.FID())
            self.sitename = feature.Basename()
        else:
            tiles = {t: (1, 1) for t in tiles}
            self.sitename = 'tiles'
        self.coverage = tiles

    @property
    def tiles(self):
        """ List of tile ids """
        return self.coverage.keys()

    @property
    def available_dates(self):
        """ Get list of all dates for these tiles """
        dates = []
        for t in self.tiles:
            dates.extend(self.repo.find_dates(t))
        return dates

    def print_tile_coverage(self):
        """ Print tile coverage info """
        if self.site is not None:
            print Colors.BOLD + '\nTile Coverage'

# Path: gips/utils.py
# class Colors():
#     _c = '\033['
#     OFF     = _c + '0m'
#     # Font styles
#     BOLD    = _c + '1m'
#     UNDER   = _c + '4m'
#     REV     = _c + '7m'
#     # Text colors
#     BLACK   = _c + '30m'
#     RED     = _c + '31m'
#     GREEN   = _c + '32m'
#     YELLOW  = _c + '33m'
#     BLUE    = _c + '34m'
#     PURPLE  = _c + '35m'
#     CYAN    = _c + '36m'
#     WHITE   = _c + '37m'
#     # Background colors
#     _BLACK  = _c + '40m'
#     _RED    = _c + '41m'
#     _GREEN  = _c + '42m'
#     _YELLOW = _c + '43m'
#     _BLUE   = _c + '44m'
#     _PURPLE = _c + '45m'
#     _CYAN   = _c + '46m'
#     _WHITE  = _c + '47m'
# 
# def open_vector(fname, key="", where=''):
#     """ Open vector or feature """
#     parts = fname.split(':')
#     if len(parts) == 1:
#         vector = GeoVector(fname)
#         vector.SetPrimaryKey(key)
#     else:
#         # or it is a database
#         if parts[0] not in settings().DATABASES.keys():
#             raise Exception("%s is not a valid database" % parts[0])
#         try:
#             db = settings().DATABASES[parts[0]]
#             filename = ("PG:dbname=%s host=%s port=%s user=%s password=%s" %
#                         (db['NAME'], db['HOST'], db['PORT'], db['USER'], db['PASSWORD']))
#             vector = GeoVector(filename, parts[1])
#             vector.SetPrimaryKey(key)
# 
#         except Exception, e:
#             VerboseOut(traceback.format_exc(), 4)
#     if where != '':
#         # return array of features
#         return vector.where(where)
#         features = []
#     else:
#         return vector


# Path: gips/core.py
import datetime
import calendar
from gips.utils import Colors, open_vector

        # default to all tiles if none provided
        if tiles is None and feature is None:
            tiles = self.repo.find_tiles()

        if feature is not None:
            tiles = self.repo.vector2tiles(feature, pcov, ptile, tiles)
            self.feature = (feature.Filename(), feature.LayerName(), feature.FID())
            self.sitename = feature.Basename()
        else:
            tiles = {t: (1, 1) for t in tiles}
            self.sitename = 'tiles'
        self.coverage = tiles

    @property
    def tiles(self):
        """ List of tile ids """
        return self.coverage.keys()

    @property
    def available_dates(self):
        """ Get list of all dates for these tiles """
        dates = []
        for t in self.tiles:
            dates.extend(self.repo.find_dates(t))
        return dates

    def print_tile_coverage(self):
        """ Print tile coverage info """
        if self.site is not None:
            print Colors.BOLD + '\nTile Coverage'

            print Colors.UNDER + '{:^8}{:>14}{:>14}'.format('Tile', '% Coverage', '% Tile Used') + Colors.OFF