Commit ab41238d1189d608a3d5c42ca16f4c069a116d4c
1 parent
f7116fe57a
Exists in
master
del sqlite, add yml
Showing 6 changed files with 80 additions and 73 deletions Side-by-side Diff
__pycache__/routes.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2cfg.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2comp.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2rout.cpython-310.pyc
No preview for this file type
k2/k2rout.py
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | import shutil |
| 5 | 5 | from flask import request |
| 6 | 6 | from .k2cfg import k2 |
| 7 | -from .k2comp import Component | |
| 7 | +#from .k2comp import Component | |
| 8 | 8 | from flask_migrate import Migrate |
| 9 | 9 | import requests |
| 10 | 10 | import subprocess |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| ... | ... | @@ -71,16 +71,23 @@ |
| 71 | 71 | |
| 72 | 72 | @components_bp.route('/api/languages', methods=['GET']) |
| 73 | 73 | def find_language(): |
| 74 | - components = Component.query.all() | |
| 74 | + project_folder = 'components' | |
| 75 | + # Зчитати вміст файлу YAML | |
| 76 | + with open(f"{project_folder}/components.yml", 'r') as file: | |
| 77 | + components_data = yaml.safe_load(file) | |
| 78 | + | |
| 75 | 79 | languages_paths = [] |
| 80 | + | |
| 76 | 81 | # Додаємо головну директорію languages |
| 77 | 82 | languages_paths.append('languages') |
| 78 | - # Знаходимо шляхи до директорій languages всередині папки components | |
| 79 | - for component in components: | |
| 80 | - component_languages_directory = 'components/' + component.name + '/' + component.name + '/languages' | |
| 81 | - languages_paths.append(component_languages_directory) | |
| 83 | + | |
| 84 | + # Знаходимо шляхи до директорій languages для кожного компонента з даних YAML | |
| 85 | + if components_data is not None: | |
| 86 | + for component in components_data['components']: | |
| 87 | + component_languages_directory = f"components/{component['name']}/{component['name']}/languages" | |
| 88 | + languages_paths.append(component_languages_directory) | |
| 89 | + | |
| 82 | 90 | result = ';'.join(languages_paths) |
| 83 | - print(result) | |
| 84 | 91 | return result |
| 85 | 92 | |
| 86 | 93 | |
| ... | ... | @@ -189,71 +196,71 @@ |
| 189 | 196 | return render_template('component-info-site.html', selected_component=selected_component) |
| 190 | 197 | |
| 191 | 198 | |
| 192 | -@components_bp.route('/install_components_git/<string:component_id>') | |
| 193 | -def install_components_git(component_id): | |
| 194 | - # Шлях до головної папки проекту | |
| 195 | - project_folder = 'components' | |
| 196 | - # component = Component.get_repository_by_id(component_id) | |
| 197 | - response = requests.get(f'{k2.update_domain}api/components') | |
| 198 | - json_data = response.json() | |
| 199 | - selected_component = next((component for component in json_data if component['id'] == component_id), None) | |
| 200 | - # Назва репозиторія | |
| 201 | - repository_name = selected_component['name'] | |
| 202 | - # Шлях до папки репозиторія в межах проекту | |
| 203 | - repository_folder = os.path.join(project_folder, repository_name) | |
| 204 | - # URL репозиторія | |
| 205 | - | |
| 206 | - git_repo_url = selected_component['git_link'] | |
| 207 | - try: | |
| 208 | - # Перевірка наявності папки репозиторія | |
| 209 | - if not os.path.exists(repository_folder): | |
| 210 | - # Створення папки репозиторія | |
| 211 | - os.makedirs(repository_folder) | |
| 212 | - # Шлях до файлу __init__.py | |
| 213 | - init_file = os.path.join(repository_folder, '__init__.py') | |
| 214 | - # Перевірка наявності файлу __init__.py | |
| 215 | - if not os.path.exists(init_file): | |
| 216 | - # Створення пустого файлу __init__.py | |
| 217 | - open(init_file, 'a').close() | |
| 218 | - # підключення до приватного репозиторію | |
| 219 | - # os.environ['GITLAB_PRIVATE_TOKEN'] = '8xxTpxrKVDGoXD5ynjiW' | |
| 220 | - # git_repo_url_with_token = git_repo_url.replace('https://', | |
| 221 | - # f'https://oauth2:{os.environ["GITLAB_PRIVATE_TOKEN"]}@') | |
| 222 | - | |
| 223 | - # Команда для встановлення з використанням git_repo_url і повного шляху до папки репозиторія | |
| 224 | - command = ['venv/Scripts/python.exe', '-m', 'pip', 'install', '--use-pep517', 'git+' + git_repo_url, | |
| 225 | - '--target=' + repository_folder] | |
| 226 | - # Виконуємо команду встановлення | |
| 227 | - subprocess.check_call(command) | |
| 228 | - | |
| 229 | - # Шлях до файлу, до якого потрібно додати код | |
| 230 | - file_path = 'routes.py' | |
| 231 | - # Код, який потрібно додати | |
| 232 | - code = selected_component['dependencies'] | |
| 233 | - # Відкриття файлу у режимі дозапису | |
| 234 | - with open(file_path, 'a') as file: | |
| 235 | - # Запис нового коду у файл | |
| 236 | - file.write('\n') | |
| 237 | - file.write(code) | |
| 238 | - file.write('\n') | |
| 239 | - component = Component.query.filter_by(name=selected_component['name']).first() | |
| 240 | - if not component: | |
| 241 | - new_component = Component( | |
| 242 | - name=selected_component['name'], | |
| 243 | - description=selected_component['description'], | |
| 244 | - version=selected_component['version'], | |
| 245 | - git_link=selected_component['git_link'], | |
| 246 | - dependencies=selected_component['dependencies'], | |
| 247 | - installed=True | |
| 248 | - ) | |
| 249 | - # Add the new component to the database | |
| 250 | - db.session.add(new_component) | |
| 251 | - db.session.commit() | |
| 252 | - | |
| 253 | - # Повертаємо повідомлення про успішне встановлення | |
| 254 | - return f'Installed successfully <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 255 | - except subprocess.CalledProcessError as e: | |
| 256 | - return 'Error installing : ' + str(e) | |
| 199 | +# @components_bp.route('/install_components_git/<string:component_id>') | |
| 200 | +# def install_components_git(component_id): | |
| 201 | +# # Шлях до головної папки проекту | |
| 202 | +# project_folder = 'components' | |
| 203 | +# # component = Component.get_repository_by_id(component_id) | |
| 204 | +# response = requests.get(f'{k2.update_domain}api/components') | |
| 205 | +# json_data = response.json() | |
| 206 | +# selected_component = next((component for component in json_data if component['id'] == component_id), None) | |
| 207 | +# # Назва репозиторія | |
| 208 | +# repository_name = selected_component['name'] | |
| 209 | +# # Шлях до папки репозиторія в межах проекту | |
| 210 | +# repository_folder = os.path.join(project_folder, repository_name) | |
| 211 | +# # URL репозиторія | |
| 212 | +# | |
| 213 | +# git_repo_url = selected_component['git_link'] | |
| 214 | +# try: | |
| 215 | +# # Перевірка наявності папки репозиторія | |
| 216 | +# if not os.path.exists(repository_folder): | |
| 217 | +# # Створення папки репозиторія | |
| 218 | +# os.makedirs(repository_folder) | |
| 219 | +# # Шлях до файлу __init__.py | |
| 220 | +# init_file = os.path.join(repository_folder, '__init__.py') | |
| 221 | +# # Перевірка наявності файлу __init__.py | |
| 222 | +# if not os.path.exists(init_file): | |
| 223 | +# # Створення пустого файлу __init__.py | |
| 224 | +# open(init_file, 'a').close() | |
| 225 | +# # підключення до приватного репозиторію | |
| 226 | +# # os.environ['GITLAB_PRIVATE_TOKEN'] = '8xxTpxrKVDGoXD5ynjiW' | |
| 227 | +# # git_repo_url_with_token = git_repo_url.replace('https://', | |
| 228 | +# # f'https://oauth2:{os.environ["GITLAB_PRIVATE_TOKEN"]}@') | |
| 229 | +# | |
| 230 | +# # Команда для встановлення з використанням git_repo_url і повного шляху до папки репозиторія | |
| 231 | +# command = ['venv/Scripts/python.exe', '-m', 'pip', 'install', '--use-pep517', 'git+' + git_repo_url, | |
| 232 | +# '--target=' + repository_folder] | |
| 233 | +# # Виконуємо команду встановлення | |
| 234 | +# subprocess.check_call(command) | |
| 235 | +# | |
| 236 | +# # Шлях до файлу, до якого потрібно додати код | |
| 237 | +# file_path = 'routes.py' | |
| 238 | +# # Код, який потрібно додати | |
| 239 | +# code = selected_component['dependencies'] | |
| 240 | +# # Відкриття файлу у режимі дозапису | |
| 241 | +# with open(file_path, 'a') as file: | |
| 242 | +# # Запис нового коду у файл | |
| 243 | +# file.write('\n') | |
| 244 | +# file.write(code) | |
| 245 | +# file.write('\n') | |
| 246 | +# component = Component.query.filter_by(name=selected_component['name']).first() | |
| 247 | +# if not component: | |
| 248 | +# new_component = Component( | |
| 249 | +# name=selected_component['name'], | |
| 250 | +# description=selected_component['description'], | |
| 251 | +# version=selected_component['version'], | |
| 252 | +# git_link=selected_component['git_link'], | |
| 253 | +# dependencies=selected_component['dependencies'], | |
| 254 | +# installed=True | |
| 255 | +# ) | |
| 256 | +# # Add the new component to the database | |
| 257 | +# db.session.add(new_component) | |
| 258 | +# db.session.commit() | |
| 259 | +# | |
| 260 | +# # Повертаємо повідомлення про успішне встановлення | |
| 261 | +# return f'Installed successfully <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 262 | +# except subprocess.CalledProcessError as e: | |
| 263 | +# return 'Error installing : ' + str(e) | |
| 257 | 264 | |
| 258 | 265 | |
| 259 | 266 | @components_bp.route('/install_components/<string:component_id>') |
languages/babel_translation_directories.yml