def _gen_i18n_data(app_config: dict, locale_dir: str) -> Tuple[str, dict, str, dict]: i18n_key, current_i18n = translation.get_locale_keys(app_config['locale'], locale_dir=locale_dir) default_i18n = translation.get_locale_keys( DEFAULT_I18N_KEY, locale_dir=locale_dir)[1] if i18n_key != DEFAULT_I18N_KEY else {} return i18n_key, current_i18n, DEFAULT_I18N_KEY, default_i18n
def load_managers(locale: str, context: ApplicationContext, config: dict, default_locale: str, logger: Logger) -> List[SoftwareManager]: managers = [] forbidden_gems = {gem for gem in read_forbidden_gems()} for f in os.scandir(f'{ROOT_DIR}/gems'): if f.is_dir() and f.name != '__pycache__': if f.name in forbidden_gems: logger.warning( f"gem '{f.name}' could not be loaded because it was marked as forbidden in '{FORBIDDEN_GEMS_FILE}'" ) continue loader = pkgutil.find_loader(f'bauh.gems.{f.name}.controller') if loader: module = loader.load_module() manager_class = find_manager(module) if manager_class: if locale: locale_path = f'{f.path}/resources/locale' if os.path.exists(locale_path): context.i18n.current.update( translation.get_locale_keys( locale, locale_path)[1]) if default_locale and context.i18n.default: context.i18n.default.update( translation.get_locale_keys( default_locale, locale_path)[1]) man = manager_class(context=context) if config['gems'] is None: man.set_enabled(man.is_default_enabled()) else: man.set_enabled(f.name in config['gems']) managers.append(man) return managers
def load_managers(locale: str, context: ApplicationContext, config: dict, default_locale: str) -> List[SoftwareManager]: managers = [] for f in os.scandir(ROOT_DIR + '/gems'): if f.is_dir() and f.name != '__pycache__': loader = pkgutil.find_loader('bauh.gems.{}.controller'.format( f.name)) if loader: module = loader.load_module() manager_class = find_manager(module) if manager_class: if locale: locale_path = '{}/resources/locale'.format(f.path) if os.path.exists(locale_path): context.i18n.current.update( translation.get_locale_keys( locale, locale_path)[1]) if default_locale and context.i18n.default: context.i18n.default.update( translation.get_locale_keys( default_locale, locale_path)[1]) man = manager_class(context=context) if config['gems'] is None: man.set_enabled(man.is_default_enabled()) else: man.set_enabled(f.name in config['gems']) managers.append(man) return managers
def main(): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) args = app_args.read() logger = logs.new_logger(__app_name__, bool(args.logs)) local_config = config.read_config(update_file=True) if local_config['ui']['auto_scale']: os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1' logger.info("Auto screen scale factor activated") if local_config['ui']['hdpi']: logger.info("HDPI settings activated") QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) i18n_key, current_i18n = translation.get_locale_keys( local_config['locale']) default_i18n = translation.get_locale_keys( DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {} i18n = I18n(i18n_key, current_i18n, DEFAULT_I18N_KEY, default_i18n) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=int( local_config['memory_cache']['data_expiration']), cleaner=cache_cleaner) icon_cache = cache_factory.new( int(local_config['memory_cache']['icon_expiration'])) http_client = HttpClient(logger) context = ApplicationContext( i18n=i18n, http_client=http_client, disk_cache=bool(local_config['disk_cache']['enabled']), download_icons=bool(local_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory( disk_cache_enabled=bool(local_config['disk_cache']['enabled']), logger=logger), logger=logger, distro=util.get_distro(), file_downloader=AdaptableFileDownloader( logger, bool(local_config['download']['multithreaded']), i18n, http_client), app_name=__app_name__) managers = gems.load_managers(context=context, locale=i18n_key, config=local_config, default_locale=DEFAULT_I18N_KEY) if args.reset: util.clean_app_files(managers) exit(0) manager = GenericSoftwareManager(managers, context=context, config=local_config) manager.prepare() app = QApplication(sys.argv) app.setQuitOnLastWindowClosed( False ) # otherwise windows opened through the tray icon kill the aplication when closed app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) app_icon = util.get_default_icon()[1] app.setWindowIcon(app_icon) if local_config['ui']['style']: app.setStyle(str(local_config['ui']['style'])) else: if app.style().objectName().lower() not in {'fusion', 'breeze'}: app.setStyle('Fusion') manage_window = ManageWindow(i18n=i18n, manager=manager, icon_cache=icon_cache, screen_size=app.primaryScreen().size(), config=local_config, context=context, http_client=http_client, icon=app_icon, logger=logger) if args.tray: tray_icon = TrayIcon(i18n=i18n, manager=manager, manage_window=manage_window, screen_size=app.primaryScreen().size(), config=local_config) manage_window.set_tray_icon(tray_icon) tray_icon.show() if args.show_panel: tray_icon.show_manage_window() else: manage_window.refresh_apps() manage_window.show() cache_cleaner.start() Thread(target=config.remove_old_config, args=(logger, ), daemon=True).start() sys.exit(app.exec_())