# Path: model/hlr.py
# def bind_session(connection_string, echo=False):
# def user_data_decode(user_data, data_coding_scheme, ud_hdr_ind):
# def create_sms(src_addr, dest_addr, text, charset=None):
# class Subscriber(Base):
# class Sms(Base):
# 
# Path: model/models.py
# def bind_session(connection_string, echo=False):
# class Measure(Base):
# class Settings(Base):
# 
# Path: com_interface/comms_interface_server.py
# class RequestHandler(SimpleXMLRPCRequestHandler):
# class CommsInterfaceServer(object):
#     def __init__(self, configuration, measure_model, time_to_shutdown_event):
#     def serve_forever(self):
#     def start_new_session(self):
#     def try_run_xmlrpc_server(self):
#     def try_run_vty_client(self):
#     def process_measure_worker(self):
#     def process_measure(self, meas):
#     def get_formated_welcome_message(self, **wargs):
#     def get_formated_reply_message(self, **wargs):
#     def get_last_measure(self, imsi):
#     def save_measure_to_db(self, meas, extension):
#     def __calculate_distance(self, ta):
#     def process_unknown_adress_sms_worker(self):
#     def start_tracking(self):
#     def stop_tracking(self):
#     def tracking_process(self):
#     def prepare_ready_for_silent_sms(self):
#     def vty_send_silent_sms(self, imsi):
#     def send_sms(self, imsi, text):
#     def send_sms_by_phone_number(self, extension, text):


import os
import sys
import time
import datetime
import transaction
from sqlalchemy import engine_from_config
from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
from model.hlr import (
    HLRDBSession,
    Subscriber
    )
from model.models import (
    DBSession,
    Settings,
    Base,
    )
from com_interface.comms_interface_server import (
    pf_subscriber_imsi,
    pf_subscriber_extension,
    pf_subscriber_name
    )
    engine = engine_from_config(settings, 'sqlalchemy.pf.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    hlr_engine = engine_from_config(settings, 'sqlalchemy.hlr.')
    HLRDBSession.configure(bind=hlr_engine)

    # initial settings
    with transaction.manager:
        DBSession.add_all([
            Settings(name='imsiUpdate', value=3000),
            Settings(name='smsUpdate', value=3000),
            Settings(name='silentSms', value=3000),
            Settings(
                name='welcomeMessage',
                value='You are connected to a mobile search and rescue team. ' + \
                      'Please SMS to {ph_phone_number} to communicate. ' + \
                      'Your temporary phone number is {ms_phone_number}'
            ),
            Settings(
                name='replyMessage',
                value='Your SMSs are being sent to a mobile search and rescue team. ' + \
                      'Reply to this message to communicate.'
            ),
        ])

        HLRDBSession.add_all([
            Subscriber(
                created=datetime.datetime.fromtimestamp(time.time()),
                updated=datetime.datetime.fromtimestamp(time.time()),

# Path: model/hlr.py
# def bind_session(connection_string, echo=False):
# def user_data_decode(user_data, data_coding_scheme, ud_hdr_ind):
# def create_sms(src_addr, dest_addr, text, charset=None):
# class Subscriber(Base):
# class Sms(Base):
# 
# Path: model/models.py
# def bind_session(connection_string, echo=False):
# class Measure(Base):
# class Settings(Base):
# 
# Path: com_interface/comms_interface_server.py
# class RequestHandler(SimpleXMLRPCRequestHandler):
# class CommsInterfaceServer(object):
#     def __init__(self, configuration, measure_model, time_to_shutdown_event):
#     def serve_forever(self):
#     def start_new_session(self):
#     def try_run_xmlrpc_server(self):
#     def try_run_vty_client(self):
#     def process_measure_worker(self):
#     def process_measure(self, meas):
#     def get_formated_welcome_message(self, **wargs):
#     def get_formated_reply_message(self, **wargs):
#     def get_last_measure(self, imsi):
#     def save_measure_to_db(self, meas, extension):
#     def __calculate_distance(self, ta):
#     def process_unknown_adress_sms_worker(self):
#     def start_tracking(self):
#     def stop_tracking(self):
#     def tracking_process(self):
#     def prepare_ready_for_silent_sms(self):
#     def vty_send_silent_sms(self, imsi):
#     def send_sms(self, imsi, text):
#     def send_sms_by_phone_number(self, extension, text):


# Path: web/peoplefinder/scripts/initializedb.py
import os
import sys
import time
import datetime
import transaction
from sqlalchemy import engine_from_config
from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
from model.hlr import (
    HLRDBSession,
    Subscriber
    )
from model.models import (
    DBSession,
    Settings,
    Base,
    )
from com_interface.comms_interface_server import (
    pf_subscriber_imsi,
    pf_subscriber_extension,
    pf_subscriber_name
    )

    engine = engine_from_config(settings, 'sqlalchemy.pf.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    hlr_engine = engine_from_config(settings, 'sqlalchemy.hlr.')
    HLRDBSession.configure(bind=hlr_engine)

    # initial settings
    with transaction.manager:
        DBSession.add_all([
            Settings(name='imsiUpdate', value=3000),
            Settings(name='smsUpdate', value=3000),
            Settings(name='silentSms', value=3000),
            Settings(
                name='welcomeMessage',
                value='You are connected to a mobile search and rescue team. ' + \
                      'Please SMS to {ph_phone_number} to communicate. ' + \
                      'Your temporary phone number is {ms_phone_number}'
            ),
            Settings(
                name='replyMessage',
                value='Your SMSs are being sent to a mobile search and rescue team. ' + \
                      'Reply to this message to communicate.'
            ),
        ])

        HLRDBSession.add_all([
            Subscriber(
                created=datetime.datetime.fromtimestamp(time.time()),
                updated=datetime.datetime.fromtimestamp(time.time()),

                imsi=pf_subscriber_imsi,