Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Add ability to install apps from JB release server
Browse files Browse the repository at this point in the history
  • Loading branch information
IKrukov-HORIS committed Dec 25, 2020
1 parent 4417379 commit b770644
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions projector_installer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from .utils import download_file, get_java_version, get_local_addresses

from .dialogs import select_compatible_app, select_new_config_name, list_configs, \
from .dialogs import select_app, select_new_config_name, list_configs, \
find_apps, edit_config, list_apps, select_installed_app, select_run_config, make_run_config, \
get_user_install_input, make_config_from_input

Expand Down Expand Up @@ -316,7 +316,7 @@ def do_list_app(pattern: Optional[str] = None) -> None:
def do_install_app(app_name: Optional[str], auto_run: bool = False, allow_updates: bool = False,
run_browser: bool = True) -> None:
"""Installs specified app."""
app = select_compatible_app(app_name)
app = select_app(app_name)

if app is None:
print('IDE was not selected, exiting...')
Expand Down
14 changes: 11 additions & 3 deletions projector_installer/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .apps import get_installed_apps, get_app_path, is_path_to_app, is_toolbox_path
from .secure_config import generate_token
from .utils import get_local_addresses
from .products import get_compatible_apps, IDEKind, Product
from .products import get_compatible_apps, IDEKind, Product, get_all_apps

DEF_PROJECTOR_PORT: int = 9999

Expand Down Expand Up @@ -101,14 +101,22 @@ def select_ide_kind() -> Optional[IDEKind]:
return select_from_list(kinds, lambda it: it.name, 'Choose IDE type to install or 0 to exit')


def select_compatible_app(pattern: Optional[str] = None) -> Optional[Product]:
def get_app_list(kind: IDEKind, pattern: Optional[str] = None) -> List[Product]:
"""Returns compatible or full app list, depending on user choice"""
compatible = click.prompt('Do you want to choose from Projector-compatible IDE? [y/n]',
type=bool)
return get_compatible_app_names(kind, pattern) if compatible else get_all_apps(kind, pattern)


def select_app(pattern: Optional[str] = None) -> Optional[Product]:
"""Interactively selects app name from list of projector-compatible applications."""
kind = select_ide_kind()

if kind is None:
return None

apps = get_compatible_app_names(kind, pattern)
apps = get_app_list(kind, pattern)

return select_from_list(apps, lambda it: it.name, 'Choose IDE number to install or 0 to exit')


Expand Down
31 changes: 18 additions & 13 deletions projector_installer/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,17 @@ def get_product_releases(kind: IDEKind) -> List[Product]:
return res


def get_products(kind: IDEKind) -> List[Product]:
def get_compatible_products(kind: IDEKind) -> List[Product]:
"""Returns list of all compatible apps with given kind"""
global COMPATIBLE_APPS # pylint: disable=W0603
if not COMPATIBLE_APPS:
COMPATIBLE_APPS = init_compatible_apps()
apps = init_compatible_apps()
return [app for app in apps if app.kind == kind]

return [app for app in COMPATIBLE_APPS if app.kind == kind]

def filter_app_by_name_pattern(data: List[Product], pattern: Optional[str] = None) -> List[Product]:
"""Filters given Product list by given name pattern.
Returns list with single element on exact match."""

def get_compatible_apps(kind: IDEKind, pattern: Optional[str] = None) -> List[Product]:
"""Returns list of compatible apps, matched given pattern."""

apps = [app for app in get_products(kind)
apps = [app for app in data
if pattern is None or app.name.lower().find(pattern.lower()) != -1]

if pattern:
Expand All @@ -193,7 +191,14 @@ def get_compatible_apps(kind: IDEKind, pattern: Optional[str] = None) -> List[Pr

return apps

# class ProductProvider:
#
# def get_product_list(self) -> List[Product]:
# pass

def get_compatible_apps(kind: IDEKind, pattern: Optional[str] = None) -> List[Product]:
"""Returns list of compatible apps, matched given kind and pattern."""
apps = get_compatible_products(kind)
return filter_app_by_name_pattern(apps, pattern)


def get_all_apps(kind: IDEKind, pattern: Optional[str] = None) -> List[Product]:
"""Returns list of all released apps, matched given kind and pattern."""
apps = get_product_releases(kind)
return filter_app_by_name_pattern(apps, pattern)

0 comments on commit b770644

Please sign in to comment.