diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..9dfeeb7 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,28 @@ +### Описание PR'ра + + + +### Медиа + + +### Техническая информация +- [ ] PR полностью завершён. +- [ ] Мне **НЕ** нужна помощь для завершения PR. +- [ ] Проверено на локальной машине. +- [ ] Документация обновлена. +- [ ] Тесты обновлены / добавлены. + + + + + + + + + +### Изменения + +changes: +- Изменение 1: подробное описание изменения. +- Изменение 2: подробное описание изменения. +- Изменение 3: подробное описание изменения. diff --git a/.github/workflows/assignee.yml b/.github/workflows/assignee.yml new file mode 100644 index 0000000..c5136d3 --- /dev/null +++ b/.github/workflows/assignee.yml @@ -0,0 +1,24 @@ +name: Auto Assign + +on: + issues: + types: [opened] + pull_request_target: + types: [opened] + +jobs: + run: + runs-on: ubuntu-latest + if: ${{ github.actor != 'themanyfaceddemon' }} + + permissions: + issues: write + pull-requests: write + + steps: + - name: 'Auto-assign issue' + uses: pozil/auto-assign-issue@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + assignees: themanyfaceddemon + numOfAssignee: 1 diff --git a/.github/workflows/close-pr-on-master.yml b/.github/workflows/close-pr-on-master.yml new file mode 100644 index 0000000..5fdb9ce --- /dev/null +++ b/.github/workflows/close-pr-on-master.yml @@ -0,0 +1,23 @@ +name: Close PRs on master + +on: + pull_request_target: + types: [opened, ready_for_review] + +jobs: + run: + runs-on: ubuntu-latest + if: ${{ github.head_ref == 'master' || github.head_ref == 'main' }} + + steps: + - uses: superbrothers/close-pull-request@v3 + with: + comment: | + Похоже, вы новичок в нашем репозитории и пытаетесь внести изменения из ветки master. + + Пожалуйста, прочитайте следующие гайды для правильной работы с репозиторием: + - [Подготовка окружения](http://dmbotwiki.a0001.net/ru/guide/prepare-environment.html) + - [Как создать форк](http://dmbotwiki.a0001.net/ru/guide/how-to-create-a-fork.html) + - [Первые изменения](http://dmbotwiki.a0001.net/ru/guide/first-changes.html) + + Данный pull request будет закрыт, так как вы пытаетесь внести изменения из ветки master вашей локальной копии репозитория в ветку master основного репозитория. В будущем, пожалуйста, создавайте отдельные ветки для ваших изменений. diff --git a/.github/workflows/label-not-sorted.yml b/.github/workflows/label-not-sorted.yml new file mode 100644 index 0000000..836f588 --- /dev/null +++ b/.github/workflows/label-not-sorted.yml @@ -0,0 +1,38 @@ +name: "Label new issues with 'Not sorted'" + +on: + issues: + types: [opened] + +jobs: + add-label: + runs-on: ubuntu-latest + + permissions: + issues: write + + steps: + - name: Label new issues with "Not sorted" + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const issue_number = context.issue.number; + + // Get issue details + const { data: issue } = await github.rest.issues.get({ + owner, + repo, + issue_number + }); + + // Check if author is "themanyfaceddemon" + if (issue.user.login !== "themanyfaceddemon" || issue.labels.length === 0) { + await github.rest.issues.addLabels({ + owner, + repo, + issue_number, + labels: ["Issue: Not sorted"] + }); + } diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..ebbbd8d --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,22 @@ +name: "Set labels for PR" +on: +- pull_request_target + +jobs: + labeler: + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set labels + uses: actions/labeler@v5 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + configuration-path: .github/workflows_config/labeler.yml + sync-labels: true diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..235c701 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,38 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Set PYTHONPATH + run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/Code" >> $GITHUB_ENV + + - name: Run tests + timeout-minutes: 10 + run: | + python -m unittest discover -s Tests -p "*.py" -v -f + env: + pythonLocation: /opt/hostedtoolcache/Python/3.12.3/x64 + LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.12.3/x64/lib diff --git a/.github/workflows_config/assignee.yml b/.github/workflows_config/assignee.yml new file mode 100644 index 0000000..6d781e5 --- /dev/null +++ b/.github/workflows_config/assignee.yml @@ -0,0 +1,2 @@ +"**/*": + - themanyfaceddemon diff --git a/.github/workflows_config/labeler.yml b/.github/workflows_config/labeler.yml new file mode 100644 index 0000000..0d29f8f --- /dev/null +++ b/.github/workflows_config/labeler.yml @@ -0,0 +1,15 @@ +"Changes: Unit test": +- changed-files: + - any-glob-to-any-file: ['Tests/**'] + +"Changes: Workflows": +- changed-files: + - any-glob-to-any-file: ['.github/workflows/**'] + +"Changes: Workflows config": +- changed-files: + - any-glob-to-any-file: ['.github/workflows_config/**'] + +"Changes: GitHub template": +- changed-files: + - any-glob-to-any-file: ['.github/ISSUE_TEMPLATE/**', '.github/PULL_REQUEST_TEMPLATE.md'] diff --git a/.gitignore b/.gitignore index bc2923d..06ec1a8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ venv.bak/ # Data [Dd]ata/* -Content/* +Content/Servers/* # Texture Sprites/ diff --git a/Code/gui/login_window.py b/Code/gui/login_window.py index 71a7032..097d4d8 100644 --- a/Code/gui/login_window.py +++ b/Code/gui/login_window.py @@ -1,6 +1,7 @@ import os from gui.main_window import MainApplicationWindow +from PyQt6.QtCore import QThread, pyqtSignal from PyQt6.QtGui import QPixmap from PyQt6.QtWidgets import (QDialog, QLabel, QLineEdit, QMainWindow, QMessageBox, QProgressBar, QPushButton) @@ -8,7 +9,7 @@ from root_path import ROOT_PATH from systems.decorators import global_class from systems.network import ClientUnit -from PyQt6.QtCore import QThread, pyqtSignal + @global_class class LoginWindow(QMainWindow): diff --git a/Code/systems/network/client_unit.py b/Code/systems/network/client_unit.py index d590da2..5500b32 100755 --- a/Code/systems/network/client_unit.py +++ b/Code/systems/network/client_unit.py @@ -53,11 +53,15 @@ def check_server(self, ip: str, port: int = 5000) -> None: self._socket_url = (ip, server_info.get("socket_port")) def download_server_content(self, progress_callback=None) -> None: - response = self._session.get(f"{self._http_url}/server/download_server_content", stream=True) + try: + response = self._session.get(f"{self._http_url}/server/download_server_content", stream=True) + response.raise_for_status() + + except requests.RequestException as e: + raise RuntimeError(f"Error during HTTP request: {e}") archive_path = "content.zip" - content_dir = os.path.join(ROOT_PATH, 'Content') - + content_dir = os.path.join(ROOT_PATH, 'Content', "Servers", self._http_url) total_size = int(response.headers.get('content-length', 0)) downloaded_size = 0 @@ -68,17 +72,24 @@ def download_server_content(self, progress_callback=None) -> None: downloaded_size += len(chunk) if progress_callback: progress_callback(downloaded_size, total_size) - + except IOError as e: raise IOError(f"Error saving file: {e}") if os.path.exists(content_dir): shutil.rmtree(content_dir) - with zipfile.ZipFile(archive_path, 'r') as zip_ref: - zip_ref.extractall(content_dir) + os.makedirs(content_dir, exist_ok=True) - os.remove(archive_path) + try: + with zipfile.ZipFile(archive_path, 'r') as zip_ref: + zip_ref.extractall(content_dir) + + except zipfile.BadZipFile as e: + raise RuntimeError(f"Error extracting zip file: {e}") + + finally: + os.remove(archive_path) # --- Auth API --- # def register(self, login: str, password: str) -> None: diff --git a/GUI/images/status/failure_16_16.png b/Content/Client/images/status/failure_16_16.png similarity index 100% rename from GUI/images/status/failure_16_16.png rename to Content/Client/images/status/failure_16_16.png diff --git a/GUI/images/status/failure_64_64.png b/Content/Client/images/status/failure_64_64.png similarity index 100% rename from GUI/images/status/failure_64_64.png rename to Content/Client/images/status/failure_64_64.png diff --git a/Tests/Texture/TextureSystem.py b/Tests/Texture/TextureSystem.py index e9e54c2..62751e4 100644 --- a/Tests/Texture/TextureSystem.py +++ b/Tests/Texture/TextureSystem.py @@ -7,7 +7,7 @@ import yaml from PIL import Image -from Code.texture_system import TextureSystem +from Code.systems.texture_system import TextureSystem class TestTextureSystem(unittest.TestCase):