# Path: sesql/utils.py
# class Timer(object):
#     def __init__(self):
#     def start(self):
#     def stop(self):
#     def __enter__(self):
#     def __exit__(self, *args, **kwargs):
#     def get_local(self):
#     def get_global(self):
#     def reset(self):
#     def peek(self):
# def safe_str(what):
# def log_time(function, message = None):
#     def log_time_inner(*args, **kwargs):
# def strip_ligatures(value):
# def format_time(timedelta, keep = 3):
# def print_eta(percent, timedelta):
# 
# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/typemap.py
# class TypeMap(object):
#     def __init__(self):
#     def all_subclasses(klass, done = None):
#     def all_tables(self):
#     def all_classes(self):
#     def all_class_names(self):
#     def get_class_names_for(self, table):
#     def get_classes_for(self, table):
#     def get_table_for(self, klass):
#     def get_class_by_name(self, klass):
# 
# Path: sesql/fieldmap.py
# class FieldMap(object):
#     def __init__(self):
#     def all_fields(self):
#     def get_field(self, field):
#     def get_primary(self):


import logging
from sesql import utils
from sesql import config
from sesql import typemap
from sesql import fieldmap
def get_sesql_id(obj):
    """
    Get classname and id, the SeSQL identifiers
    """
    if isinstance(obj, (tuple, list)) and len(obj) == 2:
        return tuple(obj)

    def get_val(field):
        vals = fieldmap.fieldmap[field].get_values(obj)
        return vals and vals[0] or None
    return (get_val('classname'), get_val('id'))

@config.orm.transactional
def schedule_reindex(cursor, item):
    try:
        item = get_sesql_id(item)
    except (TypeError, AttributeError, ValueError):
        log.info("%r: can't get classname/id, skipping" % item)
        return

    classname, objid = item
    table_name = typemap.typemap.get_table_for(classname)
    if not table_name:
        log.info("%s: no table found, skipping" % classname)
        return

    cursor.execute("SELECT nextval('sesql_reindex_id_seq')")
    cursor.execute("INSERT INTO sesql_reindex_schedule (rowid, classname, objid) SELECT currval('sesql_reindex_id_seq'), %s, %s", item)

@index_log_wrap

# Path: sesql/utils.py
# class Timer(object):
#     def __init__(self):
#     def start(self):
#     def stop(self):
#     def __enter__(self):
#     def __exit__(self, *args, **kwargs):
#     def get_local(self):
#     def get_global(self):
#     def reset(self):
#     def peek(self):
# def safe_str(what):
# def log_time(function, message = None):
#     def log_time_inner(*args, **kwargs):
# def strip_ligatures(value):
# def format_time(timedelta, keep = 3):
# def print_eta(percent, timedelta):
# 
# Path: sesql/config.py
# CONFIG_PATH_FALLBACK = 'sesql_config'
#     CONFIG_PATH = getattr(settings, 'SESQL_CONFIG_PATH', CONFIG_PATH_FALLBACK)
#     CONFIG_PATH = CONFIG_PATH_FALLBACK
# 
# Path: sesql/typemap.py
# class TypeMap(object):
#     def __init__(self):
#     def all_subclasses(klass, done = None):
#     def all_tables(self):
#     def all_classes(self):
#     def all_class_names(self):
#     def get_class_names_for(self, table):
#     def get_classes_for(self, table):
#     def get_table_for(self, klass):
#     def get_class_by_name(self, klass):
# 
# Path: sesql/fieldmap.py
# class FieldMap(object):
#     def __init__(self):
#     def all_fields(self):
#     def get_field(self, field):
#     def get_primary(self):


# Path: sesql/index.py
import logging
from sesql import utils
from sesql import config
from sesql import typemap
from sesql import fieldmap

def get_sesql_id(obj):
    """
    Get classname and id, the SeSQL identifiers
    """
    if isinstance(obj, (tuple, list)) and len(obj) == 2:
        return tuple(obj)

    def get_val(field):
        vals = fieldmap.fieldmap[field].get_values(obj)
        return vals and vals[0] or None
    return (get_val('classname'), get_val('id'))

@config.orm.transactional
def schedule_reindex(cursor, item):
    try:
        item = get_sesql_id(item)
    except (TypeError, AttributeError, ValueError):
        log.info("%r: can't get classname/id, skipping" % item)
        return

    classname, objid = item
    table_name = typemap.typemap.get_table_for(classname)
    if not table_name:
        log.info("%s: no table found, skipping" % classname)
        return

    cursor.execute("SELECT nextval('sesql_reindex_id_seq')")
    cursor.execute("INSERT INTO sesql_reindex_schedule (rowid, classname, objid) SELECT currval('sesql_reindex_id_seq'), %s, %s", item)

@index_log_wrap

@config.orm.transactional