Skip to content

Commit

Permalink
[feature] Add new group for applications.
Browse files Browse the repository at this point in the history
[feature] Add new group for applications.
  • Loading branch information
keygenqt authored Nov 12, 2024
1 parent 40af157 commit fbc647b
Show file tree
Hide file tree
Showing 31 changed files with 511 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

### Subscribe and like!

[![Version](https://img.shields.io/badge/PyPI-3.1.0-blue?logo=pypi&logoColor=white)](https://pypi.org/project/aurora-cli/)
[![Releases](https://img.shields.io/badge/dynamic/json?url=https://api.github.com/repos/keygenqt/aurora-cli/releases/latest&query=assets[0][download_count]&label=Releases&color=blue&logo=github&prefix=3.1.0%20(&suffix=))](https://github.com/keygenqt/aurora-cli/releases)
[![Version](https://img.shields.io/badge/PyPI-3.2.0-blue?logo=pypi&logoColor=white)](https://pypi.org/project/aurora-cli/)
[![Releases](https://img.shields.io/badge/dynamic/json?url=https://api.github.com/repos/keygenqt/aurora-cli/releases/latest&query=assets[0][download_count]&label=Releases&color=blue&logo=github&prefix=3.2.0%20(&suffix=))](https://github.com/keygenqt/aurora-cli/releases)

![picture](https://github.com/keygenqt/aurora-cli/blob/main/data/images/banner/banner_1000.png?raw=true)

Expand Down
3 changes: 3 additions & 0 deletions aurora_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from aurora_cli.src.base.utils.cache_func import cache_func_clear
from aurora_cli.src.base.utils.output import echo_stdout, echo_verbose, OutResult
from aurora_cli.src.cli.apps.group_apps import group_apps
from aurora_cli.src.cli.device.group_device import group_device, init_subgroups_device
from aurora_cli.src.cli.emulator.group_emulator import group_emulator, init_subgroups_emulator
from aurora_cli.src.cli.flutter.group_flutter import group_flutter, init_subgroups_flutter
Expand Down Expand Up @@ -62,6 +63,8 @@ def main(
def _init_groups():
# group API
main.add_command(group_api)
# group Apps
main.add_command(group_apps)
# group Devices via ssh
main.add_command(group_device)
init_subgroups_device()
Expand Down
73 changes: 71 additions & 2 deletions aurora_cli/src/base/common/features/request_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
"""

import re
from time import sleep

from packaging.version import Version

from aurora_cli.src.base.constants.url import (
URL_AURORA_REPO_VERSIONS,
URL_FLUTTER_SDK_VERSIONS,
URL_FLUTTER_PLUGINS_VERSIONS
URL_FLUTTER_PLUGINS_VERSIONS,
URL_APPS_VERSIONS,
URL_APPS_DESC
)
from aurora_cli.src.base.texts.error import TextError
from aurora_cli.src.base.texts.info import TextInfo
from aurora_cli.src.base.utils.output import OutResult, OutResultError
from aurora_cli.src.base.utils.cache_func import cache_func
from aurora_cli.src.base.utils.output import OutResult, OutResultError, echo_stdout, OutResultInfo
from aurora_cli.src.base.utils.request import request_get


Expand Down Expand Up @@ -149,3 +153,68 @@ def request_flutter_plugins() -> OutResult:
return OutResult(TextInfo.available_versions_flutter(versions), value=versions)
except (Exception,):
return OutResultError(TextError.request_error())


@cache_func(expire=3600)
def request_versions_applications() -> []:
echo_stdout(OutResultInfo(TextInfo.loading_applications()))
try:
page = 1
result = []
while page < 60:
response = request_get(f'{URL_APPS_VERSIONS}?per_page=100&page={page}')
data = response.json()
if len(data) == 0:
break
for release in data:
psdk_version = release['tag_name'].split('-')[-3]
for asset in release['assets']:
if asset['content_type'] == 'application/x-rpm':
full_name = asset['name']
arch = full_name.split('.')[-2]
revision = full_name.split('-')[-1].split('.')[0]
version = full_name.split('-')[-2]
name = full_name.replace(f'-{version}-{revision}.{arch}.rpm', '')
if name != full_name:
result.append({
'url': asset['browser_download_url'],
'size': asset['size'],
'downloads': asset['download_count'],
'name': name,
'full_name': full_name,
'arch': arch,
'revision': revision,
'version': version,
'psdk': psdk_version
})
page += 1
sleep(1)

# Sort and filter latest release package
apps = {}
sorts = {}
for value in result:
name = f'{value['name']}|{value['arch']}'
if not name in sorts.keys():
sorts[name] = [value['version']]
else:
sorts[name].append(value['version'])

for key in sorts.keys():
sorts[key].sort(key=Version)
name = key.split('|')[0]
arch = key.split('|')[-1]
latest = sorts[key][-1]
for item in result:
if item['name'] == name and item['arch'] == arch and item['version'] == latest:
if not name in apps.keys():
apps[name] = {'versions': [item]}
else:
apps[name]['versions'].append(item)
# Get desc
response = request_get(URL_APPS_DESC.format(name))
apps[name]['spec'] = response.json()

return apps
except (Exception,):
return []
5 changes: 2 additions & 3 deletions aurora_cli/src/base/common/features/ssh_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ def ssh_check_package_installed(
) -> bool:
result = ssh_command(
client=client,
execute=f'ls /usr/bin/{package}',
execute=f'file /usr/bin/{package}',
close=close,
)

return 'No such file or directory' not in result.value['stdout'][0]
return ': symbolic link to' in result.value['stdout'][0]
Empty file.
81 changes: 81 additions & 0 deletions aurora_cli/src/base/common/groups/apps/apps_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Copyright 2024 Vitaliy Zarubin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from time import sleep

from aurora_cli.src.base.common.features.request_version import request_versions_applications
from aurora_cli.src.base.texts.error import TextError
from aurora_cli.src.base.texts.info import TextInfo
from aurora_cli.src.base.utils.app import app_exit
from aurora_cli.src.base.utils.argv import argv_is_api
from aurora_cli.src.base.utils.download import check_downloads, downloads
from aurora_cli.src.base.utils.output import echo_stdout, OutResultInfo, OutResultError


def apps_filter_common(search: str, group: str):
apps = request_versions_applications()
if group:
for key in [key for key in apps.keys() if group not in apps[key]['spec']['groups']]:
apps.pop(key, None)

if search:
for key in [key for key in apps.keys() if
str(search).lower() not in str(apps[key]['spec']['name']).lower() and str(
search).lower() not in key]:
apps.pop(key, None)

return apps

def apps_available_common(search: str, group: str):
apps = apps_filter_common(search, group)
if not apps:
echo_stdout(TextInfo.available_apps_empty())
else:
echo_stdout(TextInfo.available_versions_apps(apps))


def apps_download_common(app_id, arch):
is_bar = not argv_is_api()
apps = request_versions_applications()

if app_id not in apps.keys():
echo_stdout(OutResultError(TextError.error_application_id(app_id)))
app_exit()

app = apps[app_id]
build = [build for build in app['versions'] if build['arch'] == arch]

if not build:
echo_stdout(OutResultError(TextError.error_application_arch(arch)))
app_exit()

url = build[0]['url']
urls, files = check_downloads([url], is_check_size=False)

if not urls and not files:
echo_stdout(OutResultError(TextError.get_install_info_error()))
app_exit()

if urls:
echo_stdout(OutResultInfo(TextInfo.application_download_start()))
downloads(urls, is_bar)
sleep(1)

for file in files:
if not file.is_file():
echo_stdout(OutResultError(TextError.get_install_info_error()))
app_exit()

return files[0]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
from aurora_cli.src.base.texts.info import TextInfo
from aurora_cli.src.base.texts.success import TextSuccess
from aurora_cli.src.base.utils.cache_func import cache_func_clear
from aurora_cli.src.base.utils.cache_settings import (
CacheSettingsKey,
cache_settings_save,
Expand Down Expand Up @@ -43,6 +44,7 @@ def settings_clear_common():

def settings_localization_common(language: str):
cache_settings_save(CacheSettingsKey.language, language)
cache_func_clear()
echo_stdout(OutResult(TextSuccess.settings_localization_update()))


Expand Down
2 changes: 1 addition & 1 deletion aurora_cli/src/base/constants/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

APP_NAME = 'aurora-cli'

APP_VERSION = '3.1.0'
APP_VERSION = '3.2.0'

PATH_DIR = '~/.aurora-cli'

Expand Down
4 changes: 4 additions & 0 deletions aurora_cli/src/base/constants/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@
URL_CLANG_FORMAT_CONF_FLUTTER = 'https://gitlab.com/omprussia/flutter/flutter/-/raw/stable/.clang-format'

URL_CLANG_FORMAT_CONF = 'https://gitlab.com/omprussia/demos/IpcCatalog/-/raw/example/.clang-format'

URL_APPS_VERSIONS = 'https://api.github.com/repos/keygenqt/aurora-apps/releases'

URL_APPS_DESC = 'https://raw.githubusercontent.com/keygenqt/aurora-apps/refs/heads/main/apps/{}/spec.json'
24 changes: 24 additions & 0 deletions aurora_cli/src/base/localization/ru/ru_app_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,27 @@ def argument_test_answer_iterate():
@staticmethod
def argument_password():
return 'Root пароль.'

@staticmethod
def argument_app_id():
return 'Укажите ID приложения.'

@staticmethod
def argument_arch():
return 'Укажите архитектуру приложения.'

@staticmethod
def argument_app_device_index():
return 'Укажите индекс устройства.'

@staticmethod
def argument_app_sign_index():
return 'Укажите индекс ключа подписи.'

@staticmethod
def argument_apps_filter():
return 'Отфильтруйте проекты по группе.'

@staticmethod
def argument_apps_search():
return 'Поиск проектов.'
4 changes: 4 additions & 0 deletions aurora_cli/src/base/localization/ru/ru_app_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class TextCommandRu(Enum):
@staticmethod
def command_apps_available():
return 'Получите список доступных приложений для ОС Аврора.'

@staticmethod
def command_device_list():
return 'Получить список устройств.'
Expand Down
4 changes: 4 additions & 0 deletions aurora_cli/src/base/localization/ru/ru_app_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def group_device():
def group_vscode():
return 'Работа с Visual Studio Code.'

@staticmethod
def group_apps():
return 'Приложения доступные для установки.'

@staticmethod
def subgroup_device_package():
return 'Работа с пакетами.'
Expand Down
8 changes: 8 additions & 0 deletions aurora_cli/src/base/localization/ru/ru_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,11 @@ def psdk_sign_error(path):
@staticmethod
def distributive_error(name):
return '<red>Эта функция доступна только для дистрибутива:</red> {}.'.format(name)

@staticmethod
def error_application_id(app_id):
return '<red>Приложение с таким ID не найдено:</red> {}.'.format(app_id)

@staticmethod
def error_application_arch(arch):
return '<red>Приложение с этой архитектурой не найдено:</red> {}.'.format(arch)
24 changes: 24 additions & 0 deletions aurora_cli/src/base/localization/ru/ru_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ def available_versions_psdk(versions: []):
def available_versions_flutter(versions: []):
return '<blue>Доступные версии Flutter для ОС Аврора:</blue>\n{}'.format('\n'.join(versions))

@staticmethod
def available_apps_empty():
return f'<blue>Список проектов пуст.</blue>'

@staticmethod
def available_versions_apps(apps: {}):
return '<blue>Доступное приложения для ОС Aurora:</blue>\n{}'.format('\n\n'.join([(
'> {name} <i>({app_id})</i>\n{groups}\n{desc}\n{repo}'.format(
name=apps[key]['spec']['name'],
groups='[{}]'.format(', '.join(apps[key]['spec']['groups'])),
desc=apps[key]['spec']['desc_ru'],
repo=apps[key]['spec']['repo'],
app_id=key,
)
) for key in apps.keys()]))

@staticmethod
def installed_versions_sdk(versions: []):
return '<blue>Установленная версия Аврора SDK:</blue>\n{}'.format('\n'.join(versions))
Expand Down Expand Up @@ -170,6 +186,10 @@ def psdk_remove_start():
def psdk_download_start():
return '<blue>Загрузка файлов Аврора Platform SDK.</blue>'

@staticmethod
def application_download_start():
return '<blue>Загрузка пакета приложений началась.</blue>'

@staticmethod
def vscode_extensions_flutter(extensions: []):
return '<blue>Будут установлены расширения для работы с Flutter:</blue>\n' + '\n'.join(extensions)
Expand Down Expand Up @@ -311,3 +331,7 @@ def settings_list(values: dict):
@staticmethod
def settings_item_empty():
return 'Значение не установлено.'

@staticmethod
def loading_applications():
return '<blue>Поиск приложений...</blue>'
30 changes: 30 additions & 0 deletions aurora_cli/src/base/texts/app_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,33 @@ def argument_test_answer_iterate():
@localization
def argument_password():
return 'Root password.'

@staticmethod
@localization
def argument_app_id():
return 'Select the application ID.'

@staticmethod
@localization
def argument_arch():
return 'Select the application architecture.'

@staticmethod
@localization
def argument_app_device_index():
return 'Select the device index.'

@staticmethod
@localization
def argument_app_sign_index():
return 'Select the sign key index.'

@staticmethod
@localization
def argument_apps_filter():
return 'Filter projects by group.'

@staticmethod
@localization
def argument_apps_search():
return 'Search projects.'
Loading

0 comments on commit fbc647b

Please sign in to comment.