コード例 #1
0
    def ask_password(context: ApplicationContext,
                     i18n: I18n,
                     app_config: Optional[dict] = None,
                     comp_manager: Optional[QtComponentsManager] = None,
                     tries: int = 3) -> Tuple[bool, Optional[str]]:

        current_config = CoreConfigManager().get_config(
        ) if not app_config else app_config

        store_password = bool(current_config['store_root_password'])

        if store_password and isinstance(context.root_password,
                                         str) and validate_password(
                                             context.root_password):
            return True, context.root_password

        if comp_manager:
            comp_manager.save_states(state_id=ACTION_ASK_ROOT,
                                     only_visible=True)
            comp_manager.disable_visible()

        diag = RootDialog(i18n=i18n, max_tries=tries)
        diag.exec()
        password = diag.password

        if comp_manager:
            comp_manager.restore_state(ACTION_ASK_ROOT)

        if isinstance(password, str) and store_password:
            context.root_password = password

        return (True, password) if diag.valid else (False, None)
コード例 #2
0
def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]:
    i18n = generate_i18n(app_config, resource.get_path('locale'))

    cache_cleaner = CacheCleaner()

    cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']), cleaner=cache_cleaner)
    icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration']))

    http_client = HttpClient(logger)

    context = ApplicationContext(i18n=i18n,
                                 http_client=http_client,
                                 download_icons=bool(app_config['download']['icons']),
                                 app_root_dir=ROOT_DIR,
                                 cache_factory=cache_factory,
                                 disk_loader_factory=DefaultDiskCacheLoaderFactory(logger),
                                 logger=logger,
                                 distro=util.get_distro(),
                                 file_downloader=AdaptableFileDownloader(logger, bool(app_config['download']['multithreaded']),
                                                                         i18n, http_client, app_config['download']['multithreaded_client']),
                                 app_name=__app_name__,
                                 internet_checker=InternetChecker(offline=app_args.offline))

    managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY)

    if app_args.reset:
        util.clean_app_files(managers)
        exit(0)

    manager = GenericSoftwareManager(managers, context=context, config=app_config)

    app = new_qt_application(app_config=app_config, logger=logger, quit_on_last_closed=True)

    if app_args.settings:  # only settings window
        manager.cache_available_managers()
        return app, SettingsWindow(manager=manager, i18n=i18n, screen_size=app.primaryScreen().size(), window=None)
    else:
        manage_window = ManageWindow(i18n=i18n,
                                     manager=manager,
                                     icon_cache=icon_cache,
                                     screen_size=app.primaryScreen().size(),
                                     config=app_config,
                                     context=context,
                                     http_client=http_client,
                                     icon=util.get_default_icon()[1],
                                     logger=logger)

        prepare = PreparePanel(screen_size=app.primaryScreen().size(),
                               context=context,
                               manager=manager,
                               i18n=i18n,
                               manage_window=manage_window,
                               app_config=app_config)
        cache_cleaner.start()

        return app, prepare
コード例 #3
0
ファイル: app.py プロジェクト: vinifmor/bauh
def main():
    if not os.getenv('PYTHONUNBUFFERED'):
        os.environ['PYTHONUNBUFFERED'] = '1'

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    args = cli_args.read()
    logger = logs.new_logger(__app_name__, False)

    app_config = CoreConfigManager().get_config()
    http_client = HttpClient(logger)

    i18n = generate_i18n(app_config, resource.get_path('locale'))

    cache_factory = DefaultMemoryCacheFactory(expiration_time=0)

    downloader = AdaptableFileDownloader(
        logger=logger,
        multithread_enabled=app_config['download']['multithreaded'],
        multithread_client=app_config['download']['multithreaded_client'],
        i18n=i18n,
        http_client=http_client,
        check_ssl=app_config['download']['check_ssl'])

    context = ApplicationContext(
        i18n=i18n,
        http_client=http_client,
        download_icons=bool(app_config['download']['icons']),
        app_root_dir=ROOT_DIR,
        cache_factory=cache_factory,
        disk_loader_factory=DefaultDiskCacheLoaderFactory(logger),
        logger=logger,
        distro=util.get_distro(),
        file_downloader=downloader,
        app_name=__app_name__,
        app_version=__version__,
        internet_checker=InternetChecker(offline=False),
        suggestions_mapping=None,  # TODO not needed at the moment
        root_user=user.is_root())

    managers = gems.load_managers(context=context,
                                  locale=i18n.current_key,
                                  config=app_config,
                                  default_locale=DEFAULT_I18N_KEY,
                                  logger=logger)

    cli = CLIManager(
        GenericSoftwareManager(managers, context=context, config=app_config))

    if args.command == 'updates':
        cli.list_updates(args.format)
コード例 #4
0
ファイル: root.py プロジェクト: Archman-OS/bauh
def ask_root_password(context: ApplicationContext, i18n: I18n, app_config: dict = None) -> Tuple[str, bool]:

    cur_config = read_config() if not app_config else app_config
    store_password = bool(cur_config['store_root_password'])

    if store_password and context.root_password and validate_password(context.root_password):
        return context.root_password, True

    diag = QInputDialog()
    diag.setStyleSheet("""QLineEdit {  border-radius: 5px; font-size: 16px; border: 1px solid lightblue }""")
    diag.setInputMode(QInputDialog.TextInput)
    diag.setTextEchoMode(QLineEdit.Password)
    diag.setWindowIcon(util.get_default_icon()[1])
    diag.setWindowTitle(i18n['popup.root.title'])
    diag.setLabelText('')
    diag.setOkButtonText(i18n['popup.root.continue'].capitalize())
    diag.setCancelButtonText(i18n['popup.button.cancel'].capitalize())
    diag.resize(400, 200)

    for attempt in range(3):

        ok = diag.exec_()

        if ok:
            if not validate_password(diag.textValue()):

                body = i18n['popup.root.bad_password.body']

                if attempt == 2:
                    body += '. ' + i18n['popup.root.bad_password.last_try']

                show_message(title=i18n['popup.root.bad_password.title'],
                             body=body,
                             type_=MessageType.ERROR)
                ok = False
                diag.setTextValue('')

            if ok:
                if store_password:
                    context.root_password = diag.textValue()

                return diag.textValue(), ok
        else:
            break

    return '', False
コード例 #5
0
ファイル: app.py プロジェクト: pigeonsintheattic/bauh
def main():
    if not os.getenv('PYTHONUNBUFFERED'):
        os.environ['PYTHONUNBUFFERED'] = '1'

    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    args = cli_args.read()
    logger = logs.new_logger(__app_name__, False)

    app_config = config.read_config(update_file=True)
    http_client = HttpClient(logger)

    i18n = generate_i18n(app_config, resource.get_path('locale'))

    cache_factory = DefaultMemoryCacheFactory(expiration_time=0)

    context = ApplicationContext(
        i18n=i18n,
        http_client=http_client,
        download_icons=bool(app_config['download']['icons']),
        app_root_dir=ROOT_DIR,
        cache_factory=cache_factory,
        disk_loader_factory=DefaultDiskCacheLoaderFactory(logger),
        logger=logger,
        distro=util.get_distro(),
        file_downloader=AdaptableFileDownloader(
            logger, bool(app_config['download']['multithreaded']), i18n,
            http_client, app_config['download']['multithreaded_client']),
        app_name=__app_name__)

    managers = gems.load_managers(context=context,
                                  locale=i18n.current_key,
                                  config=app_config,
                                  default_locale=DEFAULT_I18N_KEY)

    cli = CLIManager(
        GenericSoftwareManager(managers, context=context, config=app_config))

    if args.command == 'updates':
        cli.list_updates(args.format)
コード例 #6
0
ファイル: root.py プロジェクト: tulliana/bauh
def ask_root_password(context: ApplicationContext,
                      i18n: I18n,
                      app_config: dict = None) -> Tuple[str, bool]:

    cur_config = read_config() if not app_config else app_config
    store_password = bool(cur_config['store_root_password'])

    if store_password and context.root_password and validate_password(
            context.root_password):
        return context.root_password, True

    diag = QInputDialog(flags=Qt.CustomizeWindowHint | Qt.WindowTitleHint)
    diag.setStyleSheet(
        """QLineEdit {  border-radius: 5px; font-size: 16px; border: 1px solid lightblue }"""
    )
    diag.setInputMode(QInputDialog.TextInput)
    diag.setTextEchoMode(QLineEdit.Password)
    diag.setWindowIcon(util.get_default_icon()[1])
    diag.setWindowTitle(i18n['popup.root.title'])
    diag.setLabelText('')
    diag.setOkButtonText(i18n['popup.root.continue'].capitalize())
    diag.setCancelButtonText(i18n['popup.button.cancel'].capitalize())

    bt_box = [c for c in diag.children() if isinstance(c, QDialogButtonBox)][0]

    for bt in bt_box.buttons():
        if bt_box.buttonRole(bt) == QDialogButtonBox.AcceptRole:
            bt.setStyleSheet(css.OK_BUTTON)

        bt.setCursor(QCursor(Qt.PointingHandCursor))
        bt.setIcon(QIcon())

    diag.resize(400, 200)

    for attempt in range(3):

        ok = diag.exec_()

        if ok:
            if not validate_password(diag.textValue()):

                body = i18n['popup.root.bad_password.body']

                if attempt == 2:
                    body += '. ' + i18n['popup.root.bad_password.last_try']

                show_message(title=i18n['popup.root.bad_password.title'],
                             body=body,
                             type_=MessageType.ERROR)
                ok = False
                diag.setTextValue('')

            if ok:
                if store_password:
                    context.root_password = diag.textValue()

                return diag.textValue(), ok
        else:
            break

    return '', False
コード例 #7
0
ファイル: manage.py プロジェクト: vinifmor/bauh
def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]:
    i18n = generate_i18n(app_config, resource.get_path('locale'))

    cache_cleaner = CacheCleaner()

    cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']), cleaner=cache_cleaner)
    icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration']))

    http_client = HttpClient(logger)

    downloader = AdaptableFileDownloader(logger=logger, multithread_enabled=app_config['download']['multithreaded'],
                                         multithread_client=app_config['download']['multithreaded_client'],
                                         i18n=i18n, http_client=http_client,
                                         check_ssl=app_config['download']['check_ssl'])

    context = ApplicationContext(i18n=i18n,
                                 http_client=http_client,
                                 download_icons=bool(app_config['download']['icons']),
                                 app_root_dir=ROOT_DIR,
                                 cache_factory=cache_factory,
                                 disk_loader_factory=DefaultDiskCacheLoaderFactory(logger),
                                 logger=logger,
                                 distro=util.get_distro(),
                                 file_downloader=downloader,
                                 app_name=__app_name__,
                                 app_version=__version__,
                                 internet_checker=InternetChecker(offline=app_args.offline),
                                 suggestions_mapping=read_suggestions_mapping(),
                                 root_user=user.is_root())

    managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config,
                                  default_locale=DEFAULT_I18N_KEY, logger=logger)

    if app_args.reset:
        util.clean_app_files(managers)
        exit(0)

    force_suggestions = bool(app_args.suggestions)
    manager = GenericSoftwareManager(managers, context=context, config=app_config, force_suggestions=force_suggestions)

    app = new_qt_application(app_config=app_config, logger=logger, quit_on_last_closed=True)

    screen_size = app.primaryScreen().size()
    context.screen_width, context.screen_height = screen_size.width(), screen_size.height()
    logger.info(f"Screen: {screen_size.width()} x {screen_size.height()} "
                f"(DPI: {int(app.primaryScreen().logicalDotsPerInch())})")

    if app_args.settings:  # only settings window
        manager.cache_available_managers()
        return app, SettingsWindow(manager=manager, i18n=i18n, window=None)
    else:
        manage_window = ManageWindow(i18n=i18n,
                                     manager=manager,
                                     icon_cache=icon_cache,
                                     screen_size=screen_size,
                                     config=app_config,
                                     context=context,
                                     http_client=http_client,
                                     icon=util.get_default_icon()[1],
                                     force_suggestions=force_suggestions,
                                     logger=logger)

        prepare = PreparePanel(screen_size=screen_size,
                               context=context,
                               manager=manager,
                               i18n=i18n,
                               manage_window=manage_window,
                               app_config=app_config,
                               force_suggestions=force_suggestions)
        cache_cleaner.start()

        return app, prepare