feat(Anaconda): Local Repo

This commit is contained in:
nocode committed 2026-06-13 02:06:34 +02:00
1 parent 05ae9c36c3
commit c412cd5d33
203 files changed
+23997 -7

No files matched your search

@@ -0,0 +1,181 @@
# Copyright (C) 2009 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Chris Lumens <clumens@redhat.com>
#
class AbstractIntf(object):
"""The base class for Interfaces. This is an abstract class. It
provides methods that create and run various kinds of windows.
We provide a basic level of graphical and text oriented interfaces
here, but it should be possible for things like anaconda to supply
their own much more complicated ones with little effort.
"""
def __init__(self, *args, **kwargs):
"""Create a new AbstractInterface instance. This method need not
be overridden by subclasses.
"""
pass
def enableNetwork(self, *args, **kwargs):
"""Display and run a dialog that brings up the network, if it is
currently disabled. This method must be provided by all subclasses,
and should return False if unsuccessful.
"""
raise NotImplementedError
def exitWindow(self, title, message, *args, **kwargs):
"""Display and run a dialog that displays a message with the proper
buttons and images for quitting afterwards. This method must be
provided by all subclasses.
title -- The window's title.
message -- The window's text.
"""
raise NotImplementedError
def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
"""Create and return an instance of the initial execption handling
dialog. This method must be provided by all subclasses.
text -- The short traceback (usually, just the stack trace).
exnFile -- A file containing the output of ExceptionDump.write().
"""
raise NotImplementedError
def messageWindow(self, title, message, *args, **kwargs):
"""Display a generic informational message. This can be an error,
status update, and so forth. It must be provided by all subclasses.
title -- The window's title.
message -- The window's text.
"""
raise NotImplementedError
def saveExceptionWindow(self, exnFile, *args, **kwargs):
"""Create and return an instance of the exception saving dialog. This
method must be provided by all subclasses.
"""
raise NotImplementedError
class AbstractMainExceptionWindow(object):
"""This abstract class describes the basic level of support required of
any interface that supplies a main exception window. The main exception
window is the initial dialog displayed by the exception handler that
provides the debug/save/quit options.
"""
def __init__(self, shortTraceback=None, longTraceback=None, *args, **kwargs):
"""Create a new MainExceptionWindow instance. This must handle
creating the dialog and populating it with widgets, but must not
run the dialog. A self.dialog attribute should be created that
refers to the dialog itself.
shortTraceback -- The short traceback (usually, just the stack
trace).
longTraceback -- The long traceback (full traceback and the main
object dump).
"""
pass
def destroy(self, *args, **kwargs):
"""Destroy the current dialog. This method must be provided by all
subclasses.
"""
raise NotImplementedError
def run(self, *args, **kwargs):
"""Run the window and set a return value. This method does everything
after the interface has been set up, but does not destroy it. This
method must be provided by all subclasses.
"""
raise NotImplementedError
class AbstractExitWindow(object):
"""This abstract class describes the basic level of support required of
a basic message dialog that should be displayed before the program
exits. All interfaces must provide this class.
"""
def __init__(self, title, text, *args, **kwargs):
"""Create a new ExitWindow instance. This must handle creating the
dialog and putting the text into it, but must not run the dialog.
This method must be provided by all subclasses.
title -- The window's title.
text -- The window's text.
"""
pass
def destroy(self, *args, **kwargs):
"""Destroy the current dialog. This method must be provided by all
subclasses.
"""
raise NotImplementedError
def run(self, *args, **kwargs):
"""Run the window and set a return value. This method does everything
after the interface has been set up but does not destroy it. This
method must be provided by all subclasses.
"""
raise NotImplementedError
class AbstractMessageWindow(object):
"""This abstract class describes the basic level of support required of
a basic message dialog. All interfaces must provide this class.
"""
def __init__(self, title, text, *args, **kwargs):
"""Create a new MessageWindow instance. This must handle creating the
dialog and putting the text into it, but must not run the dialog.
This method must be provided by all subclasses.
title -- The window's title.
text -- The window's text.
"""
pass
def destroy(self, *args, **kwargs):
"""Destroy the current dialog. This method must be provided by all
subclasses.
"""
raise NotImplementedError
def run(self, *args, **kwargs):
"""Run the window and set a return value. This method does everything
after the interface has been set up but does not destroy it. This
method must be provided by all subclasses.
"""
raise NotImplementedError
class AbstractSaveExceptionWindow(object):
"""This abstract class describes the basic level of support required of
any interface that supplies an exception saving window. The exception
saving window is the dialog displayed if the user clicks "save" on the
initial dialog, and presents multiple options for how the traceback
should be saved.
"""
def __init__(self, *args, **kwargs):
"""Create a new SaveExceptionWindow instance. This must handle
creating the dialog and populating it with widgets, but must not
run the dialog. A self.dialog attribute should be created that
refers to the dialog itself.
"""
pass
def run(self, *args, **kwargs):
"""Run the window and set a return value. This method does everything
after the interface has been set up but does not destroy it. This
method must be provided by all subclasses.
"""
raise NotImplementedError
@@ -0,0 +1,177 @@
# Copyright (C) 2009 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Chris Lumens <clumens@redhat.com>
#
from meh import MAIN_RESPONSE_DEBUG, MAIN_RESPONSE_NONE, MAIN_RESPONSE_QUIT, MAIN_RESPONSE_SAVE
from meh.ui import AbstractIntf, AbstractSaveExceptionWindow, AbstractMainExceptionWindow, AbstractMessageWindow
import os
import sys
import report
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import gettext
_ = lambda x: gettext.ldgettext("python-meh", x)
def find_glade_file(file):
path = os.environ.get("GLADEPATH", "./:ui/:/tmp/updates/:/tmp/updates/ui/:/usr/share/python-meh/")
for d in path.split(":"):
fn = d + file
if os.access(fn, os.R_OK):
return fn
raise RuntimeError("Unable to find glade file %s" % file)
class GraphicalIntf(AbstractIntf):
def __init__(self, *args, **kwargs):
AbstractIntf.__init__(self, *args, **kwargs)
def enableNetwork(self, *args, **kwargs):
"""Should be provided by the inheriting class."""
return False
def exitWindow(self, title, message, *args, **kwargs):
win = ExitWindow(title, message, *args, **kwargs)
win.run()
win.destroy()
def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
win = MainExceptionWindow(text, exnFile, *args, **kwargs)
return win
def messageWindow(self, title, message, *args, **kwargs):
win = MessageWindow(title, message, *args, **kwargs)
win.run()
win.destroy()
def saveExceptionWindow(self, signature, *args, **kwargs):
win = SaveExceptionWindow(signature)
win.run()
class SaveExceptionWindow(AbstractSaveExceptionWindow):
def __init__(self, signature, *args, **kwargs):
AbstractSaveExceptionWindow.__init__(self, signature, *args, **kwargs)
self.signature = signature
def run(self, *args, **kwargs):
# Don't need to check the return value of report since it will
# handle all the UI reporting for us.
report.report_problem_in_memory(self.signature, report.LIBREPORT_WAIT)
class MainExceptionWindow(AbstractMainExceptionWindow):
def __init__(self, shortTraceback=None, longTraceback=None, *args, **kwargs):
AbstractMainExceptionWindow.__init__(self, shortTraceback, longTraceback,
*args, **kwargs)
builder = Gtk.Builder()
builder.set_translation_domain("python-meh")
glade_file = find_glade_file("exception-dialog.glade")
builder.add_from_file(glade_file)
builder.connect_signals(self)
self._main_window = builder.get_object("exceptionWindow")
# this makes sure the Meh window remains active
# even if the exception has been triggered in a dialog
window_group = Gtk.WindowGroup()
window_group.add_window(self._main_window)
self._traceback_buffer = builder.get_object("tracebackBuffer")
self._traceback_buffer.set_text(longTraceback)
self._response = MAIN_RESPONSE_QUIT
self._debug_button = builder.get_object("debugButton")
allowDebug = kwargs.get("allowDebug", sys.stdout.isatty)
if allowDebug and not allowDebug():
self._debug_button.set_sensitive(False)
@property
def main_window(self):
return self._main_window
def destroy(self, *args, **kwargs):
self._main_window.destroy()
def run(self, *args, **kwargs):
self._main_window.show_all()
# keep our window above dialogs
self._main_window.set_modal(True)
self._main_window.set_keep_above(True)
Gtk.main()
self.destroy()
return self._response
def on_report_clicked(self, button):
# hide our window to not interfere with libreport window
self._main_window.hide()
self._response = MAIN_RESPONSE_SAVE
Gtk.main_quit()
def on_quit_clicked(self, button):
self._response = MAIN_RESPONSE_QUIT
Gtk.main_quit()
def on_debug_clicked(self, button):
self._response = MAIN_RESPONSE_DEBUG
Gtk.main_quit()
def on_expander_activated(self, expander, *args):
if not expander.get_expanded():
self._main_window.resize(600, 400)
else:
#resize the window back to the default size when expander is
#minimized
self._main_window.resize(600, 1)
def on_main_window_deleted(self, *args):
self._response = MAIN_RESPONSE_NONE
self.destroy()
Gtk.main_quit()
class MessageWindow(AbstractMessageWindow):
def __init__(self, title, text, *args, **kwargs):
AbstractMessageWindow.__init__(self, title, text, *args, **kwargs)
self.rc = 0
self.dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.OK,
type=Gtk.MessageType.INFO,
message_format=text)
self.dialog.set_title(title)
self.dialog.set_position(Gtk.WindowPosition.CENTER)
def destroy(self, *args, **kwargs):
self.dialog.destroy()
def run(self, *args, **kwargs):
self.dialog.show_all()
self.rc = self.dialog.run()
self.dialog.destroy()
class ExitWindow(MessageWindow):
def __init__(self, title, text, *args, **kwargs): # pylint: disable=super-init-not-called
self.dialog = Gtk.MessageDialog(buttons=Gtk.ButtonsType.NONE,
type=Gtk.MessageType.INFO,
message_format=text)
self.dialog.set_title(title)
self.dialog.add_button(_("_Exit"), 0)
self.dialog.set_position(Gtk.WindowPosition.CENTER)
@@ -0,0 +1,225 @@
# Copyright (C) 2009, 2013 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Chris Lumens <clumens@redhat.com>
# Vratislav Podzimek <vpodzime@redhat.com>
#
from __future__ import print_function
from meh import MAIN_RESPONSE_DEBUG, MAIN_RESPONSE_SAVE, MAIN_RESPONSE_SHELL, MAIN_RESPONSE_QUIT
from meh.ui import AbstractIntf, AbstractSaveExceptionWindow, AbstractMainExceptionWindow, AbstractMessageWindow
import report
import report.io.TextIO
from report import LIBREPORT_WAIT, LIBREPORT_RUN_CLI
import os
import sys
if sys.version_info.major == 3:
raw_input_fn = input
else:
raw_input_fn = raw_input # pylint: disable=undefined-variable
import gettext
_ = lambda x: gettext.ldgettext("python-meh", x)
class IOHandler(object):
"""
Class that provides methods for input and output. Its instance is expected
to be passed to objects performing some I/O operations.
"""
def __init__(self, in_func=raw_input_fn, out_func=print): # pylint: disable=used-before-assignment
"""
Constructor for the IOhandler class. Arguments can be used to override
default I/O functions with the custom ones.
:param in_func: input function similar to standard raw_input
:type in_func: str -> str
:param out_func: output function similar to standard print
:type out_func: str -> None
"""
self.in_func = in_func
self.out_func = out_func
def print(self, msg=""):
self.out_func(msg)
def raw_input(self, prompt):
return self.in_func(prompt)
class TextWindow(object):
"""Helper class providing some common methods needed by all text windows."""
def __init__(self, title, *args, **kwargs):
self._io = kwargs.get("io_handler", IOHandler())
self._title = title
# short (one-char) answer meaning "yes"
self._yes_answer = _("y")
# short (one-char) answer meaning "no"
self._no_answer = _("n")
@property
def _usable_width(self):
return os.environ.get("COLUMNS", 80) - 1
def _print_rule(self):
rule = self._usable_width * "="
self._io.print(rule)
def print_header(self):
self._io.print()
self._print_rule()
self._io.print(self._title)
self._print_rule()
def destroy(self):
self._print_rule()
self._print_rule()
class TextIntf(AbstractIntf):
def __init__(self, *args, **kwargs):
AbstractIntf.__init__(self, *args, **kwargs)
self.screen = kwargs.get("screen", None)
self._io = kwargs.get("io_handler", IOHandler())
def set_io_handler(self, handler):
"""
Set different IO handler.
:type handler: an instance of the IOHandler class
"""
self._io = handler
def enableNetwork(self, *args, **kwargs):
"""Should be provided by the inheriting class."""
return False
def exitWindow(self, title, message, *args, **kwargs):
kwargs["io_handler"] = self._io
win = ExitWindow(title, message, *args, **kwargs)
win.run()
win.destroy()
def mainExceptionWindow(self, text, exnFile, *args, **kwargs):
kwargs["io_handler"] = self._io
win = MainExceptionWindow(text, exnFile, *args, **kwargs)
return win
def messageWindow(self, title, message, *args, **kwargs):
kwargs["io_handler"] = self._io
win = MessageWindow(title, message, *args, **kwargs)
win.run()
win.destroy()
def saveExceptionWindow(self, signature, *args, **kwargs):
kwargs["io_handler"] = self._io
win = SaveExceptionWindow(signature, *args, **kwargs)
win.run()
win.destroy()
class SaveExceptionWindow(TextWindow, AbstractSaveExceptionWindow):
def __init__(self, signature, *args, **kwargs):
AbstractSaveExceptionWindow.__init__(self, signature,
*args, **kwargs)
TextWindow.__init__(self, _("Save exception"), *args, **kwargs)
self.signature = signature
def run(self, *args, **kwargs):
# Don't need to check the return value of report since it will
# handle all the UI reporting for us.
report.report_problem_in_memory(self.signature,
LIBREPORT_WAIT|LIBREPORT_RUN_CLI)
class MainExceptionWindow(TextWindow, AbstractMainExceptionWindow):
def __init__(self, shortTraceback=None, longTraceback=None, *args, **kwargs):
AbstractMainExceptionWindow.__init__(self, shortTraceback, longTraceback,
*args, **kwargs)
TextWindow.__init__(self, _("An unknown error has occurred"),
*args, **kwargs)
self._short_traceback = shortTraceback
self._menu_items = [(_("Report Bug"), MAIN_RESPONSE_SAVE),
(_("Run shell"), MAIN_RESPONSE_SHELL),
(_("Quit"), MAIN_RESPONSE_QUIT)]
allowDebug = kwargs.get("allowDebug", sys.stdout.isatty)
if allowDebug and allowDebug():
self._menu_items.insert(1, (_("Debug"), MAIN_RESPONSE_DEBUG))
def run(self, *args, **kwargs):
self.print_header()
self._io.print(self._short_traceback)
self._io.print(_("What do you want to do now?"))
for (idx, item) in enumerate(self._menu_items):
self._io.print("%d) %s" % (idx + 1, item[0]))
ret = -1
num_menu_items = len(self._menu_items)
self._io.print()
while not (0 < ret <= num_menu_items):
ret = self._io.raw_input(_("Please make your choice from above: "))
try:
ret = int(ret)
except ValueError:
ret = -1
return self._menu_items[ret - 1][1]
class MessageWindow(TextWindow, AbstractMessageWindow):
def __init__(self, title, text, *args, **kwargs):
AbstractMessageWindow.__init__(self, title, text, *args, **kwargs)
TextWindow.__init__(self, title, *args, **kwargs)
self._text = text
def run(self, *args, **kwargs):
self.print_header()
self._io.print(self._text)
self._io.print()
self._io.raw_input(_("Hit ENTER to continue"))
class ExitWindow(MessageWindow):
def __init__(self, title, text, *args, **kwargs):
MessageWindow.__init__(self, title, text, *args, **kwargs)
def run(self, *args, **kwargs):
self.print_header()
self._io.print(self._text)
self._io.print()
# self._no_answer may be non-ascii string (simple .upper() doesn't work)
no_answer_upper = self._no_answer.decode("utf-8").upper().encode("utf-8")
answer = self._io.raw_input(_(
"Are you sure you want to exit? [%(yes)s/%(no)s]") %
{ "yes": self._yes_answer,
"no": no_answer_upper })
# no answer means accepting the default (self._no_answer) and the answer
# is case insensitive (and may be non-ascii)
lower_answer = answer.decode("utf-8").lower().encode("utf-8")
answer = lower_answer or self._no_answer
if answer in (self._yes_answer, self._no_answer):
return answer == self._yes_answer
else:
self.run(*args, **kwargs)