当前位置: 首页>>代码示例>>Python>>正文


Python EventLoop.build_loop方法代码示例

本文整理汇总了Python中ubuntui.ev.EventLoop.build_loop方法的典型用法代码示例。如果您正苦于以下问题:Python EventLoop.build_loop方法的具体用法?Python EventLoop.build_loop怎么用?Python EventLoop.build_loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ubuntui.ev.EventLoop的用法示例。


在下文中一共展示了EventLoop.build_loop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]
def main():
    with open(maas_data) as fp:
        maas_machines = json.load(fp)
    machine_view = maas_machines
    ui = MachineUI(machine_view)
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    EventLoop.run()
开发者ID:Ubuntu-Solutions-Engineering,项目名称:urwid-ubuntu,代码行数:9,代码来源:viewer-maas.py

示例2: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]
def main():
    opts = parse_options(sys.argv[1:])

    config = Config('bundle-placer', opts.__dict__)
    config.save()

    setup_logger(cfg_path=config.cfg_path)
    log = logging.getLogger('bundleplacer')
    log.debug(opts.__dict__)

    log.info("Editing file: {}".format(opts.bundle_filename))

    if opts.maas_ip and opts.maas_cred:
        creds = dict(api_host=opts.maas_ip,
                     api_key=opts.maas_cred)
        maas, maas_state = connect_to_maas(creds)
    else:
        maas_state = FakeMaasState()

    placement_controller = PlacementController(config=config,
                                               maas_state=maas_state)

    mainview = PlacerView(placement_controller, config)
    ui = PlacerUI(mainview)

    def unhandled_input(key):
        if key in ['q', 'Q']:
            raise urwid.ExitMainLoop()
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    mainview.loop = EventLoop.loop
    mainview.update()
    EventLoop.run()
开发者ID:mikemccracken,项目名称:bundle-placement,代码行数:34,代码来源:cli.py

示例3: start

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]
 def start(self):
     EventLoop.build_loop(self.common['ui'], STYLES,
                          unhandled_input=self.unhandled_input)
     EventLoop.set_alarm_in(0.05, self._start)
     EventLoop.run()
开发者ID:pombredanne,项目名称:conjure,代码行数:7,代码来源:app.py

示例4: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]
def main():
    with open(juju_data) as fp:
        juju_state = json.load(fp)
    ui = ServiceUI(juju_state)
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    EventLoop.run()
开发者ID:Ubuntu-Solutions-Engineering,项目名称:urwid-ubuntu,代码行数:8,代码来源:viewer-juju.py

示例5: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]
def main():
    if os.getenv("BUNDLE_EDITOR_TESTING"):
        test_args = True
    else:
        test_args = False

    opts = parse_options(sys.argv[1:], test_args)

    config = Config('bundle-placer', opts.__dict__)
    config.save()

    setup_logger(cfg_path=config.cfg_path)
    log = logging.getLogger('bundleplacer')
    log.debug(opts.__dict__)

    log.info("Editing file: {}".format(opts.bundle_filename))

    if opts.maas_ip and opts.maas_cred:
        creds = dict(api_host=opts.maas_ip,
                     api_key=opts.maas_cred)
        maas, maas_state = connect_to_maas(creds)
    elif 'fake_maas' in opts and opts.fake_maas:
        maas = None
        maas_state = FakeMaasState()
    else:
        maas = None
        maas_state = None

    try:
        placement_controller = PlacementController(config=config,
                                                   maas_state=maas_state)
    except Exception as e:
        print("Error: " + e.args[0])
        return

    def cb():
        if maas:
            maas.tag_name(maas.nodes)

        bw = BundleWriter(placement_controller)
        if opts.out_filename:
            outfn = opts.out_filename
        else:
            outfn = opts.bundle_filename
            if os.path.exists(outfn):
                shutil.copy2(outfn, outfn + '~')
        bw.write_bundle(outfn)
        async.shutdown()
        raise urwid.ExitMainLoop()

    has_maas = (maas_state is not None)
    mainview = PlacerView(placement_controller, config, cb, has_maas=has_maas)
    ui = PlacerUI(mainview)

    def unhandled_input(key):
        if key in ['q', 'Q']:
            async.shutdown()
            raise urwid.ExitMainLoop()
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    mainview.loop = EventLoop.loop
    mainview.update()
    EventLoop.run()
开发者ID:Ubuntu-Solutions-Engineering,项目名称:bundle-placement,代码行数:64,代码来源:cli.py

示例6: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]

#.........这里部分代码省略.........
    if not os.path.exists(global_config_filename):
        # fallback to source tree location
        global_config_filename = os.path.join(os.path.dirname(__file__),
                                              "../etc/conjure-up.conf")
        if not os.path.exists(global_config_filename):
            utils.error("Could not find {}.".format(global_config_filename))
            sys.exit(1)

    with open(global_config_filename) as fp:
        global_conf = yaml.safe_load(fp.read())
        app.global_config = global_conf

    spells_dir = app.argv.spells_dir
    if not os.path.exists(spells_dir):
        spells_dir = os.path.join(os.path.dirname(__file__),
                                  "../spells")

    app.config['spells-dir'] = spells_dir
    spells_index_path = os.path.join(app.config['spells-dir'],
                                     'spells-index.yaml')
    with open(spells_index_path) as fp:
        app.spells_index = yaml.safe_load(fp.read())

    spell_name = spell
    app.endpoint_type = detect_endpoint(opts.spell)

    if app.endpoint_type == EndpointType.LOCAL_SEARCH:
        spells = utils.find_spells_matching(opts.spell)

        if len(spells) == 0:
            utils.error("Can't find a spell matching '{}'".format(opts.spell))
            sys.exit(1)

        # One result means it was a direct match and we can copy it
        # now. Changing the endpoint type then stops us from showing
        # the picker UI. More than one result means we need to show
        # the picker UI and will defer the copy to
        # SpellPickerController.finish(), so nothing to do here.
        if len(spells) == 1:
            print("found spell {}".format(spells[0]))
            utils.set_chosen_spell(spell_name,
                                   os.path.join(opts.cache_dir,
                                                spell_name))
            download_local(os.path.join(app.config['spells-dir'],
                                        spell_name),
                           app.config['spell-dir'])
            utils.set_spell_metadata()
            app.endpoint_type = EndpointType.LOCAL_DIR

    # download spell if necessary
    elif app.endpoint_type == EndpointType.LOCAL_DIR:
        if not os.path.isdir(opts.spell):
            utils.warning("Could not find spell {}".format(opts.spell))
            sys.exit(1)

        spell_name = os.path.basename(os.path.abspath(spell))
        utils.set_chosen_spell(spell_name,
                               path.join(opts.cache_dir, spell_name))
        download_local(opts.spell, app.config['spell-dir'])
        utils.set_spell_metadata()

    elif app.endpoint_type in [EndpointType.VCS, EndpointType.HTTP]:

        utils.set_chosen_spell(spell, path.join(opts.cache_dir, spell))
        remote = get_remote_url(opts.spell)

        if remote is None:
            utils.warning("Can't guess URL matching '{}'".format(opts.spell))
            sys.exit(1)

        download(remote, app.config['spell-dir'], True)
        utils.set_spell_metadata()

    if app.argv.status_only:
        if not juju.model_available():
            utils.error("Attempted to access the status screen without "
                        "an available Juju model.\n"
                        "Please select a model using 'juju switch' or "
                        "create a new controller using 'juju bootstrap'.")
            sys.exit(1)

    app.env = os.environ.copy()
    app.env['CONJURE_UP_SPELL'] = spell_name

    if app.argv.cloud:
        if app.endpoint_type in [None, EndpointType.LOCAL_SEARCH]:
            utils.error("Please specify a spell for headless mode.")
            sys.exit(1)

        app.headless = True
        app.ui = None
        app.env['CONJURE_UP_HEADLESS'] = "1"
        _start()

    else:
        app.ui = ConjureUI()
        EventLoop.build_loop(app.ui, STYLES,
                             unhandled_input=unhandled_input)
        EventLoop.set_alarm_in(0.05, _start)
        EventLoop.run()
开发者ID:tych0,项目名称:conjure-up,代码行数:104,代码来源:app.py

示例7: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]

#.........这里部分代码省略.........
            spells_dir, branch=spells_registry_branch)
    else:
        app.log.debug("Refreshing spell registry")
        download_or_sync_registry(
            app.global_config['registry']['repo'],
            spells_dir, update=True, branch=spells_registry_branch)

    spells_index_path = os.path.join(app.config['spells-dir'],
                                     'spells-index.yaml')
    with open(spells_index_path) as fp:
        app.spells_index = yaml.safe_load(fp.read())

    spell_name = spell
    app.endpoint_type = detect_endpoint(opts.spell)

    if app.endpoint_type == EndpointType.LOCAL_SEARCH:
        spells = utils.find_spells_matching(opts.spell)

        if len(spells) == 0:
            utils.error("Can't find a spell matching '{}'".format(opts.spell))
            sys.exit(1)

        # One result means it was a direct match and we can copy it
        # now. Changing the endpoint type then stops us from showing
        # the picker UI. More than one result means we need to show
        # the picker UI and will defer the copy to
        # SpellPickerController.finish(), so nothing to do here.
        if len(spells) == 1:
            app.log.debug("found spell {}".format(spells[0]))
            spell = spells[0]
            utils.set_chosen_spell(spell_name,
                                   os.path.join(opts.cache_dir,
                                                spell['key']))
            download_local(os.path.join(app.config['spells-dir'],
                                        spell['key']),
                           app.config['spell-dir'])
            utils.set_spell_metadata()
            app.endpoint_type = EndpointType.LOCAL_DIR

    # download spell if necessary
    elif app.endpoint_type == EndpointType.LOCAL_DIR:
        if not os.path.isdir(opts.spell):
            utils.warning("Could not find spell {}".format(opts.spell))
            sys.exit(1)

        if not os.path.exists(os.path.join(opts.spell,
                                           "metadata.yaml")):
            utils.warning("'{}' does not appear to be a spell. "
                          "{}/metadata.yaml was not found.".format(
                              opts.spell, opts.spell))
            sys.exit(1)

        spell_name = os.path.basename(os.path.abspath(spell))
        utils.set_chosen_spell(spell_name,
                               path.join(opts.cache_dir, spell_name))
        download_local(opts.spell, app.config['spell-dir'])
        utils.set_spell_metadata()

    elif app.endpoint_type in [EndpointType.VCS, EndpointType.HTTP]:

        utils.set_chosen_spell(spell, path.join(opts.cache_dir, spell))
        remote = get_remote_url(opts.spell)

        if remote is None:
            utils.warning("Can't guess URL matching '{}'".format(opts.spell))
            sys.exit(1)

        download(remote, app.config['spell-dir'], True)
        utils.set_spell_metadata()

    app.env = os.environ.copy()
    app.env['CONJURE_UP_CACHEDIR'] = app.argv.cache_dir
    app.env['CONJURE_UP_SPELL'] = spell_name

    if app.argv.show_env:
        if not app.argv.cloud:
            utils.error("You must specify a cloud for headless mode.")
            sys.exit(1)
        if app.endpoint_type in [None, EndpointType.LOCAL_SEARCH]:
            utils.error("Please specify a spell for headless mode.")
            sys.exit(1)

        show_env()

    if app.argv.cloud:
        if app.endpoint_type in [None, EndpointType.LOCAL_SEARCH]:
            utils.error("Please specify a spell for headless mode.")
            sys.exit(1)

        app.headless = True
        app.ui = None
        app.env['CONJURE_UP_HEADLESS'] = "1"
        _start()

    else:
        app.ui = ConjureUI()
        EventLoop.build_loop(app.ui, STYLES,
                             unhandled_input=unhandled_input)
        EventLoop.set_alarm_in(0.05, _start)
        EventLoop.run()
开发者ID:conjure-up,项目名称:conjure-up,代码行数:104,代码来源:app.py

示例8: main

# 需要导入模块: from ubuntui.ev import EventLoop [as 别名]
# 或者: from ubuntui.ev.EventLoop import build_loop [as 别名]

#.........这里部分代码省略.........
    app.ui = ConjureUI()

    if spell in global_conf['curated_spells']:
        install_curated_spell(spell)

    spell_dir = os.environ.get('XDG_CACHE_HOME', os.path.join(
        os.path.expanduser('~'),
        '.cache/conjure-up'))

    if app.fetcher == "charmstore-search":
        app.bundles = load_charmstore_results(spell, global_conf['blessed'])
        app.config = {'metadata': None,
                      'spell-dir': spell_dir,
                      'spell': spell}

        # Set a general description of spell
        definition = None
        if path.isfile('/usr/share/conjure-up/keyword-definitions.yaml'):
            with open('/usr/share/conjure-up/keyword-definitions.yaml') as fp:
                definitions = yaml.safe_load(fp.read())
                definition = definitions.get(spell, None)
        if definition is None:
            try:
                definition = next(
                    bundle['Meta']['bundle-metadata']['Description']
                    for bundle in app.bundles if 'Description'
                    in bundle['Meta']['bundle-metadata'])
            except StopIteration:
                app.log.error("Could not find a suitable description "
                              "for spell: {}".format(spell))

        if definition is not None:
            app.config['description'] = definition
        else:
            utils.warning(
                "Failed to find a description for spell: {}, "
                "and is a bug that should be filed.".format(spell))

    else:
        # Check cache dir for spells
        spell_dir = path.join(spell_dir, spell)

        metadata_path = path.join(spell_dir,
                                  'conjure/metadata.json')

        remote = get_remote_url(opts.spell)
        purge_top_level = True
        if remote is not None:
            if app.fetcher == "charmstore-search" or \
               app.fetcher == "charmstore-direct":
                purge_top_level = False
            download(remote, spell_dir, purge_top_level)
        else:
            utils.warning("Could not find spell: {}".format(spell))
            sys.exit(1)

        with open(metadata_path) as fp:
            metadata = json.load(fp)

        app.config = {'metadata': metadata,
                      'spell-dir': spell_dir,
                      'spell': spell}

        # Need to provide app.bundles dictionary even for single
        # spells in the GUI
        app.bundles = [
            {
                'Meta': {
                    'extra-info/conjure': metadata
                }
            }
        ]

    if hasattr(app.argv, 'cloud'):
        if app.fetcher != "charmstore-search":
            app.headless = True
            app.ui = None
        else:
            utils.error("Unable run a keyword search in headless mode, "
                        "please provide a single bundle path.")
            sys.exit(1)

    app.env = os.environ.copy()
    app.env['CONJURE_UP_SPELL'] = spell

    if app.argv.status_only:
        if not juju.available():
            utils.error("Attempted to access the status screen of "
                        "a non-bootstrapped Juju environment. "
                        "Please bootstrap an environment first.")
            sys.exit(1)

    if app.headless:
        app.env['CONJURE_UP_HEADLESS'] = "1"
        _start()
    else:
        EventLoop.build_loop(app.ui, STYLES,
                             unhandled_input=unhandled_input)
        EventLoop.set_alarm_in(0.05, _start)
        EventLoop.run()
开发者ID:benluteijn,项目名称:conjure-up,代码行数:104,代码来源:app.py


注:本文中的ubuntui.ev.EventLoop.build_loop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。