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

Commit

Permalink
IDEKind selection before ide install
Browse files Browse the repository at this point in the history
  • Loading branch information
IKrukov-HORIS committed Dec 25, 2020
1 parent 89df0e1 commit a8c8300
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 184 deletions.
22 changes: 4 additions & 18 deletions projector_installer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Optional, List
from os import path, system, uname

from .apps import get_compatible_apps, get_app_path, get_installed_apps, get_product_info, \
from .apps import get_app_path, get_installed_apps, get_product_info, \
unpack_app, get_java_path, get_path_to_latest_app
from .log_utils import init_log, shutdown_log, get_path_to_log
from .secure_config import get_ca_crt_file, parse_custom_fqdns
Expand Down Expand Up @@ -316,26 +316,12 @@ 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."""
apps = get_compatible_apps(app_name)
app = select_compatible_app(app_name)

if len(apps) == 0:
print('There are no known IDEs matched to the given name.')
if app_name is None:
print('Try to reinstall Projector.')
print('Exiting...')
if app is None:
print('IDE was not selected, exiting...')
sys.exit(1)

if len(apps) > 1:
app_name = select_compatible_app(app_name)

if app_name is None:
print('IDE was not selected, exiting...')
sys.exit(1)
else:
app_name = apps[0].name

apps = get_compatible_apps(app_name)
app = apps[0]
config_name_hint = make_config_name(app.name)
user_input = get_user_install_input(config_name_hint, auto_run)

Expand Down
27 changes: 1 addition & 26 deletions projector_installer/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
from typing import Optional, List
import json

from . import global_config
from .global_config import get_apps_dir, init_compatible_apps
from .installable_app import InstallableApp
from .global_config import get_apps_dir
from .utils import unpack_tar_file

IDEA_PATH_SELECTOR = 'idea.paths.selector'
Expand All @@ -26,29 +24,6 @@ def get_installed_apps(pattern: Optional[str] = None) -> List[str]:
return res


def get_compatible_apps(pattern: Optional[str] = None) -> List[InstallableApp]:
"""Returns list of compatible apps, matched given pattern."""
if not global_config.COMPATIBLE_APPS:
global_config.COMPATIBLE_APPS = init_compatible_apps()

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

if pattern:
for app in apps:
if pattern.lower() == app.name.lower():
return [app]

return apps


def get_compatible_app_names(pattern: Optional[str] = None) -> List[str]:
"""Get sorted list of projector-compatible applications, matches given pattern."""
res = [app.name for app in get_compatible_apps(pattern)]
res.sort()
return res


def get_app_path(app_name: str) -> str:
"""Returns full path to given app."""
return join(get_apps_dir(), app_name)
Expand Down
77 changes: 59 additions & 18 deletions projector_installer/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
import click

from .run_config import get_run_configs, RunConfig, get_run_config_names, get_used_projector_ports
from .apps import get_installed_apps, get_app_path, get_compatible_app_names, \
is_path_to_app, is_toolbox_path

from .global_config import DEF_PROJECTOR_PORT
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

DEF_PROJECTOR_PORT: int = 9999


def get_compatible_app_names(kind: IDEKind, pattern: Optional[str] = None) -> List[Product]:
"""Get sorted list of projector-compatible applications, matches given pattern."""
res = get_compatible_apps(kind, pattern)
return sorted(res, key=lambda x: x.name)


def display_run_configs_names(config_names: List[str]) -> None:
Expand All @@ -39,25 +45,34 @@ def display_run_configs(run_configs: Dict[str, RunConfig]) -> None:
display_run_configs_names(config_names)


def print_selection_list(names: List[str]) -> None:
"""Pretty list for selection."""
for i, name in enumerate(names):
print(f'\t{i + 1:4}. {name}')


def find_apps(pattern: Optional[str] = None) -> None:
"""Pretty-print projector-compatible applications, matched to given pattern."""
app_names = get_compatible_app_names(pattern)
for i, app_name in enumerate(app_names):
print(f'\t{i + 1:4}. {app_name}')
apps: List[Product] = []

for kind in IDEKind:
apps = apps + get_compatible_app_names(kind, pattern)

def list_apps(pattern: Optional[str] = None) -> None:
"""Pretty print the list of installed ide."""
for i, app in enumerate(get_installed_apps(pattern)):
print(f'\t{i + 1:4}. {app}')
print_selection_list(list(map(lambda x: x.name, apps)))


def list_apps(pattern: Optional[str]) -> None:
"""Print list of installed apps"""
apps = get_installed_apps(pattern)
print_selection_list(apps)


def select_installed_app(pattern: Optional[str] = None) -> Optional[str]:
"""Interactively selects installed ide."""
apps: List[str] = get_installed_apps(pattern)

while True:
list_apps(pattern)
print_selection_list(apps)
prompt = f'Choose an IDE number to uninstall or 0 to exit: [0-{len(apps)}]'
app_number: int = click.prompt(prompt, type=int)

Expand All @@ -71,13 +86,39 @@ def select_installed_app(pattern: Optional[str] = None) -> Optional[str]:
return apps[app_number - 1]


def select_compatible_app(pattern: Optional[str] = None) -> Optional[str]:
def select_ide_kind() -> Optional[IDEKind]:
"""Interactively selects desired IDE kind"""
kinds = [k for k in IDEKind if k != IDEKind.Unknown]
kind_names = list(map(lambda x: x.name, kinds))
prompt = f'Choose IDE type to install or 0 to exit: [0-{len(kind_names)}]'

while True:
print_selection_list(kind_names)
pos: int = click.prompt(prompt, type=int)

if pos < 0 or pos > len(kinds):
print('Invalid number.')
continue

if pos == 0:
return None

return kinds[pos - 1]


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

if kind is None:
return None

apps = get_compatible_app_names(kind, pattern)
app_names: List[str] = list(map(lambda x: x.name, apps))
prompt = f'Choose IDE number to install or 0 to exit: [0-{len(app_names)}]'

while True:
find_apps(pattern)
prompt = f'Choose IDE number to install or 0 to exit: [0-{len(app_names)}]'
print_selection_list(app_names)
app_number: int = click.prompt(prompt, type=int)

if app_number < 0 or app_number > len(app_names):
Expand All @@ -87,7 +128,7 @@ def select_compatible_app(pattern: Optional[str] = None) -> Optional[str]:
if app_number == 0:
return None

return app_names[app_number - 1]
return apps[app_number - 1]


def select_unused_config_name(hint: str) -> str:
Expand Down Expand Up @@ -162,7 +203,7 @@ def select_installed_app_path() -> Optional[str]:
apps = get_installed_apps()

while True:
list_apps()
print_selection_list(apps)
prompt = f'Choose IDE number to install or 0 to exit: [0-{len(apps)}]'
app_number = click.prompt(prompt, type=int)

Expand Down
16 changes: 0 additions & 16 deletions projector_installer/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"""

import sys
from typing import List
from shutil import rmtree
from os.path import dirname, join, expanduser, abspath

from .installable_app import InstallableApp, load_compatible_apps
from .utils import create_dir_if_not_exist

USER_HOME: str = expanduser('~')
INSTALL_DIR: str = dirname(abspath(__file__))
DEF_PROJECTOR_PORT: int = 9999
COMPATIBLE_IDE_FILE: str = join(INSTALL_DIR, 'compatible_ide.json')
DEF_CONFIG_DIR: str = '.projector'
SSL_PROPERTIES_FILE = 'ssl.properties'
BUNDLED_DIR: str = 'bundled'
Expand Down Expand Up @@ -68,18 +64,6 @@ def get_ssl_dir() -> str:
return join(config_dir, 'ssl')


COMPATIBLE_APPS: List[InstallableApp] = []


def init_compatible_apps() -> List[InstallableApp]:
"""Initializes compatible apps list."""
try:
return load_compatible_apps(COMPATIBLE_IDE_FILE)
except IOError as error:
print(f'Cannot load compatible ide file: {str(error)}. Exiting...')
sys.exit(2)


def get_projector_server_dir() -> str:
"""Returns directory with projector server jar"""
return join(INSTALL_DIR, BUNDLED_DIR, SERVER_DIR)
Expand Down
106 changes: 0 additions & 106 deletions projector_installer/installable_app.py

This file was deleted.

Loading

0 comments on commit a8c8300

Please sign in to comment.