예제 #1
0
def main():
  global event_socket
  global mon_ami_server
  global configuration_options

  option_parser = OptionParser()

  # Log options
  option_parser.add_option("--log-file",  action="store", type="string", dest="log_file",  default=None)
  option_parser.add_option("--log-level", action="store", type="int",    dest="log_level", default=5)

  # FreeSWITCH event_socket
  option_parser.add_option("--freeswitch-address",  action="store", type="string", dest="freeswitch_address",  default='127.0.0.1')
  option_parser.add_option("--freeswitch-port",     action="store", type="int",    dest="freeswitch_port",     default=8021)
  option_parser.add_option("--freeswitch-password", action="store", type="string", dest="freeswitch_password", default='ClueCon')

  # Asterisk Manager Interface
  option_parser.add_option("-a", "--address", "--ami-address", action="store", type="string", dest="ami_address", default='0.0.0.0')
  option_parser.add_option("-p", "--port", "--ami-port",       action="store", type="int",    dest="ami_port",    default=5038)

  # User database
  option_parser.add_option("--user-db-name",         action="store", type="string", dest="user_db_name",         default='/opt/GS5/db/development.sqlite3')
  option_parser.add_option("--user-db-table",        action="store", type="string", dest="user_db_table",        default='sip_accounts')
  option_parser.add_option("--user-db-name-row",     action="store", type="string", dest="user_db_name_row",     default='auth_name')
  option_parser.add_option("--user-db-password-row", action="store", type="string", dest="user_db_password_row", default='password')

  # Define common User/Password options
  option_parser.add_option("--user-override-name",     action="store", type="string", dest="user_override_name",     default=None)
  option_parser.add_option("--user-override-password", action="store", type="string", dest="user_override_password", default=None)
  option_parser.add_option("--user-ignore-name",       action="store_true", dest="user_ignore_name",                 default=False)
  option_parser.add_option("--user-ignore-password",   action="store_true", dest="user_ignore_password",             default=False)

  (configuration_options, args) = option_parser.parse_args()

  setup_log(configuration_options.log_file, configuration_options.log_level)
  ldebug('starting MonAMI main process')

  # Catch signals
  signal(SIGHUP,  signal_handler)
  signal(SIGTERM, signal_handler)
  signal(SIGINT, signal_handler)

  # Starting FreeSWITCH event_socket thread
  event_socket = FreeswitchEventSocket(configuration_options.freeswitch_address, configuration_options.freeswitch_port, configuration_options.freeswitch_password)
  event_socket.start()

  if event_socket.isAlive():
    # Starting Asterisk manager thread 
    mon_ami_server = MonAMIServer(configuration_options.ami_address, configuration_options.ami_port, event_socket)
    mon_ami_server.user_password_authentication = user_password_authentication
    mon_ami_server.start()

  while mon_ami_server.isAlive():
    sleep(1)

  if event_socket.isAlive():
    ldebug('killing event_socket thread')
    event_socket.stop()

  ldebug('exiting MonAMI main process')
예제 #2
0
def create_app():
    """create flask-sports app"""

    app = Flask(__name__)

    app.secret_key = '4A8BF09E6732FDC682988A8SYZ666AB7CF53176D08631E'

    config = load_config(CONFIGS['2'])  # 选择环境

    # load logger
    setup_log(config)

    # load config
    app.config.from_object(config)

    # register blueprint
    # app.register_blueprint(test)

    celery_app.init_app(app)  # 注册celery应用
    redis_app.init_app(app)  # 注册redis应用
    sms.init_app(app)  # 注册阿里云短信服务
    signal.init_app(app)  # 注册发送验证码信号
    db.init_app(app)  # 注册mongodb实例
    oss.init_app(app)  # 注册OSS服务

    with app.app_context():
        # 手动推送上下文
        # get_user_model(app) # 注册用户模型表
        pass

    got_request_exception.connect(log_exception, app)  # 记录请求的异常

    return app
예제 #3
0
def _calculate_resources(data, args, resources):
    parallel = clargs.to_parallel(args)
    config = data[0][0]['config']
    config['resources'].update({resources['name']: {'memory': "%sg" % resources['mem'], 'cores': resources['cores']}})
    parallel.update({'progs': [resources['name']]})
    # parallel = log.create_base_logger(config, parallel)
    # log.setup_local_logging(config, parallel)
    log.setup_log(config, parallel)
    dirs = {'work': os.path.abspath(os.getcwd())}
    system.write_info(dirs, parallel, config)
    sysinfo = system.machine_info()[0]
    log.logger.info("Number of items %s" % len(data))
    parallel = res.calculate(parallel, data, sysinfo, config)
    log.logger.info(parallel)
    # print parallel
    # raise
    return parallel
예제 #4
0
def setup(script_name=''):
    Subject.Subject_name
    settings.define_app_options()
    self_dir = os.path.dirname(os.path.abspath(__file__))
    parse_command_line(final=False)
    conf_filename = "server.conf"
    if not options.debug:
        conf_filename = "prod.conf"
    conf_filename = os.path.join(os.path.dirname(self_dir), conf_filename)
    if os.path.exists(conf_filename):
        parse_config_file(conf_filename, final=False)
    else:
        print 'no {} found. skip it'.format(conf_filename)
    parse_command_line(final=True)
    setup_log(options)

    dbs = {}
    for subject in Subject.Subject_name:
        dbs[subject] = MongoClient(options.mongodb_host,
                     replicaSet=options.replica_set)[options[subject+'db_name']]
        print 'Connected to '+subject+'db ', options.mongodb_host

    env = Env
    env.db = dbs
    env.tc = {}
    env.deeprender_host = options.deeprender_host

    env.subject = Subject.get('math')

    if not options.debug:
        channel = logging.StreamHandler(sys.stdout)
        channel.setFormatter(LogFormatter())
        logging.getLogger().addHandler(channel)

    gen_log.info("Env was setup for %s. Subject: %s", script_name, env.subject.zh_name)

    return env
예제 #5
0
def main():
    global event_socket
    global mon_ami_server
    global configuration_options

    option_parser = OptionParser()

    # Log options
    option_parser.add_option("--log-file",
                             action="store",
                             type="string",
                             dest="log_file",
                             default=None)
    option_parser.add_option("--log-level",
                             action="store",
                             type="int",
                             dest="log_level",
                             default=5)

    # FreeSWITCH event_socket
    option_parser.add_option("--freeswitch-address",
                             action="store",
                             type="string",
                             dest="freeswitch_address",
                             default='127.0.0.1')
    option_parser.add_option("--freeswitch-port",
                             action="store",
                             type="int",
                             dest="freeswitch_port",
                             default=8021)
    option_parser.add_option("--freeswitch-password",
                             action="store",
                             type="string",
                             dest="freeswitch_password",
                             default='ClueCon')

    # Asterisk Manager Interface
    option_parser.add_option("-a",
                             "--address",
                             "--ami-address",
                             action="store",
                             type="string",
                             dest="ami_address",
                             default='0.0.0.0')
    option_parser.add_option("-p",
                             "--port",
                             "--ami-port",
                             action="store",
                             type="int",
                             dest="ami_port",
                             default=5038)

    # User database
    option_parser.add_option("--user-db-name",
                             action="store",
                             type="string",
                             dest="user_db_name",
                             default='gemeinschaft')
    option_parser.add_option("--user-db-user",
                             action="store",
                             type="string",
                             dest="user_db_user",
                             default='gemeinschaft')
    option_parser.add_option("--user-db-password",
                             action="store",
                             type="string",
                             dest="user_db_password",
                             default='gemeinschaft')
    option_parser.add_option("--user-db-table",
                             action="store",
                             type="string",
                             dest="user_db_table",
                             default='sip_accounts')
    option_parser.add_option("--user-db-name-row",
                             action="store",
                             type="string",
                             dest="user_db_name_row",
                             default='auth_name')
    option_parser.add_option("--user-db-password-row",
                             action="store",
                             type="string",
                             dest="user_db_password_row",
                             default='password')

    # Define common User/Password options
    option_parser.add_option("--user-override-name",
                             action="store",
                             type="string",
                             dest="user_override_name",
                             default=None)
    option_parser.add_option("--user-override-password",
                             action="store",
                             type="string",
                             dest="user_override_password",
                             default=None)
    option_parser.add_option("--user-ignore-name",
                             action="store_true",
                             dest="user_ignore_name",
                             default=False)
    option_parser.add_option("--user-ignore-password",
                             action="store_true",
                             dest="user_ignore_password",
                             default=False)

    (configuration_options, args) = option_parser.parse_args()

    setup_log(configuration_options.log_file, configuration_options.log_level)
    ldebug('starting MonAMI main process')

    # Catch signals
    signal(SIGHUP, signal_handler)
    signal(SIGTERM, signal_handler)
    signal(SIGINT, signal_handler)

    # Starting FreeSWITCH event_socket thread
    event_socket = FreeswitchEventSocket(
        configuration_options.freeswitch_address,
        configuration_options.freeswitch_port,
        configuration_options.freeswitch_password)
    event_socket.start()

    if event_socket.isAlive():
        # Starting Asterisk manager thread
        mon_ami_server = MonAMIServer(configuration_options.ami_address,
                                      configuration_options.ami_port,
                                      event_socket)
        mon_ami_server.user_password_authentication = user_password_authentication
        mon_ami_server.start()

    while mon_ami_server.isAlive():
        sleep(1)

    if event_socket.isAlive():
        ldebug('killing event_socket thread')
        event_socket.stop()

    ldebug('exiting MonAMI main process')
예제 #6
0
파일: main.py 프로젝트: PW-Sat2/GSControl
    sys.exit(0)


parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url', required=True, help="Slack URL to upload")
parser.add_argument('-g', '--gs', required=True, help="GS Name")
parser.add_argument('-v',
                    '--verbose',
                    action='store_true',
                    help="Verbose / debug mode")

args = parser.parse_args()
slack_url = args.url
gs_name = args.gs

setup_log(args.verbose)
logger = logging.getLogger()

frames_queue = deque()
rcv_dist = ReceiveDistribute(frames_queue)
upload = UploadSlack(frames_queue, slack_url, gs_name)
logger.log(logging.INFO, "Starting Slack Uploader services")
rcv_dist.start()
upload.start()

signal.signal(signal.SIGINT, signal_handler)
print('Press Ctrl+C to finish...')

while True:
    time.sleep(10)
예제 #7
0
# -*- coding:utf-8 -*-
import sys
import util, log
import datetime
import time
from threadpool import ThreadPool
from Queue import Queue
from threading import Thread
from threadpool import Terminate_Watcher

logger_name = 'progressBarLogger'
log.setup_log(logger_name, 'INFO', 'INFO', '/tmp/foo.log')
LOG = log.get_logger(logger_name)

fmt_dl_header = u' Progress Monitor :[%s] | Threads Pool:[%d]\n'
fmt_dl_progress = u' Progress [%d/%d]:'
fmt_dl_last_finished = u'  Latest %d finished tasks:\n'
fmt_dl_failed_jobs = u'  Failed tasks:\n'

fmt_progress = '%s [%s] %.1f%%\n'
SHOW_DONE_NUMBER = 5


class JobStatus:
    """
    An Enum class to indicate the status of a Job
    """
    Waiting = 0
    Running = 1
    Success = 2
    Failed = 3
예제 #8
0
from log import setup_log
setup_log()

import tensorflow as tf
from util import fun, kl_divergence_gauss
import numpy as np
ds = tf.contrib.distributions
import collections
from matplotlib import pyplot as plt

import logging
import sys




_DistrOutput = collections.namedtuple("DistrOutput", ("sample", "params"))

def plot_poiss(v, c):
    v_res = []
    cols = []
    for s_id in xrange(v.shape[1]):
        spikes = np.where(v[:, s_id])[0]
        cols.append(c[spikes])
        v_t = np.asarray([
            spikes, 
            np.tile([s_id], len(spikes))
        ])
        v_res.append(v_t)

    v_res = np.concatenate(v_res, axis=1)
예제 #9
0
import re, os, sys
import datetime
import daemon
import msgpack
import yaml

#Salt lib
import salt.config
import salt.utils.event

#Custom lib
import log as logging
import models

__opts__ = salt.config.client_config("/etc/salt/master")
logging.setup_log(root=__file__, LogDir=logging.options["LogDir"], LogLevel=logging.options["LogLevel"])
LOG = logging.getLogger(__name__)

class ListenEvent(daemon.Daemon):
    def run(self):
        event = salt.utils.event.MasterEvent(__opts__["sock_dir"])
        for eachevent in event.iter_events(full=True):
            if "salt/job/" in eachevent["tag"]:
                data = eachevent["data"]
                if data.has_key("return"):
                    if data["fun"] in [
                            "grains.append",
                            "grains.remove",
                            "grains.setval",
                            "grains.setvals",
                            "grains.items"]:
예제 #10
0
from log import setup_log
setup_log()

import tensorflow as tf
from util import fun, kl_divergence_gauss
import numpy as np
ds = tf.contrib.distributions
import collections
from matplotlib import pyplot as plt

import logging
import sys

_DistrOutput = collections.namedtuple("DistrOutput", ("sample", "params"))


def plot_poiss(v, c):
    v_res = []
    cols = []
    for s_id in xrange(v.shape[1]):
        spikes = np.where(v[:, s_id])[0]
        cols.append(c[spikes])
        v_t = np.asarray([spikes, np.tile([s_id], len(spikes))])
        v_res.append(v_t)

    v_res = np.concatenate(v_res, axis=1)
    cols = np.concatenate(cols)
    plt.scatter(v_res[0, :], v_res[1, :], c=cols)


def sample_mog(batch_size, n_mixture=8, std=0.1, radius=1.0):
예제 #11
0
 def __init__(self, h, w, y, x):
     super(LogBox, self).__init__(h, w, y, x)
     self.title("Logs")
     self.box.keypad(1)
     setup_log(self.box)