Ejemplo n.º 1
0
def main():
    global ready

    connect_control.keep_running = True
    config.load()
    connect_manager.https_manager.load_config()

    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)
    # to profile gae_proxy, run proxy.py, visit some web by proxy, then visit http://127.0.0.1:8084/quit to quit and print result.
    do_profile = False
    if do_profile:
        import cProfile, pstats
        pr = cProfile.Profile()
        pr.enable()

    global __file__
    __file__ = os.path.abspath(__file__)
    if os.path.islink(__file__):
        __file__ = getattr(os, 'readlink', lambda x: x)(__file__)
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    #xlog.basicConfig(level=xlog.DEBUG if config.LISTEN_DEBUGINFO else xlog.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]')
    pre_start()
    log_info()

    CertUtil.init_ca()

    proxy_daemon = simple_http_server.HTTPServer(
        (config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer(
            (config.PAC_IP, config.PAC_PORT), pac_server.PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()

    ready = True  # checked by launcher.module_init

    while connect_control.keep_running:
        time.sleep(1)

    xlog.info("Exiting gae_proxy module...")
    proxy_daemon.shutdown()
    proxy_daemon.server_close()
    proxy_thread.join()
    if config.PAC_ENABLE:
        pac_daemon.shutdown()
        pac_daemon.server_close()
        pac_thread.join()
    ready = False  # checked by launcher.module_init
    xlog.debug("## GAEProxy set keep_running: %s",
               connect_control.keep_running)

    if do_profile:
        pr.disable()
        pr.print_stats()
Ejemplo n.º 2
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                data = json.dumps(user_config.user_special, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != user_config.user_special.appid:
                    if appids:
                        fail_appid_list = test_appid.test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            return self.send_response('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid)

                    appid_updated = True
                    user_config.user_special.appid = appids
                user_config.user_special.password = self.postvars['password'][0]
                user_config.user_special.proxy_enable = self.postvars['proxy_enable'][0]
                user_config.user_special.proxy_type = self.postvars['proxy_type'][0]
                user_config.user_special.proxy_host = self.postvars['proxy_host'][0]
                user_config.user_special.proxy_port = self.postvars['proxy_port'][0]
                if not user_config.user_special.proxy_port:
                    user_config.user_special.proxy_port = 0
                user_config.user_special.proxy_user = self.postvars['proxy_user'][0]
                user_config.user_special.proxy_passwd = self.postvars['proxy_passwd'][0]
                user_config.user_special.host_appengine_mode = self.postvars['host_appengine_mode'][0]
                use_ipv6 = int(self.postvars['use_ipv6'][0])
                if user_config.user_special.use_ipv6 != use_ipv6:
                    if use_ipv6:
                        if not check_ip.check_ipv6():
                            xlog.warn("Enable Ipv6 but check failed.")
                            return self.send_response('text/html', '{"res":"fail", "reason":"IPv6 fail"}')

                    user_config.user_special.use_ipv6 = use_ipv6
                user_config.save()

                config.load()
                appid_manager.reset_appid()
                import connect_manager
                connect_manager.load_proxy_config()
                connect_manager.https_manager.load_config()
                if appid_updated:
                    connect_manager.https_manager.clean_old_connection()

                google_ip.reset()
                check_ip.load_proxy_config()

                data = '{"res":"success"}'
                self.send_response('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response('text/html', data)
Ejemplo n.º 3
0
def init_config():
    config.add_search_path("/etc/datadog-unix-agent")
    config.add_search_path(".")
    try:
        config.load()
    finally:
        initialize_logging('dogstatsd')
Ejemplo n.º 4
0
    def req_init_module_handler(self):
        req = urlparse(self.path).query
        reqs = parse_qs(req, keep_blank_values=True)
        data = ''

        try:
            module = reqs['module'][0]
            config.load()

            if reqs['cmd'] == ['start']:
                result = module_init.start(module)
                data = '{ "module": "%s", "cmd": "start", "result": "%s" }' % (
                    module, result)
            elif reqs['cmd'] == ['stop']:
                result = module_init.stop(module)
                data = '{ "module": "%s", "cmd": "stop", "result": "%s" }' % (
                    module, result)
            elif reqs['cmd'] == ['restart']:
                result_stop = module_init.stop(module)
                result_start = module_init.start(module)
                data = '{ "module": "%s", "cmd": "restart", "stop_result": "%s", "start_result": "%s" }' % (
                    module, result_stop, result_start)
        except Exception as e:
            xlog.exception("init_module except:%s", e)

        self.send_response("text/html", data)
Ejemplo n.º 5
0
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)

        config.load()

        self.setFont(QFont("Fixed", 8))

        # set up controls
        # items panel
        self._cardModel = CardModel()
        self._cardModelIndex = QModelIndex()  # current index for card model

        self.setWindowTitle("Mentor")
        self.setWindowIcon(QIcon(QPixmap(":/images/mentor.png")))
        self.setGeometry(config.GUI_GEOMETRY)
        if config.GUI_MAXIMIZED:
            self.setWindowState(Qt.WindowMaximized)

        self.createCentralWidget()
        self.createActions()
        self.createMenus()
        self.createToolbars()
        self.createStatusBar()


        self.propagateFonts(self, QFont("Fixed", 8))

        self.connect(qApp, SIGNAL('aboutToQuit()'), self.qApp_aboutToQuit)

        QTimer.singleShot(0, self._openRecentFile)
Ejemplo n.º 6
0
    def __init(self):        
        # Loaded theme file.
        self.loginfo("Loading application theme...")
        from widget.skin import app_theme        
        
        # Loaded configure.
        self.loginfo("Loading settings...")
        from config import config        
        config.load()
        
        self.__show_splash()

        # Loaded MediaDB.
        self.loginfo("Loading MediaDB...")
        from library import MediaDB
        MediaDB.connect("loaded", self.on_db_loaded)
        MediaDB.load()
        
        # Loaded Chinese to Pinyin DB.
        from pinyin import TransforDB        
        TransforDB.load()        
        
        # initialize Gui
        self.loginfo("Initialize Gui...")
        from widget.instance import DeepinMusic        
        self.app_instance = DeepinMusic()
        self.app_instance.connect("ready", self.on_ready_cb)

        if self.options.StartMinimized:
            self.app_instance.window.iconify()
Ejemplo n.º 7
0
def _config(given):
    if given is None:
        env_config_file = os.getenv('CONJURRC')
        if env_config_file is not None:
            config.load(env_config_file)
        return config
    return given
Ejemplo n.º 8
0
    def __init(self):
        # Loading configure.
        self.loginfo("Loading settings...")
        from config import config
        config.load()

        # Show splash.
        self.__show_splash()

        # Loading theme file.
        self.loginfo("Loading application theme...")
        from widget.skin import app_theme

        # Loading MediaDB.
        self.loginfo("Loading MediaDB...")
        from library import MediaDB
        MediaDB.connect("loaded", self.on_db_loaded)
        MediaDB.load()

        # Loading WebcastDB
        from webcast_library import WebcastDB
        WebcastDB.load()

        # Loading Chinese to Pinyin DB.
        from pinyin import TransforDB
        TransforDB.load()

        # initialize Gui
        self.loginfo("Initialize Gui...")
        from widget.instance import DeepinMusic
        self.app_instance = DeepinMusic()
        self.app_instance.connect("ready", self.on_ready_cb)

        if self.options.StartMinimized:
            self.app_instance.window.iconify()
Ejemplo n.º 9
0
def interpolate(r, g, b):
    from config import config
    low = config.load("positions", "low", [[0, 0], [0, 0], [0, 0]])
    center = config.load("positions", "center", [[0, 0], [0, 0], [0, 0]])
    high = config.load("positions", "high", [[0, 0], [0, 0], [0, 0]])

    xr = [0, r, 255]  # low, center, high
    xg = [0, g, 255]  # low, center, high
    xb = [0, b, 255]  # low, center, high
    p = [low, center, high]
    print(p)
    rr = [p[0][0][0], p[1][0][0], p[2][0][0]]
    rt = [p[0][0][1], p[1][0][1], p[2][0][1]]
    gr = [p[0][1][0], p[1][1][0], p[2][1][0]]
    gt = [p[0][1][1], p[1][1][1], p[2][1][1]]
    br = [p[0][2][0], p[1][2][0], p[2][2][0]]
    bt = [p[0][2][1], p[1][2][1], p[2][2][1]]

    x_new = np.linspace(0, 255, 256)

    frr = interp1d(xr, rr, kind='linear')
    frt = interp1d(xr, rt, kind='linear')
    fgr = interp1d(xg, gr, kind='linear')
    fgt = interp1d(xg, gt, kind='linear')
    fbr = interp1d(xb, br, kind='linear')
    fbt = interp1d(xb, bt, kind='linear')

    yr = [[int(round(r)), int(round(t))]
          for r, t in np.stack((frr(x_new), frt(x_new)), axis=-1)]
    yg = [[int(round(r)), int(round(t))]
          for r, t in np.stack((fgr(x_new), fgt(x_new)), axis=-1)]
    yb = [[int(round(r)), int(round(t))]
          for r, t in np.stack((fbr(x_new), fbt(x_new)), axis=-1)]

    return [[yr[i], yg[i], yb[i]] for i in range(0, 256)]
Ejemplo n.º 10
0
def init_config(do_log=True):
    # init default search path
    config.add_search_path("/etc/datadog-agent")
    config.add_search_path(os.path.join(DEFAULT_PATH, "etc/datadog-agent"))
    config.add_search_path("./etc/datadog-agent")
    config.add_search_path(".")
    try:
        config.load()
    except Exception:
        if do_log:
            initialize_logging('agent')
        raise

    # init log
    if do_log:
        initialize_logging('agent')

    # add file provider
    file_provider = FileConfigProvider()
    file_provider.add_place(
        os.path.join(os.path.dirname(config.get_loaded_config()), 'conf.d'))
    file_provider.add_place(os.path.join(config.get('conf_path'), 'conf.d'))
    file_provider.add_place(config.get('additional_checksd'))
    config.add_provider('file', file_provider)

    # FIXME: perhaps do this elsewhere
    config.collect_check_configs()
Ejemplo n.º 11
0
 def test_010_load_config(self):
     # Load new config file
     config.config_filepath = os.path.join(config.test_dir, 'test-{}-config.json'.format(config.test_id))
     config.load()
     self.assertEqual(config.core['bot']['api'], os.environ['WBHTESTTAPI'],
                      "API didn't match with WBHTESTTAPI environment variable value")
     self.assertEqual(config.BlackHoles[0].telegram_id, os.environ['WBHTESTTID'],
                      "telegram_id of first blackhole didn't match with WBHTESTTID environment variable value")
Ejemplo n.º 12
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()

        elif reqs['cmd'] == ['update']:
            #update ip_range if needed
            content = self.postvars['ip_range'][0]

            #check ip_range checksums, update if needed
            default_digest = hashlib.md5(
                ip_range.load_range_content(default=True)).hexdigest()
            old_digest = hashlib.md5(ip_range.load_range_content()).hexdigest()
            new_digest = hashlib.md5(content).hexdigest()

            if new_digest == default_digest:
                ip_range.remove_user_range()

            else:
                if old_digest != new_digest:
                    ip_range.update_range_content(content)

            if old_digest != new_digest:
                ip_range.load_ip_range()

            #update auto_adjust_scan_ip and scan_ip_thread_num
            should_auto_adjust_scan_ip = int(
                self.postvars['auto_adjust_scan_ip_thread_num'][0])
            thread_num_for_scan_ip = int(
                self.postvars['scan_ip_thread_num'][0])

            use_ipv6 = self.postvars['use_ipv6'][0]
            if user_config.user_special.use_ipv6 != use_ipv6:
                xlog.debug("use_ipv6 change to %s", use_ipv6)
                user_config.user_special.use_ipv6 = use_ipv6

            #update user config settings
            user_config.user_special.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip
            user_config.user_special.scan_ip_thread_num = thread_num_for_scan_ip
            user_config.save()
            config.load()

            #update google_ip settings
            google_ip.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip

            if google_ip.max_scan_ip_thread_num != thread_num_for_scan_ip:
                google_ip.adjust_scan_thread_num(thread_num_for_scan_ip)

            #reponse
            data = '{"res":"success"}'

        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response_nc(mimetype, data)
Ejemplo n.º 13
0
def main():
    arguments = docopt(__doc__, help=True, version=VERSION)
    config_path = arguments['--config']
    keydir = arguments['--keydir']

    config.load(config_path, keydir)

    for host in config.get_hosts():
        process_host(host)
Ejemplo n.º 14
0
def main():
    global ready

    connect_control.keep_running = True
    config.load()
    connect_manager.https_manager.load_config()

    xlog.debug("## GAEProxy set keep_running: %s", connect_control.keep_running)
    # to profile gae_proxy, run proxy.py, visit some web by proxy, then visit http://127.0.0.1:8084/quit to quit and print result.
    do_profile = config.do_profile
    if do_profile:
        import cProfile, pstats
        pr = cProfile.Profile()
        pr.enable()

    global __file__
    __file__ = os.path.abspath(__file__)
    if os.path.islink(__file__):
        __file__ = getattr(os, 'readlink', lambda x: x)(__file__)
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    #xlog.basicConfig(level=xlog.DEBUG if config.LISTEN_DEBUGINFO else xlog.INFO, format='%(levelname)s - %(asctime)s %(message)s', datefmt='[%b %d %H:%M:%S]')
    pre_start()
    log_info()

    CertUtil.init_ca()

    proxy_daemon = simple_http_server.HTTPServer((config.LISTEN_IP, config.LISTEN_PORT), proxy_handler.GAEProxyHandler)
    proxy_thread = threading.Thread(target=proxy_daemon.serve_forever)
    proxy_thread.setDaemon(True)
    proxy_thread.start()

    if config.PAC_ENABLE:
        pac_daemon = simple_http_server.HTTPServer((config.PAC_IP, config.PAC_PORT), pac_server.PACServerHandler)
        pac_thread = threading.Thread(target=pac_daemon.serve_forever)
        pac_thread.setDaemon(True)
        pac_thread.start()

    ready = True  # checked by launcher.module_init

    while connect_control.keep_running:
        time.sleep(1)

    xlog.info("Exiting gae_proxy module...")
    proxy_daemon.shutdown()
    proxy_daemon.server_close()
    proxy_thread.join()
    if config.PAC_ENABLE:
        pac_daemon.shutdown()
        pac_daemon.server_close()
        pac_thread.join()
    ready = False  # checked by launcher.module_init
    xlog.debug("## GAEProxy set keep_running: %s", connect_control.keep_running)

    if do_profile:
        pr.disable()
        pr.print_stats()
Ejemplo n.º 15
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()

        elif reqs['cmd'] == ['update']:
            #update ip_range if needed
            content = self.postvars['ip_range'][0]

            #check ip_range checksums, update if needed
            default_digest = hashlib.md5(ip_range.load_range_content(default=True)).hexdigest()
            old_digest = hashlib.md5(ip_range.load_range_content()).hexdigest()
            new_digest = hashlib.md5(content).hexdigest()

            if new_digest == default_digest:
                ip_range.remove_user_range()

            else:
                if old_digest != new_digest:
                    ip_range.update_range_content(content)

            if old_digest != new_digest:
                ip_range.load_ip_range()

            #update auto_adjust_scan_ip and scan_ip_thread_num
            should_auto_adjust_scan_ip = int(self.postvars['auto_adjust_scan_ip_thread_num'][0])
            thread_num_for_scan_ip = int(self.postvars['scan_ip_thread_num'][0])

            use_ipv6 = self.postvars['use_ipv6'][0]
            if user_config.user_special.use_ipv6 != use_ipv6:
                xlog.debug("use_ipv6 change to %s", use_ipv6)
                user_config.user_special.use_ipv6 = use_ipv6

            #update user config settings
            user_config.user_special.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip
            user_config.user_special.scan_ip_thread_num = thread_num_for_scan_ip
            user_config.save()
            config.load()

            #update google_ip settings
            google_ip.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip

            if google_ip.max_scan_ip_thread_num != thread_num_for_scan_ip:
                google_ip.adjust_scan_thread_num(thread_num_for_scan_ip)

            #reponse 
            data='{"res":"success"}'

        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response_nc(mimetype, data)
Ejemplo n.º 16
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                ret_config = {
                    "appid": "|".join(config.GAE_APPIDS),
                    "auto_adjust_scan_ip_thread_num":
                    config.auto_adjust_scan_ip_thread_num,
                    "scan_ip_thread_num": config.max_scan_ip_thread_num,
                    "use_ipv6": config.use_ipv6
                }
                data = json.dumps(ret_config, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != "|".join(config.GAE_APPIDS):
                    if appids and (front.ip_manager.good_ipv4_num +
                                   front.ip_manager.good_ipv6_num):
                        fail_appid_list = test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            return self.send_response_nc(
                                'text/html',
                                '{"res":"fail", "reason":"appid fail:%s"}' %
                                fail_appid)

                    appid_updated = True
                    if appids:
                        xlog.info("set appids:%s", appids)
                        config.GAE_APPIDS = appids.split("|")
                    else:
                        config.GAE_APPIDS = []

                config.save()

                config.load()
                front.appid_manager.reset_appid()
                if appid_updated:
                    front.http_dispatcher.close_all_worker()

                front.ip_manager.reset()

                data = '{"res":"success"}'
                self.send_response_nc('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response_nc('text/html', data)
Ejemplo n.º 17
0
    def setup_config(self, filename=None):
        """Loads the configuration and makes sure it is processed.

        Arguments:
            filename    The relative path (from project directory) of a
                        configuration file.
        """
        if not filename is None:
            cfg = config.load(varargs=None, filename=filename)
        else:
            cfg = config.load(varargs=None)
        self._cfg = cfg
Ejemplo n.º 18
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        try:
            if reqs['cmd'] == ['get_config']:
                data = json.dumps(user_config.user_special,
                                  default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                user_config.user_special.appid = self.postvars['appid'][0]
                user_config.user_special.password = self.postvars['password'][
                    0]
                user_config.user_special.proxy_enable = self.postvars[
                    'proxy_enable'][0]
                user_config.user_special.proxy_type = self.postvars[
                    'proxy_type'][0]
                user_config.user_special.proxy_host = self.postvars[
                    'proxy_host'][0]
                user_config.user_special.proxy_port = self.postvars[
                    'proxy_port'][0]
                user_config.user_special.proxy_user = self.postvars[
                    'proxy_user'][0]
                user_config.user_special.proxy_passwd = self.postvars[
                    'proxy_passwd'][0]
                user_config.user_special.host_appengine_mode = self.postvars[
                    'host_appengine_mode'][0]
                user_config.user_special.ip_connect_interval = int(
                    self.postvars['ip_connect_interval'][0])
                user_config.user_special.use_ipv6 = int(
                    self.postvars['use_ipv6'][0])
                user_config.user_special.connect_interval = int(
                    self.postvars['connect_interval'][0])
                user_config.save()

                config.load()
                appid_manager.reset_appid()
                import connect_manager
                connect_manager.load_sock()
                connect_manager.https_manager.load_config()
                connect_manager.forwork_manager.load_config()

                google_ip.load_config()
                check_ip.load_sock()

                data = '{"res":"success"}'
                self.send_response('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response('text/html', data)
Ejemplo n.º 19
0
    def setup_config(self, filename=None):
        """Loads the configuration and makes sure it is processed.

        Arguments:
            filename    The relative path (from project directory) of a
                        configuration file.
        """
        if not filename is None:
            cfg = config.load(varargs=None, filename=filename)
        else:
            cfg = config.load(varargs=None)
        self._cfg = cfg
Ejemplo n.º 20
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                data = json.dumps(user_config.user_special, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != user_config.user_special.appid:
                    user_config.user_special.appid = appids

                user_config.user_special.proxy_enable = self.postvars['proxy_enable'][0]
                user_config.user_special.proxy_type = self.postvars['proxy_type'][0]
                user_config.user_special.proxy_host = self.postvars['proxy_host'][0]
                user_config.user_special.proxy_port = self.postvars['proxy_port'][0]
                try:
                    user_config.user_special.proxy_port = int(user_config.user_special.proxy_port)
                except:
                    user_config.user_special.proxy_port = 0

                user_config.user_special.proxy_user = self.postvars['proxy_user'][0]
                user_config.user_special.proxy_passwd = self.postvars['proxy_passwd'][0]
                user_config.user_special.host_appengine_mode = self.postvars['host_appengine_mode'][0]

                use_ipv6 = int(self.postvars['use_ipv6'][0])
                if user_config.user_special.use_ipv6 != use_ipv6:
                    if use_ipv6:
                        if not check_local_network.check_ipv6():
                            xlog.warn("IPv6 was enabled, but check failed.")
                            return self.send_response_nc('text/html', '{"res":"fail", "reason":"IPv6 fail"}')

                    user_config.user_special.use_ipv6 = use_ipv6

                user_config.save()

                config.load()

                ip_manager.reset()
                check_ip.load_proxy_config()

                data = '{"res":"success"}'
                self.send_response_nc('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response_nc('text/html', data)
def init_config():
    config.add_search_path("/etc/datadog-agent")
    config.add_search_path(os.path.join(DEFAULT_PATH, "etc/datadog-agent"))
    config.add_search_path("./etc/datadog-agent")
    config.add_search_path(".")
    try:
        config.load()
        config.add_search_path(config.get('conf_path'))

        #  load again
        config.load()
    finally:
        initialize_logging('dogstatsd')
Ejemplo n.º 22
0
class SubMenu(MainMenu):
    choices = []
    default_color = pg.Color(40, 40, 40)

    rts = [
        config.load("positions", "offset", [[0, 0], [0, 0], [0, 0]]),
        config.load("positions", "sidebyside", [[0, 0], [0, 0], [0, 0]])
    ]

    def __init__(self):
        super(SubMenu, self).__init__()
        self.logo = LOGO.WHITE
        self.background = pg.Color("white")
Ejemplo n.º 23
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                ret_config = {
                    "appid": "|".join(config.GAE_APPIDS),
                    "auto_adjust_scan_ip_thread_num": config.auto_adjust_scan_ip_thread_num,
                    "scan_ip_thread_num": config.max_scan_ip_thread_num,
                    "use_ipv6": config.use_ipv6
                }
                data = json.dumps(ret_config, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != "|".join(config.GAE_APPIDS):
                    if appids and (front.ip_manager.good_ipv4_num + front.ip_manager.good_ipv6_num):
                        fail_appid_list = test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            return self.send_response_nc('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid)

                    appid_updated = True
                    if appids:
                        xlog.info("set appids:%s", appids)
                        config.GAE_APPIDS = appids.split("|")
                    else:
                        config.GAE_APPIDS = []

                config.save()

                config.load()
                front.appid_manager.reset_appid()
                if appid_updated:
                    front.http_dispatcher.close_all_worker()

                front.ip_manager.reset()

                data = '{"res":"success"}'
                self.send_response_nc('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response_nc('text/html', data)
Ejemplo n.º 24
0
def main(args):
    args = _parse_arguments(args)
    repo_root = common.get_repo_root(args.repo_root)
    cfg = config.load(repo_root, args.verbose)
    pom_content = pomcontentm.PomContent()
    if args.pom_description is not None:
        pom_content.description = args.pom_description
    if args.verbose:
        logger.debug("Global pom content: %s" % pom_content)

    mvn_install_info = maveninstallinfo.MavenInstallInfo(
        cfg.maven_install_paths)
    ws = workspace.Workspace(repo_root, cfg.excluded_dependency_paths,
                             cfg.all_src_exclusions, mvn_install_info,
                             pom_content)
    packages = argsupport.get_all_packages(repo_root, args.package)
    packages = ws.filter_artifact_producing_packages(packages)
    if len(packages) == 0:
        raise Exception(
            "Did not find any artifact producing BUILD.pom packages at [%s]" %
            args.package)
    spider = crawler.Crawler(ws, cfg.pom_template, args.verbose)
    result = spider.crawl(packages,
                          follow_monorepo_references=args.recursive,
                          force_release=args.force)

    if len(result.pomgens) == 0:
        logger.info(
            "No releases are required. pomgen will not generate any pom files. To force pom generation, use pomgen's --force option."
        )
    else:
        output_dir = _get_output_dir(args)

        for pomgen in result.pomgens:
            pom_dest_dir = os.path.join(output_dir, pomgen.bazel_package)
            if not os.path.exists(pom_dest_dir):
                os.makedirs(pom_dest_dir)

            # the goldfile pom is actually a pomgen metadata file, so we
            # write it using the mdfiles module, which ensures it goes
            # into the proper location within the specified bazel package
            if args.pom_goldfile:
                pom_content = pomgen.gen(pom.PomContentType.GOLDFILE)
                pom_goldfile_path = mdfiles.write_file(
                    pom_content, output_dir, pomgen.bazel_package,
                    mdfiles.POM_XML_RELEASED_FILE_NAME)
                logger.info("Wrote pom goldfile to [%s]" % pom_goldfile_path)
            else:
                pom_content = pomgen.gen(pom.PomContentType.RELEASE)
                pom_path = os.path.join(pom_dest_dir, "pom.xml")
                _write_file(pom_path, pom_content)
                logger.info("Wrote pom file to [%s]" % pom_path)
                for i, companion_pomgen in enumerate(
                        pomgen.get_companion_generators()):
                    pom_content = companion_pomgen.gen(
                        pom.PomContentType.RELEASE)
                    pom_path = os.path.join(pom_dest_dir,
                                            "pom_companion%s.xml" % i)
                    _write_file(pom_path, pom_content)
                    logger.info("Wrote companion pom file to [%s]" % pom_path)
Ejemplo n.º 25
0
 def startup(self, persistent):
     self.rt = config.load("positions", "offset",
                           [[[0, 0], [0, 0], [0, 0]]])
     self.persist = persistent
     dmx.send_rgb(255, 255, 255)
     dmx.send_rt(*self.rt)
     self.active_choice = 0
Ejemplo n.º 26
0
def main():
    class HelpExit(Exception): pass

    verbose = False
    try:
        opt_parser = parser()
        opt_parser.remove_option("--label")
        opt_parser.remove_option("--sub-label")
        opt_parser.remove_option("-s")
        opt_parser.remove_option("--log")
        opt_parser.remove_option("--bg-error")
        opt_parser.add_option("--theta-prefix",
                              action="store", default="el",
                              help="theta plots prefix")
        opt_parser.add_option("--theta-postfix",
                              action="store", default="",
                              help="theta plots postfix")
        opt_parser.add_option('-o', "--output",
                              action='store', default='theta_input.root',
                              help="output filename")

        options, args = opt_parser.parse_args()

        # load application configuration
        #
        if not options.config:
            raise RuntimeError("application configuration is not specified")

        config_ = config.load(os.path.expanduser(options.config))
        verbose = (options.verbose if options.verbose
                   else config_["core"]["verbose"])

        if verbose:
            print("loaded configuration from:", options.config)

        if 1 == len(sys.argv):
            raise HelpExit()

        # import templates only here otherwise PyROOT inhercepts --help option
        import theta.templates

        app = theta.templates.Input(options, args, config_)
        app.run()
    except HelpExit:
        opt_parser.print_help()

        return 0
    except Exception as error:
        if verbose:
            # print Exception traceback for debug
            import traceback

            traceback.print_tb(sys.exc_info()[2])

        print(error, file=sys.stderr)

        return 1
    else:
        return 0
Ejemplo n.º 27
0
    def test_pom_template(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "pom")
        self._write_pomgenrc(repo_root, pom_template_path, ext_deps_path="")

        cfg = config.load(repo_root)

        self.assertEqual("pom", cfg.pom_template)
Ejemplo n.º 28
0
    def test_maven_install_paths(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        self._write_pomgenrc(repo_root, pom_template_path, "eternal,world")

        cfg = config.load(repo_root)

        self.assertEqual(("eternal", "world"), cfg.maven_install_paths)
Ejemplo n.º 29
0
 def startup(self, persistent):
     self.persist = persistent
     self.title = self.persist["choice"]
     self.rt = config.load("positions", self.conf,
                           [[0, 0], [0, 0], [0, 0]])  # rotation & tilt
     dmx.send_rgb(255, 255, 255)
     dmx.send_rt(*self.rt)
     self.back = "CALIBRATE"
Ejemplo n.º 30
0
    def test_maven_install_paths_default(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        self._write_pomgenrc(repo_root, pom_template_path, None)

        cfg = config.load(repo_root)

        self.assertEqual(("maven_install.json", ), cfg.maven_install_paths)
Ejemplo n.º 31
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                data = json.dumps(user_config.user_special,
                                  default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != user_config.user_special.appid:
                    if appids and (google_ip.good_ipv4_num +
                                   google_ip.good_ipv6_num):
                        fail_appid_list = test_appid.test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            return self.send_response_nc(
                                'text/html',
                                '{"res":"fail", "reason":"appid fail:%s"}' %
                                fail_appid)

                    appid_updated = True
                    user_config.user_special.appid = appids

                user_config.save()

                config.load()
                appid_manager.reset_appid()
                import connect_manager
                connect_manager.https_manager.load_config()
                if appid_updated:
                    http_dispatch.close_all_worker()

                google_ip.reset()

                data = '{"res":"success"}'
                self.send_response_nc('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response_nc('text/html', data)
Ejemplo n.º 32
0
    def test_external_dependencies__single_file(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        ext_deps_path = self._write_file(repo_root, "ext_deps", "abc")
        self._write_pomgenrc(repo_root, pom_template_path, ext_deps_path)

        cfg = config.load(repo_root)

        self.assertEqual("abc\n", cfg.external_dependencies)
Ejemplo n.º 33
0
def set_proxy(args):
    xlog.info("set_proxy:%s", args)

    user_config.user_special.proxy_enable = args["enable"]
    user_config.user_special.proxy_type = args["type"]
    user_config.user_special.proxy_host = args["host"]
    try:
        user_config.user_special.proxy_port = int(args["port"])
    except:
        user_config.user_special.proxy_port = 0

    user_config.user_special.proxy_user = args["user"]
    user_config.user_special.proxy_passwd = args["passwd"]

    user_config.save()
    config.load()

    check_ip.load_proxy_config()
Ejemplo n.º 34
0
def init_agent():
    # init default search path
    config.add_search_path("/etc/datadog-unix-agent")
    config.add_search_path(".")
    config.load()

    # init log
    level = logging.getLevelName(config.get("log_level").upper())
    logging.basicConfig(level=level)

    # add file provider
    file_provider = FileConfigProvider()
    file_provider.add_place(config.get('additional_checksd'))
    config.add_provider('file', file_provider)

    # FIXME: do this elsewhere
    # collect config
    config.collect_check_configs()
Ejemplo n.º 35
0
    def test_str(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        self._write_pomgenrc(repo_root, pom_template_path, "maven, misc")

        cfg = config.load(repo_root)

        self.assertIn("pom_template_path=%s" % pom_template_path, str(cfg))
        self.assertIn("maven_install_paths=('maven', 'misc')", str(cfg))
Ejemplo n.º 36
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""

        try:
            if reqs["cmd"] == ["get_config"]:
                data = json.dumps(user_config.user_special, default=lambda o: o.__dict__)
            elif reqs["cmd"] == ["set_config"]:
                user_config.user_special.appid = self.postvars["appid"][0]
                user_config.user_special.password = self.postvars["password"][0]
                user_config.user_special.proxy_enable = self.postvars["proxy_enable"][0]
                user_config.user_special.proxy_type = self.postvars["proxy_type"][0]
                user_config.user_special.proxy_host = self.postvars["proxy_host"][0]
                user_config.user_special.proxy_port = self.postvars["proxy_port"][0]
                user_config.user_special.proxy_user = self.postvars["proxy_user"][0]
                user_config.user_special.proxy_passwd = self.postvars["proxy_passwd"][0]
                user_config.user_special.host_appengine_mode = self.postvars["host_appengine_mode"][0]
                user_config.user_special.ip_connect_interval = int(self.postvars["ip_connect_interval"][0])
                user_config.user_special.use_ipv6 = int(self.postvars["use_ipv6"][0])
                user_config.user_special.connect_interval = int(self.postvars["connect_interval"][0])
                user_config.save()

                config.load()
                appid_manager.reset_appid()
                import connect_manager

                connect_manager.load_proxy_config()
                connect_manager.https_manager.load_config()
                connect_manager.forwork_manager.load_config()

                google_ip.reset()
                check_ip.load_proxy_config()

                data = '{"res":"success"}'
                self.send_response("text/html", data)
                # http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response("text/html", data)
Ejemplo n.º 37
0
    def __init__(self):
        super(LyricBoard, self).__init__()
        # self.fontdes = pango.FontDescription(fontdes)
        self.connect("expose_event", self.on_expose)
        
        # 不是同一个config
        # self.config = Config()
        # self.config.load()      # 读入
        
        config.load()           # 先读入,不然什么都找不到
        # config.connect("config-changed", self.draw)
        config.connect("config-changed", self.get_font_and_bgcolor)
        
        # --------------- logger --------------
        self.logger = logging.getLogger("lyricboard")
        # 低于level的log会被抛弃
        self.logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter("%(levelname)-8s %(message)s")
        handler = logging.StreamHandler()        
        handler.setFormatter(formatter)
        
        # add some handler to log
        self.logger.addHandler(handler)

        handler = logging.FileHandler('lyricboard', 'w')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

        # self.logger.debug("hello world")        

        # 初始化字体和颜色
        self.get_font_and_bgcolor()   

        # 定时滚动歌词
        gobject.timeout_add(1000, self.on_time_out)
        self.time_count = 0

        # 当前播放时刻,定时查询
        self.current_play_time = None
        self.current_lyric = None
        self.current_linecount = None
        self.lyrictext = parser.text        
Ejemplo n.º 38
0
def main(args):
    args = _parse_arguments(args)
    repo_root = common.get_repo_root(args.repo_root)    
    cfg = config.load(repo_root)
    mvn_install_info = maveninstallinfo.MavenInstallInfo(cfg.maven_install_paths)    
    ws = workspace.Workspace(repo_root, 
                             cfg.excluded_dependency_paths,
                             cfg.all_src_exclusions,
                             mvn_install_info,
                             pomcontent.NOOP)

    group_id = "all_ext_deps_group" if args.group_id is None else args.group_id
    artifact_id = "all_ext_deps_art" if args.artifact_id is None else args.artifact_id
    version = "0.0.1-SNAPSHOT" if args.version is None else args.version
    
    artifact_def = buildpom.MavenArtifactDef(group_id=group_id,
                                             artifact_id=artifact_id,
                                             version=version)

    if args.stdin:
        dep_labels = set() # we want to de-dupe labels
        dependencies = []
        for line in sys.stdin:
            line = line.strip()
            if len(line) == 0:
                continue
            if not line.startswith("@"):
                continue
            if _starts_with_ignored_prefix(line):
                continue
            dep_labels.add(line)
        dependencies = ws.parse_dep_labels(dep_labels)
    else:
        dependencies = list(ws.name_to_external_dependencies.values())

    # note that it is possible to end up with duplicate dependencies
    # because different labels may point to the same dependency (gav)
    # (for ex: @maven//:org_antlr_ST4 and @antlr//:org_antlr_ST4)
    # however those indentical gavs may have distinct exclusions
    dependencies.sort()

    if args.exclude_all_transitives:
        # ignore what was specified in the pinned dependencies files
        # and add an "exclude all" dependency for all dependencies that
        # will end up in the generated pom
        ws.dependency_metadata.clear()
        for dep in dependencies:
            ws.dependency_metadata.register_exclusions(
                dep, [dependency.EXCLUDE_ALL_PLACEHOLDER_DEP])

    pomgen = ThirdPartyDepsPomGen(ws, artifact_def, dependencies,
                                  cfg.pom_template)
    pomgen.process_dependencies()
    return pomgen.gen(pom.PomContentType.RELEASE)
Ejemplo n.º 39
0
    def __init__(self, title, parent):

        gtk.Window.__init__(self)
        self.set_title(title)
        self.set_resizable(False)
        # self.set_size_request(200, 200)
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.set_border_width(12)
        self.set_property("skip-taskbar-hint", True)        

        # 禁止跟同一类应用的其他窗口交互
        # Modal windows prevent interaction with other
        # windows in the same application
        self.set_modal(True)
        self.set_transient_for(parent)

        btn = gtk.Button(stock=gtk.STOCK_CLOSE)
        btn.connect("clicked", self.on_destroy)
        box_btn = gtk.HBox()
        box_btn.pack_end(btn, False, False)
        
        self.main_vbox = gtk.VBox(spacing = 6)
        
        gtk.Window.add(self, gtk.VBox(spacing=12))
        self.child.pack_start(self.main_vbox)
        self.child.pack_start(box_btn)        

        self.notebook = gtk.Notebook()
        self.add(self.notebook)
        
        self.lyric_page = self.make_lyric_page()
        self.notebook.append_page(self.lyric_page, self.make_tab("lyric", gtk.STOCK_PREFERENCES))        

        self.connect("delete-event", self.on_destroy)
        self.show_all()

        self.font_info = None
        self.bg_color = None        

        
        config.load()      # 先读入,改变时重写回去
Ejemplo n.º 40
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                data = json.dumps(user_config.user_special, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != user_config.user_special.appid:
                    if appids and (google_ip.good_ipv4_num + google_ip.good_ipv6_num):
                        fail_appid_list = test_appid.test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            return self.send_response_nc('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid)

                    appid_updated = True
                    user_config.user_special.appid = appids

                user_config.save()

                config.load()
                appid_manager.reset_appid()
                import connect_manager
                connect_manager.https_manager.load_config()
                if appid_updated:
                    http_dispatch.close_all_worker()

                google_ip.reset()

                data = '{"res":"success"}'
                self.send_response_nc('text/html', data)
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
                return
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        self.send_response_nc('text/html', data)
Ejemplo n.º 41
0
    def __init__(self, tmpdir, config_dir, scheduler=None):
        self.next_client_id = 0
        self.clients = []
        self.jobs = []
        self._delayed_jobs = {}
        self._timer = kaa.OneShotTimer(self.step)
        self._ipc = kaa.rpc.Server(os.path.join(tmpdir, 'socket'))
        self._ipc.signals['client-connected'].connect(self.client_connect)
        self._ipc.register(self)

        # Load configuration for scheduler settings.  We sync the config file
        # if necessary here instead of Server beacon-daemon forks and starts
        # Thumbnailer first.  If we synced in Server instead, because we are
        # watching the config, we'd get notified of the change if the config
        # needed syncing, causing us to revert any run-time scheduler change.
        config.load(os.path.join(config_dir, 'config'), sync=True)
        config.watch()
        if scheduler:
            config.scheduler.policy = scheduler

        # video module
        self.videothumb = VideoThumb(self, config)
Ejemplo n.º 42
0
    def test_external_dependencies__multiple_files(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        ext_deps_p1 = self._write_file(repo_root, "ext_deps1", "abc")
        ext_deps_p2 = self._write_file(repo_root, "ext_deps2", "def")
        ext_deps_p3 = self._write_file(repo_root, "ext_deps3", "ghi")
        self._write_pomgenrc(
            repo_root, pom_template_path,
            "%s,%s,%s" % (ext_deps_p1, ext_deps_p2, ext_deps_p3))

        cfg = config.load(repo_root)

        self.assertEqual("abc\ndef\nghi\n", cfg.external_dependencies)
Ejemplo n.º 43
0
    def __init__(self, tmpdir, config_dir, scheduler=None):
        self.next_client_id = 0
        self.clients = []
        self.jobs = []
        self._delayed_jobs = {}
        self._timer = kaa.OneShotTimer(self.step)
        self._ipc = kaa.rpc.Server(os.path.join(tmpdir, 'socket'))
        self._ipc.signals['client-connected'].connect(self.client_connect)
        self._ipc.register(self)

        # Load configuration for scheduler settings.  We sync the config file
        # if necessary here instead of Server beacon-daemon forks and starts
        # Thumbnailer first.  If we synced in Server instead, because we are
        # watching the config, we'd get notified of the change if the config
        # needed syncing, causing us to revert any run-time scheduler change.
        config.load(os.path.join(config_dir, 'config'), sync=True)
        config.watch()
        if scheduler:
            config.scheduler.policy = scheduler

        # video module
        self.videothumb = VideoThumb(self, config)
Ejemplo n.º 44
0
    def test_str(self):
        repo_root = tempfile.mkdtemp("root")
        pom_template_path = self._write_file(repo_root, "pom_template", "foo")
        ext_deps_p1 = self._write_file(repo_root, "ext_deps1", "abc")
        ext_deps_p2 = self._write_file(repo_root, "ext_deps2", "def")
        self._write_pomgenrc(repo_root, pom_template_path,
                             "%s,%s" % (ext_deps_p1, ext_deps_p2))

        cfg = config.load(repo_root)

        self.assertIn("pom_template_path=%s" % pom_template_path, str(cfg))
        self.assertIn(
            "external_dependencies_path=%s,%s" % (ext_deps_p1, ext_deps_p2),
            str(cfg))
Ejemplo n.º 45
0
def main():
    class HelpExit(Exception): pass

    verbose = False
    try:
        opt_parser = parser()
        #opt_parser.remove_option("--plots")
        opt_parser.remove_option("--bg-error")
        options, args = opt_parser.parse_args()

        # load application configuration
        #
        if not options.config:
            raise RuntimeError("application configuration is not specified")

        config_ = config.load(os.path.expanduser(options.config))
        verbose = (options.verbose if options.verbose
                   else config_["core"]["verbose"])

        if verbose:
            print("loaded configuration from:", options.config)

        if 1 == len(sys.argv):
            raise HelpExit()

        # import templates only here otherwise PyROOT inhercepts --help option
        from electron_id import templates

        if not options.plots:
            options.plots = "/electron_no_id/{pt,eta}:/el_id_?/{pt,eta}"

        app = templates.ElectronIDEfficiency(options, args, config_)
        app.run()
    except HelpExit:
        opt_parser.print_help()

        return 0
    except Exception as error:
        if verbose:
            # print Exception traceback for debug
            import traceback

            traceback.print_tb(sys.exc_info()[2])

        print(error, file=sys.stderr)

        return 1
    else:
        return 0
Ejemplo n.º 46
0
def main():
    class HelpExit(Exception): pass

    verbose = False
    try:
        opt_parser = parser()

        opt_parser.add_option("--tff-input", action='store',
                              default=None,
                              help='run TFractionFitter on specific plot')

        options, args = opt_parser.parse_args()

        # load application configuration
        #
        if not options.config:
            raise RuntimeError("application configuration is not specified")

        config_ = config.load(os.path.expanduser(options.config))
        verbose = (options.verbose if options.verbose
                   else config_["core"]["verbose"])

        if verbose:
            print("loaded configuration from:", options.config)

        if 1 == len(sys.argv):
            raise HelpExit()

        # import templates only here otherwise PyROOT inhercepts --help option
        from preselection import templates

        app = templates.Templates(options, args, config_)
        app.run()
    except HelpExit:
        opt_parser.print_help()

        return 0
    except Exception as error:
        if verbose:
            # print Exception traceback for debug
            import traceback

            traceback.print_tb(sys.exc_info()[2])

        print(error, file=sys.stderr)

        return 1
    else:
        return 0
Ejemplo n.º 47
0
def main():
    class HelpExit(Exception): pass

    verbose = False
    try:
        opt_parser = parser()
        options, args = opt_parser.parse_args()

        # load application configuration
        #
        if not options.config:
            raise RuntimeError("application configuration is not specified")

        config_ = config.load(os.path.expanduser(options.config))
        verbose = (options.verbose if options.verbose
                   else config_["core"]["verbose"])

        if verbose:
            print("loaded configuration from:", options.config)

        if 1 == len(sys.argv):
            raise HelpExit()

        # import templates only here otherwise PyROOT inhercepts --help option
        from mc_stat import templates

        options.plots = "/mttbar_after_htlep"
        app = templates.Templates(options, args, config_)
        app.run()
    except HelpExit:
        opt_parser.print_help()

        return 0
    except Exception as error:
        if verbose:
            # print Exception traceback for debug
            import traceback

            traceback.print_tb(sys.exc_info()[2])

        print(error, file=sys.stderr)

        return 1
    else:
        return 0
Ejemplo n.º 48
0
          'Environment :: Graphic',
          'Environment :: Qt',
          'Intended Audience :: End Users/Desktop',
          'Intended Audience :: Photographs',
          'License :: OSI Approved :: GPL',
          'Operating System :: MacOS :: MacOS X',
          'Operating System :: Microsoft :: Windows',
          'Operating System :: POSIX',
          'Programming Language :: Python',
          ],)
os.remove("imagizer.conf")

if not configured:
    sys.path.insert(0,"imagizer-src")
    from config import config
    config.load(ConfFile)
    while True:
        print "Enter le chemin du repertoire racine du serveur WEB :"
        config.WebRepository = raw_input("[%s] :" % config.WebRepository)
        if(os.path.isdir(config.WebRepository)):
            break
        print "No Such Directory"
    config.Locale, config.Coding = locale.getdefaultlocale()
    LANG = os.getenv("LANG")
    if LANG:
        config.Locale = LANG
    config.printConfig()
    config.save("/etc/imagizer.conf")
    print "Configuration finished .... Saving it\nYou can modify it in /etc/imagizer.conf"

    try:
Ejemplo n.º 49
0
 def load(self, raws, *args, **kwargs):
     '''
         Configure a session object given arguments to specify configuration
         loading behavior.
     '''
     self.configure(raws, config.load(*args, **kwargs))
Ejemplo n.º 50
0
    def req_config_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ''

        appid_updated = False

        try:
            if reqs['cmd'] == ['get_config']:
                ret_config = {
                    "appid": "|".join(config.GAE_APPIDS),
                    "auto_adjust_scan_ip_thread_num": config.auto_adjust_scan_ip_thread_num,
                    "scan_ip_thread_num": config.max_scan_ip_thread_num,
                    "use_ipv6": config.use_ipv6,
                    "setting_level": config.setting_level,
                    "connect_receive_buffer": config.connect_receive_buffer,
                }
                data = json.dumps(ret_config, default=lambda o: o.__dict__)
            elif reqs['cmd'] == ['set_config']:
                appids = self.postvars['appid'][0]
                if appids != "|".join(config.GAE_APPIDS):
                    if appids and (front.ip_manager.good_ipv4_num + front.ip_manager.good_ipv6_num):
                        fail_appid_list = test_appids(appids)
                        if len(fail_appid_list):
                            fail_appid = "|".join(fail_appid_list)
                            data = json.dumps({"res": "fail",
                                               "reason": "appid fail:" + fail_appid
                                               })
                            return

                    appid_updated = True
                    if appids:
                        xlog.info("set appids:%s", appids)
                        config.GAE_APPIDS = appids.split("|")
                    else:
                        config.GAE_APPIDS = []

                config.save()

                config.load()
                front.appid_manager.reset_appid()
                if appid_updated:
                    front.http_dispatcher.close_all_worker()

                front.ip_manager.reset()

                data = '{"res":"success"}'
                #http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
            elif reqs['cmd'] == ['set_config_level']:
                setting_level = self.postvars['setting_level'][0]
                if setting_level:
                    xlog.info("set globa config level to %s", setting_level)
                    config.set_level(setting_level)
                    direct_config.set_level(setting_level)
                    front.ip_manager.load_config()
                    front.ip_manager.adjust_scan_thread_num()
                    front.ip_manager.remove_slowest_ip()
                    front.ip_manager.search_more_ip()

                connect_receive_buffer = int(self.postvars['connect_receive_buffer'][0])
                if 8192 <= connect_receive_buffer <= 2097152 and connect_receive_buffer != config.connect_receive_buffer:
                    xlog.info("set connect receive buffer to %dKB", connect_receive_buffer // 1024)
                    config.connect_receive_buffer = connect_receive_buffer
                    config.save()
                    config.load()

                    front.connect_manager.new_conn_pool.clear()
                    direct_front.connect_manager.new_conn_pool.clear()
                    front.http_dispatcher.close_all_worker()
                    for _, http_dispatcher in direct_front.dispatchs.items():
                        http_dispatcher.close_all_worker()

                data = '{"res":"success"}'
        except Exception as e:
            xlog.exception("req_config_handler except:%s", e)
            data = '{"res":"fail", "except":"%s"}' % e
        finally:
            self.send_response_nc('text/html', data)
Ejemplo n.º 51
0
def main():
    class HelpExit(Exception): pass

    verbose = False
    try:
        opt_parser = parser()
        opt_parser.get_option("--plots").help = (
                "Only /cutflow or /cutflow_no_weight plots are accepted "
                "[one at a time]")
        opt_parser.remove_option("--label")
        opt_parser.remove_option("--sub-label")
        opt_parser.remove_option("-s")
        opt_parser.add_option("--mode",
                              action="store", default="text",
                              help="print output in one of the formats: text, tex")
        opt_parser.add_option("--non-threshold",
                              action='store_true', default=False,
                              help="print non-threshold cutflow")

        options, args = opt_parser.parse_args()

        # load application configuration
        #
        if not options.config:
            raise RuntimeError("application configuration is not specified")

        config_ = config.load(os.path.expanduser(options.config))
        verbose = (options.verbose if options.verbose
                   else config_["core"]["verbose"])

        if verbose:
            print("loaded configuration from:", options.config)

        if 1 == len(sys.argv):
            raise HelpExit()

        # import templates only here otherwise PyROOT inhercepts --help option
        from preselection import templates

        if not options.plots:
            options.plots = "/cutflow"
        elif options.plots not in ["/cutflow", "/cutflow_no_weight"]:
            raise RuntimeError("choose either /cutflow or /cutflow_no_weight plot")

        app = templates.Cutflow(options, args, config_)
        app.run()
    except HelpExit:
        opt_parser.print_help()

        return 0
    except Exception as error:
        if verbose:
            # print Exception traceback for debug
            import traceback

            traceback.print_tb(sys.exc_info()[2])

        print(error, file=sys.stderr)

        return 1
    else:
        return 0
Ejemplo n.º 52
0
__author__ = "Manuel Ebert"
__copyright__ = "Copyright 2015, summer.ai"
__date__ = "2015-11-09"
__email__ = "*****@*****.**"

import argparse
from config import config
import json
import util
import os


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Set up buckets')
    parser.add_argument('word', help='Word to use')
    parser.add_argument('--config', dest='config', default="default", help='Config file to use')
    args = parser.parse_args()
    config.load(args.config)

    import tasks
    if not os.path.exists(config.local_s3):
        os.mkdir(config.local_s3)

    message = {'word': args.word, 'hashslug': util.hashslug(args.word)}
    message = tasks.search(message)
    message = tasks.detect(message)
    message = tasks.rate(message)
    message = tasks.save(message)

    print(json.dumps(message, indent=2))
Ejemplo n.º 53
0
Copyright 2012, All rights reserved
'''

from __future__ import print_function

import os
import yaml

from config import config

destination = os.path.expanduser("~/.exo")
if not os.path.exists(destination):
    os.mkdir(destination, 0o755)
    print("created configuration folder:", destination)
    
config_destination = os.path.join(destination, "template.yaml")
if not os.path.exists(config_destination):
    pwd = os.getcwd()

    cfg = config.load("config/config.yaml")

    cfg["template"]["channel"] = os.path.join(pwd, "config/2012.input.yaml")
    cfg["template"]["plot"] = os.path.join(pwd, "config/2012.plot.yaml")

    with open(config_destination, "w") as output_:
        yaml.dump(cfg, output_)

    print("the application configuration is saved in:", config_destination)

print("the system is setup for running")