Exemplo n.º 1
0
def main(args=None, five_to_six_script=False):
    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    add_parser_options(parser, five_to_six_script)

    # In testing we sometimes specify args, otherwise use the default:
    if not args:
        args = sys.argv[1:]

    (options, args) = parser.parse_args(args)
    set_defaults(options, five_to_six_script)
    validate_options(options)
    MigrationEngine(options).main()

    # Try to enable yum plugins: subscription-manager and product-id
    enabled_yum_plugins = repolib.YumPluginManager.enable_yum_plugins()
    if len(enabled_yum_plugins) > 0:
        print(
            _('WARNING') + '\n\n' +
            repolib.YumPluginManager.warning_message(enabled_yum_plugins) +
            '\n')

    try:
        sys.stdout.flush()
        sys.stderr.flush()
    except IOError as io_err:
        log.error(
            "Error: Unable to print data to stdout/stderr output during exit process: %s"
            % io_err)
Exemplo n.º 2
0
def main():
    logutil.init_logger()
    log = logging.getLogger('rhsm-app.' + __name__)

    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    parser.add_option("--autoheal", dest="autoheal", action="store_true",
            default=False, help="perform an autoheal check")
    parser.add_option("--force", dest="force", action="store_true",
            default=False, help=SUPPRESS_HELP)
    (options, args) = parser.parse_args()
    try:
        _main(options, log)
    except SystemExit as se:
        # sys.exit triggers an exception in older Python versions, which
        # in this case  we can safely ignore as we do not want to log the
        # stack trace. We need to check the code, since we want to signal
        # exit with failure to the caller. Otherwise, we will exit with 0
        if se.code:
            sys.exit(-1)
    except Exception as e:
        log.error("Error while updating certificates using daemon")
        print(_('Unable to update entitlement certificates and repositories'))
        log.exception(e)
        sys.exit(-1)
Exemplo n.º 3
0
def main():
    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    parser.add_option("--register",
                      action='store_true',
                      help=_("launches the registration dialog on startup"))
    options, args = parser.parse_args(args=sys.argv)

    log = logging.getLogger("rhsm-app.subscription-manager-gui")

    try:
        bus = dbus.SessionBus()
    except dbus.exceptions.DBusException as e:
        log.debug("Enabled to connect to dbus SessionBus")
        log.exception(e)
        # Just ignore it if for some reason we can't find the session bus
        bus = None

    if already_running(bus):
        # Attempt to raise the running instance to the forefront
        try:
            remote_object = bus.get_object(BUS_NAME, BUS_PATH)
            remote_object.show_window(dbus_interface=BUS_NAME)
            log.debug(
                "subscription-manager-gui already running, showing main window"
            )
        except dbus.exceptions.DBusException as e:
            log.debug("Error attempting to show main window via dbus")
            log.debug("dbus remote_object with no show_window: %s" %
                      remote_object)
            log.debug(e)
            # failed to raise the window, maybe we raced dbus?
            # fallback to opening a new window
        else:
            # we raised the existing window, we are done
            sys.exit()

    try:
        main = managergui.MainWindow(auto_launch_registration=options.register)

        # Hook into dbus service - only if it is available
        if bus:
            SubscriptionManagerService(main.main_window)

        # Exit the gtk loop when the window is closed
        main.main_window.connect('hide', ga_Gtk.main_quit)

        sys.exit(ga_Gtk.main() or 0)
    except SystemExit as e:
        # this is a non-exceptional exception thrown by Python 2.4, just
        # re-raise, bypassing handle_exception
        raise e
    except KeyboardInterrupt:
        system_exit(0, "\nUser interrupted process.")
    except Exception as e:
        log.exception(e)
        system_exit(1, e)
Exemplo n.º 4
0
    def __init__(self, name="cli", aliases=None, shortdesc=None, primary=False):
        self.name = name
        self.shortdesc = shortdesc
        self.primary = primary
        self.aliases = aliases or []

        # include our own HelpFormatter that doesn't try to break
        # long words, since that fails on multibyte words
        self.parser = OptionParser(usage=self._get_usage(), description=shortdesc,
                                   formatter=WrappedIndentedHelpFormatter())
Exemplo n.º 5
0
def main(args=None, five_to_six_script=False):
    parser = OptionParser(usage=USAGE, formatter=WrappedIndentedHelpFormatter())
    add_parser_options(parser, five_to_six_script)

    # In testing we sometimes specify args, otherwise use the default:
    if not args:
        args = sys.argv[1:]

    (options, args) = parser.parse_args(args)
    set_defaults(options, five_to_six_script)
    validate_options(options)
    MigrationEngine(options).main()
Exemplo n.º 6
0
    def test_cat_manifest(self):
        catman = CatManifestCommand()
        parser = OptionParser()
        parser.add_option("--no-content")
        (options, args) = parser.parse_args([])
        catman.options = options
        catman.args = [_build_valid_manifest()]

        with Capture() as cap:
            catman._do_command()

        self.assertEqual("", cap.err)
        self.assert_string_equals(manifestdata.correct_manifest_output, cap.out)
Exemplo n.º 7
0
    def __init__(self):
        self.rhncfg = initUp2dateConfig()
        self.rhsmcfg = rhsm.config.initConfig()

        self.proxy_host = None
        self.proxy_port = None
        self.proxy_user = None
        self.proxy_pass = None

        self.cp = None
        self.db = ProductDatabase()

        self.parser = OptionParser(usage=USAGE,
                                   formatter=WrappedIndentedHelpFormatter())
        self.add_parser_options()
    except connection.GoneException, ge:
        uuid = ConsumerIdentity.read().getConsumerId()
        if ge.deleted_id == uuid:
            log.critical(_("This consumer's profile has been deleted from the server. Its local certificates will now be archived"))
            managerlib.clean_all_data()
            log.critical(_("Certificates archived to '/etc/pki/consumer.old'. Contact your system administrator if you need more information."))

        raise ge


if __name__ == '__main__':

    logutil.init_logger()
    log = logging.getLogger('rhsm-app.' + __name__)

    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    parser.add_option("--autoheal", dest="autoheal", action="store_true",
            default=False, help="perform an autoheal check")
    (options, args) = parser.parse_args()
    try:
        main(options, log)
    except SystemExit, se:
        # sys.exit triggers an exception in older Python versions, which
        # in this case  we can safely ignore as we do not want to log the
        # stack trace. We need to check the code, since we want to signal
        # exit with failure to the caller. Otherwise, we will exit with 0
        if se.code:
            sys.exit(-1)
    except Exception, e:
        log.error("Error while updating certificates using daemon")
        print _('Unable to update entitlement certificates and repositories')
Exemplo n.º 9
0
 def __init__(self, name="cli", short_desc=None):
     self.shortdesc = short_desc
     self.name = name
     self.parser = OptionParser(usage=self._get_usage(),
                                description=self.shortdesc)
     self._define_custom_opts(self.parser)
Exemplo n.º 10
0
def main():

    log.info("rhsmd started")
    parser = OptionParser(usage=USAGE,
                          formatter=WrappedIndentedHelpFormatter())
    parser.add_option("-d",
                      "--debug",
                      dest="debug",
                      help="Display debug messages",
                      action="store_true",
                      default=False)
    parser.add_option(
        "-k",
        "--keep-alive",
        dest="keep_alive",
        help="Stay running (don't shut down after the first dbus call)",
        action="store_true",
        default=False)
    parser.add_option("-s",
                      "--syslog",
                      dest="syslog",
                      help="Run standalone and log result to syslog",
                      action="store_true",
                      default=False)
    parser.add_option(
        "-f",
        "--force-signal",
        dest="force_signal",
        help="Force firing of a signal " +
        "(valid, expired, warning, partial, classic or registration_required)")
    parser.add_option(
        "-i",
        "--immediate",
        dest="immediate",
        action="store_true",
        default=False,
        help="Fire forced signal immediately (requires --force-signal)")

    options, args = parser.parse_args()

    force_signal = parse_force_signal(options.force_signal)

    if options.immediate and force_signal is None:
        print_error("--immediate must be used with --force-signal")
        sys.exit(-2)

    global enable_debug
    enable_debug = options.debug

    # short-circuit dbus initialization
    if options.syslog:
        log.info("logging subscription status to syslog")
        status = check_status(force_signal)
        if status == RHSM_EXPIRED:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system is missing one or more subscriptions. " +
                "Please run subscription-manager for more information.")
        elif status == RHSM_PARTIALLY_VALID:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system is missing one or more subscriptions " +
                "to fully cover its products. " +
                "Please run subscription-manager for more information.")
        elif status == RHSM_WARNING:
            log_syslog(
                syslog.LOG_NOTICE,
                "This system's subscriptions are about to expire. " +
                "Please run subscription-manager for more information.")
        elif status == RHN_CLASSIC:
            log_syslog(syslog.LOG_INFO,
                       get_branding().RHSMD_REGISTERED_TO_OTHER)
        elif status == RHSM_REGISTRATION_REQUIRED:
            log_syslog(
                syslog.LOG_NOTICE,
                "In order for Subscription Manager to provide your " +
                "system with updates, your system must be registered " +
                "with the Customer Portal. Please enter your Red Hat " +
                "login to ensure your system is up-to-date.")

        # Return an exit code for the program. having valid entitlements is
        # good, so it gets an exit status of 0.
        return status

    # we are not running from cron here, so unset the excepthook
    # though, we may be running from cli, or as a dbus activation. For
    # cli, we should traceback. For dbus, we should try to log it and
    # raise dbus exception?
    sys.excepthook = sys.__excepthook__

    system_bus = dbus.SystemBus()
    loop = ga_GObject.MainLoop()
    checker = StatusChecker(system_bus, options.keep_alive, force_signal, loop)

    if options.immediate:
        checker.entitlement_status_changed(force_signal)

    loop.run()
Exemplo n.º 11
0
    except connection.GoneException, ge:
        uuid = ConsumerIdentity.read().getConsumerId()
        if ge.deleted_id == uuid:
            log.critical(_("This consumer's profile has been deleted from the server. It's local certificates will now be archived"))
            managerlib.clean_all_data()
            log.critical(_("Certificates archived to '/etc/pki/consumer.old'. Contact your system administrator if you need more information."))
        else:
            raise ge


if __name__ == '__main__':

    logutil.init_logger()
    log = logging.getLogger('rhsm-app.' + __name__)

    parser = OptionParser()
    parser.add_option("--autoheal", dest="autoheal", action="store_true",
            default=False, help="perform an autoheal check")
    (options, args) = parser.parse_args()
    try:
        main(options, log)
    except SystemExit:
        # sys.exit triggers an exception in older Python versions, which
        # in this case  we can safely ignore as we do not want to log the
        # stack trace.
        pass
    except Exception, e:
        log.error("Error while updating certificates using daemon")
        print _('Unable to update entitlement certificates and repositories')
        log.exception(e)
        sys.exit(-1)