Example #1
0
def main(command_args):
	"""Implements the logic of the 0desktop command.
	@param command_args: the command-line arguments"""
	parser = OptionParser(usage=_("usage: %prog [options] [URI]"))
	parser.add_option("-m", "--manage", help=_("manage added applications"), action='store_true')
	parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
	parser.add_option("-V", "--version", help=_("display version information"), action='store_true')

	(options, args) = parser.parse_args(command_args)

	if options.verbose:
		if options.verbose == 1:
			logger.setLevel(logging.INFO)
		else:
			logger.setLevel(logging.DEBUG)
		hdlr = logging.StreamHandler()
		fmt = logging.Formatter("%(levelname)s:%(message)s")
		hdlr.setFormatter(fmt)
		logger.addHandler(hdlr)

	if options.version:
		import zeroinstall
		print("0desktop (zero-install) " + zeroinstall.version)
		print("Copyright (C) 2013 Thomas Leonard")
		print(_("This program comes with ABSOLUTELY NO WARRANTY,"
				"\nto the extent permitted by law."
				"\nYou may redistribute copies of this program"
				"\nunder the terms of the GNU Lesser General Public License."
				"\nFor more information about these matters, see the file named COPYING."))
		sys.exit(0)

	if not args:
		interface_uri = None
	elif len(args) == 1:
		interface_uri = args[0]
	else:
		parser.print_help()
		sys.exit(1)

	if sys.version_info[0] < 3:
		import pygtk
		pygtk.require('2.0')
	else:
		from zeroinstall.gtkui import pygtkcompat
		pygtkcompat.enable()
		pygtkcompat.enable_gtk(version = '3.0')
	import gtk

	if options.manage:
		from zeroinstall.gtkui.applistbox import AppListBox, AppList
		from zeroinstall.injector.iface_cache import iface_cache
		box = AppListBox(iface_cache, AppList())
	else:
		from zeroinstall.gtkui.addbox import AddBox
		box = AddBox(interface_uri)

	box.window.connect('destroy', gtk.main_quit)
	box.window.show()
	gtk.main()
Example #2
0
def main(command_args):
	"""Implements the logic of the 0desktop command.
	@param command_args: the command-line arguments"""
	parser = OptionParser(usage=_("usage: %prog [options] [URI]"))
	parser.add_option("-m", "--manage", help=_("manage added applications"), action='store_true')
	parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
	parser.add_option("-V", "--version", help=_("display version information"), action='store_true')

	(options, args) = parser.parse_args(command_args)

	if options.verbose:
		if options.verbose == 1:
			logger.setLevel(logging.INFO)
		else:
			logger.setLevel(logging.DEBUG)
		hdlr = logging.StreamHandler()
		fmt = logging.Formatter("%(levelname)s:%(message)s")
		hdlr.setFormatter(fmt)
		logger.addHandler(hdlr)

	if options.version:
		import zeroinstall
		print("0desktop (zero-install) " + zeroinstall.version)
		print("Copyright (C) 2009 Thomas Leonard")
		print(_("This program comes with ABSOLUTELY NO WARRANTY,"
				"\nto the extent permitted by law."
				"\nYou may redistribute copies of this program"
				"\nunder the terms of the GNU Lesser General Public License."
				"\nFor more information about these matters, see the file named COPYING."))
		sys.exit(0)

	if not args:
		interface_uri = None
	elif len(args) == 1:
		interface_uri = args[0]
	else:
		parser.print_help()
		sys.exit(1)

	if sys.version_info[0] < 3:
		import pygtk
		pygtk.require('2.0')
	else:
		from zeroinstall.gtkui import pygtkcompat
		pygtkcompat.enable()
		pygtkcompat.enable_gtk(version = '3.0')
	import gtk

	if options.manage:
		from zeroinstall.gtkui.applistbox import AppListBox, AppList
		from zeroinstall.injector.iface_cache import iface_cache
		box = AppListBox(iface_cache, AppList())
	else:
		from zeroinstall.gtkui.addbox import AddBox
		box = AddBox(interface_uri)

	box.window.connect('destroy', gtk.main_quit)
	box.window.show()
	gtk.main()
Example #3
0
def do_gui(args):
    "gui [--no-prompt] [SOURCE-URI]"
    if args and args[0] == '--no-prompt':
        del args[0]
        # This option no longer has any effect, since it is the default.
        # However, old versions of 0launch's GUI pass it (< 0.52)

    from zeroinstall.gtkui import pygtkcompat
    pygtkcompat.enable()
    pygtkcompat.enable_gtk(version='3.0')

    import gui_support
    import gtk

    try:
        if len(args) == 0:
            pass
        elif len(args) == 1:
            import setup

            def get_dir_callback(default_dir):
                compile_dir = gui_support.choose_dir(
                    _('Create build directory'), default_dir)
                if compile_dir:
                    return compile_dir
                raise SafeException("Cancelled at user's request")

            setup.do_setup(args, get_dir_callback)
        else:
            raise SafeException("usage: 0compile gui URI")

        buildenv = BuildEnv()
        box = gui_support.CompileBox(buildenv.interface)
        box.connect('destroy', lambda b: gtk.main_quit())
        box.show()

        gtk.main()
    except KeyboardInterrupt:
        pass
    except SafeException as ex:
        gui_support.alert(None, '%s' % ex)
        sys.exit(1)
    except Exception as ex:
        import traceback
        traceback.print_exc()
        gui_support.alert(None, '%s: %s' % (ex.__class__, ex))
        sys.exit(1)
Example #4
0
def do_manage(args):
	"""manage"""
	if args:
		raise UsageError(_("manage command takes no arguments"))

	if sys.version_info[0] < 3:
		import pygtk
		pygtk.require('2.0')
	else:
		from zeroinstall.gtkui import pygtkcompat
		pygtkcompat.enable()
		pygtkcompat.enable_gtk(version = '3.0')

	import gtk
	from zeroinstall.gtkui import cache
	from zeroinstall.injector.iface_cache import iface_cache
	cache_explorer = cache.CacheExplorer(iface_cache)
	cache_explorer.window.connect('destroy', gtk.main_quit)
	cache_explorer.show()
	gtk.main()
Example #5
0
def do_manage(args):
    """manage"""
    if args:
        raise UsageError(_("manage command takes no arguments"))

    if sys.version_info[0] < 3:
        import pygtk
        pygtk.require('2.0')
    else:
        from zeroinstall.gtkui import pygtkcompat
        pygtkcompat.enable()
        pygtkcompat.enable_gtk(version='3.0')

    import gtk
    from zeroinstall.gtkui import cache
    from zeroinstall.injector.iface_cache import iface_cache
    cache_explorer = cache.CacheExplorer(iface_cache)
    cache_explorer.window.connect('destroy', gtk.main_quit)
    cache_explorer.show()
    gtk.main()
Example #6
0
def check_gui():
	"""Returns True if the GUI works, or returns an exception if not."""
	if sys.version_info[0] < 3:
		try:
			import pygtk; pygtk.require('2.0')
		except ImportError as ex:
			logging.info("No GUI available", exc_info = ex)
			return ex

	try:
		if sys.version_info[0] > 2:
			from zeroinstall.gtkui import pygtkcompat
			pygtkcompat.enable()
			pygtkcompat.enable_gtk(version = '3.0')
		import gtk
	except (ImportError, ValueError, RuntimeError) as ex:
		logging.info("No GUI available", exc_info = ex)
		return ex

	if gtk.gdk.get_display() is None:
		return SafeException("Failed to connect to display.")

	return True
Example #7
0
	def __init__(self, config, iface_uri, options):
		config.handler.compiler = self

		AutoCompiler.__init__(self, config, iface_uri, options)
		self.child = None

		from zeroinstall.gtkui import pygtkcompat
		pygtkcompat.enable()
		pygtkcompat.enable_gtk(version = '3.0')

		import gtk

		w = gtk.Dialog('Autocompile %s' % iface_uri, None, 0,
						 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
						  gtk.STOCK_OK, gtk.RESPONSE_OK))
		self.dialog = w

		w.set_default_size(int(gtk.gdk.screen_width() * 0.8),
				   int(gtk.gdk.screen_height() * 0.8))

		vpaned = gtk.VPaned()
		w.vbox.pack_start(vpaned, True, True, 0)
		w.set_response_sensitive(gtk.RESPONSE_OK, False)

		class AutoScroller:
			def __init__(self):
				tv = gtk.TextView()
				tv.set_property('left-margin', 8)
				tv.set_wrap_mode(gtk.WRAP_WORD_CHAR)
				tv.set_editable(False)
				swin = gtk.ScrolledWindow()
				swin.add(tv)
				swin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
				buffer = tv.get_buffer()

				heading = buffer.create_tag('heading')
				heading.set_property('scale', 1.5)

				error = buffer.create_tag('error')
				error.set_property('background', 'white')
				error.set_property('foreground', 'red')

				self.tv = tv
				self.widget = swin
				self.buffer = buffer

			def insert_at_end_and_scroll(self, data, *tags):
				vscroll = self.widget.get_vadjustment()
				if not vscroll:
					# Widget has been destroyed
					print(data, end='')
					return
				near_end = vscroll.get_upper() - vscroll.get_page_size() * 1.5 < vscroll.get_value()
				end = self.buffer.get_end_iter()
				self.buffer.insert_with_tags_by_name(end, data, *tags)
				if near_end:
					cursor = self.buffer.get_insert()
					self.buffer.move_mark(cursor, end)
					self.tv.scroll_to_mark(cursor, 0, False, 0, 0)

			def set_text(self, text):
				self.buffer.set_text(text)

		self.overall = AutoScroller()
		self.details = AutoScroller()

		vpaned.pack1(self.overall.widget, True, False)
		vpaned.pack2(self.details.widget, True, False)

		self.closed = tasks.Blocker('Window closed')

		w.show_all()
		w.connect('destroy', lambda wd: self.closed.trigger())

		def response(wd, resp):
			if self.child is not None:
				self.note_error('Sending TERM signal to build process group %d...' % self.child.pid)
				os.kill(-self.child.pid, signal.SIGTERM)
			else:
				self.closed.trigger()
		w.connect('response', response)
Example #8
0
def run_gui(args):
	parser = OptionParser(usage=_("usage: %prog [options] interface"))
	parser.add_option("", "--before", help=_("choose a version before this"), metavar='VERSION')
	parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU')
	parser.add_option("", "--command", help=_("command to select"), metavar='COMMAND')
	parser.add_option("-d", "--download-only", help=_("fetch but don't run"), action='store_true')
	parser.add_option("-g", "--force-gui", help=_("display an error if there's no GUI"), action='store_true')
	parser.add_option("", "--message", help=_("message to display when interacting with user"))
	parser.add_option("", "--not-before", help=_("minimum version to choose"), metavar='VERSION')
	parser.add_option("", "--os", help=_("target operation system type"), metavar='OS')
	parser.add_option("-r", "--refresh", help=_("check for updates of all interfaces"), action='store_true')
	parser.add_option("", "--select-only", help=_("only download the feeds"), action='store_true')
	parser.add_option("-s", "--source", help=_("select source code"), action='store_true')
	parser.add_option("", "--systray", help=_("download in the background"), action='store_true')
	parser.add_option("-v", "--verbose", help=_("more verbose output"), action='count')
	parser.add_option("-V", "--version", help=_("display version information"), action='store_true')
	parser.add_option("", "--with-store", help=_("add an implementation cache"), action='append', metavar='DIR')

	parser.disable_interspersed_args()

	(options, args) = parser.parse_args(args)

	if options.verbose:
		logger = logging.getLogger()
		if options.verbose == 1:
			logger.setLevel(logging.INFO)
		else:
			logger.setLevel(logging.DEBUG)

	if options.version:
		print("0launch-gui (zero-install) " + gui.version)
		print("Copyright (C) 2010 Thomas Leonard")
		print(_("This program comes with ABSOLUTELY NO WARRANTY,"
				"\nto the extent permitted by law."
				"\nYou may redistribute copies of this program"
				"\nunder the terms of the GNU Lesser General Public License."
				"\nFor more information about these matters, see the file named COPYING."))
		sys.exit(0)

	def nogui(ex):
		if options.force_gui:
			fn = logging.warn
		else:
			fn = logging.info
			fn("No GUI available", exc_info = ex)
		sys.exit(100)

	with warnings.catch_warnings():
		if not options.force_gui:
			warnings.filterwarnings("ignore")
		if sys.version_info[0] < 3:
			try:
				import pygtk; pygtk.require('2.0')
			except ImportError as ex:
				nogui(ex)

		import gui

		try:
			if sys.version_info[0] > 2:
				from zeroinstall.gtkui import pygtkcompat
				pygtkcompat.enable()
				pygtkcompat.enable_gtk(version = '3.0')
			import gtk
		except (ImportError, ValueError) as ex:
			nogui(ex)

		if gtk.gdk.get_display() is None:
			try:
				raise SafeException("Failed to connect to display.")
			except SafeException as ex:
				nogui(ex)	# logging needs this as a raised exception

	handler = gui.GUIHandler()

	config = load_config(handler)

	if options.with_store:
		from zeroinstall import zerostore
		for x in options.with_store:
			config.stores.stores.append(zerostore.Store(os.path.abspath(x)))

	if len(args) < 1:
		@tasks.async
		def prefs_main():
			import preferences
			box = preferences.show_preferences(config)
			done = tasks.Blocker('close preferences')
			box.connect('destroy', lambda w: done.trigger())
			yield done
		tasks.wait_for_blocker(prefs_main())
		sys.exit(0)

	interface_uri = args[0]

	if len(args) > 1:
		parser.print_help()
		sys.exit(1)

	import mainwindow, dialog

	r = requirements.Requirements(interface_uri)
	r.parse_options(options)

	widgets = dialog.Template('main')

	driver = Driver(config = config, requirements = r)
	root_iface = config.iface_cache.get_interface(interface_uri)
	driver.solver.record_details = True

	window = mainwindow.MainWindow(driver, widgets, download_only = bool(options.download_only), select_only = bool(options.select_only))
	handler.mainwindow = window

	if options.message:
		window.set_message(options.message)

	root = config.iface_cache.get_interface(r.interface_uri)
	window.browser.set_root(root)

	window.window.connect('destroy', lambda w: handler.abort_all_downloads())

	if options.systray:
		window.use_systray_icon()

	@tasks.async
	def main():
		force_refresh = bool(options.refresh)
		while True:
			window.refresh_button.set_sensitive(False)
			window.browser.set_update_icons(force_refresh)

			solved = driver.solve_with_downloads(force = force_refresh, update_local = True)

			if not window.systray_icon:
				window.show()
			yield solved
			try:
				window.refresh_button.set_sensitive(True)
				window.browser.highlight_problems()
				tasks.check(solved)
			except Exception as ex:
				window.report_exception(ex)

			if window.systray_icon and window.systray_icon.get_visible() and \
			   window.systray_icon.is_embedded():
				if driver.solver.ready:
					window.systray_icon.set_tooltip(_('Downloading updates for %s') % root_iface.get_name())
					window.run_button.set_active(True)
				else:
					# Should already be reporting an error, but
					# blink it again just in case
					window.systray_icon.set_blinking(True)

			refresh_clicked = dialog.ButtonClickedBlocker(window.refresh_button)
			yield refresh_clicked, _recalculate

			if refresh_clicked.happened:
				force_refresh = True

	tasks.wait_for_blocker(main())
Example #9
0
def run_gui(args):
    parser = OptionParser(usage=_("usage: %prog [options] interface"))
    parser.add_option("",
                      "--before",
                      help=_("choose a version before this"),
                      metavar='VERSION')
    parser.add_option("", "--cpu", help=_("target CPU type"), metavar='CPU')
    parser.add_option("",
                      "--command",
                      help=_("command to select"),
                      metavar='COMMAND')
    parser.add_option("-d",
                      "--download-only",
                      help=_("fetch but don't run"),
                      action='store_true')
    parser.add_option("-g",
                      "--force-gui",
                      help=_("display an error if there's no GUI"),
                      action='store_true')
    parser.add_option("",
                      "--message",
                      help=_("message to display when interacting with user"))
    parser.add_option("",
                      "--not-before",
                      help=_("minimum version to choose"),
                      metavar='VERSION')
    parser.add_option("",
                      "--os",
                      help=_("target operation system type"),
                      metavar='OS')
    parser.add_option("-r",
                      "--refresh",
                      help=_("check for updates of all interfaces"),
                      action='store_true')
    parser.add_option("",
                      "--select-only",
                      help=_("only download the feeds"),
                      action='store_true')
    parser.add_option("-s",
                      "--source",
                      help=_("select source code"),
                      action='store_true')
    parser.add_option("",
                      "--systray",
                      help=_("download in the background"),
                      action='store_true')
    parser.add_option("-v",
                      "--verbose",
                      help=_("more verbose output"),
                      action='count')
    parser.add_option("-V",
                      "--version",
                      help=_("display version information"),
                      action='store_true')
    parser.add_option("",
                      "--with-store",
                      help=_("add an implementation cache"),
                      action='append',
                      metavar='DIR')

    parser.disable_interspersed_args()

    (options, args) = parser.parse_args(args)

    if options.verbose:
        logger = logging.getLogger()
        if options.verbose == 1:
            logger.setLevel(logging.INFO)
        else:
            logger.setLevel(logging.DEBUG)

    if options.version:
        print("0launch-gui (zero-install) " + gui.version)
        print("Copyright (C) 2010 Thomas Leonard")
        print(
            _("This program comes with ABSOLUTELY NO WARRANTY,"
              "\nto the extent permitted by law."
              "\nYou may redistribute copies of this program"
              "\nunder the terms of the GNU Lesser General Public License."
              "\nFor more information about these matters, see the file named COPYING."
              ))
        sys.exit(0)

    def nogui(ex):
        if options.force_gui:
            fn = logging.warn
        else:
            fn = logging.info
            fn("No GUI available", exc_info=ex)
        sys.exit(100)

    with warnings.catch_warnings():
        if not options.force_gui:
            warnings.filterwarnings("ignore")
        if sys.version_info[0] < 3:
            try:
                import pygtk
                pygtk.require('2.0')
            except ImportError as ex:
                nogui(ex)

        import gui

        try:
            if sys.version_info[0] > 2:
                from zeroinstall.gtkui import pygtkcompat
                pygtkcompat.enable()
                pygtkcompat.enable_gtk(version='3.0')
            import gtk
        except (ImportError, ValueError) as ex:
            nogui(ex)

        if gtk.gdk.get_display() is None:
            try:
                raise SafeException("Failed to connect to display.")
            except SafeException as ex:
                nogui(ex)  # logging needs this as a raised exception

    handler = gui.GUIHandler()

    config = load_config(handler)

    if options.with_store:
        from zeroinstall import zerostore
        for x in options.with_store:
            config.stores.stores.append(zerostore.Store(os.path.abspath(x)))

    if len(args) < 1:

        @tasks. async
        def prefs_main():
            import preferences
            box = preferences.show_preferences(config)
            done = tasks.Blocker('close preferences')
            box.connect('destroy', lambda w: done.trigger())
            yield done

        tasks.wait_for_blocker(prefs_main())
        sys.exit(0)

    interface_uri = args[0]

    if len(args) > 1:
        parser.print_help()
        sys.exit(1)

    import mainwindow, dialog

    r = requirements.Requirements(interface_uri)
    r.parse_options(options)

    widgets = dialog.Template('main')

    driver = Driver(config=config, requirements=r)
    root_iface = config.iface_cache.get_interface(interface_uri)
    driver.solver.record_details = True

    window = mainwindow.MainWindow(driver,
                                   widgets,
                                   download_only=bool(options.download_only),
                                   select_only=bool(options.select_only))
    handler.mainwindow = window

    if options.message:
        window.set_message(options.message)

    root = config.iface_cache.get_interface(r.interface_uri)
    window.browser.set_root(root)

    window.window.connect('destroy', lambda w: handler.abort_all_downloads())

    if options.systray:
        window.use_systray_icon()

    @tasks. async
    def main():
        force_refresh = bool(options.refresh)
        while True:
            window.refresh_button.set_sensitive(False)
            window.browser.set_update_icons(force_refresh)

            solved = driver.solve_with_downloads(force=force_refresh,
                                                 update_local=True)

            if not window.systray_icon:
                window.show()
            yield solved
            try:
                window.refresh_button.set_sensitive(True)
                window.browser.highlight_problems()
                tasks.check(solved)
            except Exception as ex:
                window.report_exception(ex)

            if window.systray_icon and window.systray_icon.get_visible() and \
               window.systray_icon.is_embedded():
                if driver.solver.ready:
                    window.systray_icon.set_tooltip(
                        _('Downloading updates for %s') %
                        root_iface.get_name())
                    window.run_button.set_active(True)
                else:
                    # Should already be reporting an error, but
                    # blink it again just in case
                    window.systray_icon.set_blinking(True)

            refresh_clicked = dialog.ButtonClickedBlocker(
                window.refresh_button)
            yield refresh_clicked, _recalculate

            if refresh_clicked.happened:
                force_refresh = True

    tasks.wait_for_blocker(main())