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()
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()