def main():
    prefix = dsh_config.lookup('log_file_dir')
    logName = dsh_config.lookup('log_file_name')
    
    dsh_utils.check_logging(prefix, logName)
    dsh_utils.db_print('dsh_test1: entered...', 93)
    
    dsh_agi.read_env()

    testOut1 = prefix + 'test_out1'
    testOut2 = prefix + 'test_tanuja'
    testIn1 = prefix + 'test_in1'
    dsh_agi.say_it(testOut1)
    #dsh_agi.say_it(testOut2)
    #dsh_agi.say_it('/var/lib/asterisk/sounds/demo-congrats')
    dsh_agi.record(testIn1)
    dsh_agi.say_it(testIn1)
    dsh_utils.give_news('dsh_test1: done.')
def main():
    global globals4signal

    globals4signal['start_time'] = datetime.datetime.now()

    #
    # check the voice data directories.
    #
    success,inDir,outDir,outFile = init_dirs()
    if not success:
        sys_exit(1)

    #
    # get the AGI environment variables.
    #
    env = dsh_agi.read_env()
    if env == {}:
        dsh_utils.give_bad_news('dsh_simple1: failed to read agi envs.',
                                logging.error)
        sys_exit(1)

    #
    # log the caller info.
    # and construct a recorded file name based on caller info.
    #
    phoneNumber,callerInfo = lookup_number(env)
    logStr = dsh_map.log_caller_info(phoneNumber, callerInfo)
    globals4signal['log_str'] = logStr
    callerInfoStr = dsh_map.info2str(phoneNumber, callerInfo)
    callerInfoStr = dsh_utils.date_time_rand2() + '_' + callerInfoStr

    #
    # looks like: 090702_200101_38_09935237793_DSH_Randy-Wang.gsm
    #
    dsh_utils.db_print('dsh_simple1: callerInfoStr: ' + callerInfoStr, 94)


    #
    # setting up signal handler for hangup.
    # the handler will attempt to do the file format conversion.
    #
    signal.signal(signal.SIGHUP, hangup_signal_handler)
    

    #
    # play the out file.
    #
    dsh_agi.say_it(outFile)

    #
    # record it.
    #
    inFile = os.path.join(inDir, callerInfoStr)
    globals4signal['in_file'] = inFile
    globals4signal['start_record'] = datetime.datetime.now()
    dsh_agi.record(inFile)

    #
    # say it back.
    #
    #dsh_agi.say_it(inFile)

    dsh_utils.give_news('dsh_simple1: recording done.')

    #
    # convert file format too with a proper hangup (pressing the # key).
    #
    hangup_signal_handler(0, None)
def main():
    global globals4signal

    globals4signal['start_time'] = datetime.datetime.now()

    init_log()

    #
    # find or create unknown org and unknown person.
    #
    try:
        unknownOrg,unknownPerson = init_unknown_org_person()
    except:
        message = 'dsh_django: init_unknown_org_person failed.'
        dsh_utils.give_bad_news(message, logging.critical)
        dsh_agi.report_event(message, reportLevel='CRT')
        sys_exit(1)

    #
    # get the outgoing voice from the database.
    #
    answer = get_outgoing_voice_from_db()
    if not answer:
        sys_exit(1)
    outVobj,outgoingVoice = answer

    #
    # get the AGI environment variables.
    #
    env = dsh_agi.read_env()
    if env == {}:
        dsh_utils.give_bad_news('dsh_django1: failed to read agi envs.',
                                logging.error)
        sys_exit(1)

    #
    # look up the phone number in the django database.
    # if not found in the database, we do something about unknown callers.
    # XXX
    #lookupResult = lookup_number_in_db(env, debugCheat=True)
    lookupResult = lookup_number_in_db(env)
    caller = determine_unknown_caller(unknownOrg, unknownPerson, lookupResult)
    dsh_utils.db_print('dsh_django1: the caller determined to be: ' +
                       repr(caller), 100)
    globals4signal['caller_dude'] = caller
    
    #
    # setting up signal handler for hangup.
    # the handler will attempt to do the file format conversion.
    # and then saving into the django database.
    #
    signal.signal(signal.SIGHUP, hangup_signal_handler)


    #
    # check whether there're any personalized messages for this caller.
    #
    check_personalized_messages(caller)
    
    
    #
    # play the outgoing file.
    #
    # XXX
    dsh_agi.say_it(outgoingVoice)
    time.sleep(1)
    dsh_agi.say_it('beep')
    dsh_agi.say_it('beep')


    #
    # determine the input file name and record it.
    #
    inVobj,incomingFullName=determine_recorded_file_name(caller, outVobj)
    if incomingFullName == None:
        dsh_utils.give_bad_news(
            'dsh_django1: determine_recorded_file_name failed: ',
            logging.critical)
        sys_exit(1)
    dsh_utils.db_print('dsh_django1: incomingFullName: ' + incomingFullName,
                       101)
    globals4signal['db_in_obj'] = inVobj
    globals4signal['start_record'] = datetime.datetime.now()
    globals4signal['in_file'] = incomingFullName
    dsh_agi.record(incomingFullName)
    dsh_utils.db_print('dsh_django1: record call ends.', 101)
    time.sleep(1)
    dsh_utils.give_news('dsh_django1: recording done.')
    dsh_agi.say_it('auth-thankyou')
    dsh_agi.say_it('vm-goodbye')

    #
    # convert file format too with a proper hangup (pressing the # key).
    #
    hangup_signal_handler(0, None)