Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment:
require_changes: true
layout: "diff, files"

coverage:
status:
project:
default:
target: auto
threshold: 2%
patch:
default:
target: auto
threshold: 2%
271 changes: 271 additions & 0 deletions .github/workflows/py_analysis-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
- 'pyproject.toml'
workflow_dispatch:

env:
APP_NAME: cloud_py_api

jobs:
analysis:
runs-on: macos-12
Expand Down Expand Up @@ -46,3 +49,271 @@ jobs:

- name: Run Analysis
run: pre-commit run --all-files --verbose --show-diff-on-failure

tests-pgsql:
needs: [analysis]
runs-on: ubuntu-22.04
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • PgSQL ${{ matrix.pgsql-version }}
if: "!contains(github.event.head_commit.message, '[docs]')"
strategy:
fail-fast: false
matrix:
nextcloud: [ "25.0.2" ]
php-version: [ "7.4", "8.0" ]
pgsql-version: [ "13", "14", "15" ]

services:
postgres:
image: postgres:${{ matrix.pgsql-version }}
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: rootpassword
POSTGRES_DB: nextcloud
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Set up php ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, fileinfo, intl, pdo_pgsql, zip, gd

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: cache-nextcloud
id: nextcloud_setup
uses: actions/cache@v3
with:
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
key: ${{ matrix.nextcloud }}

- name: Download Nextcloud
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2

- name: Set up Nextcloud
run: |
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
mkdir data
php occ maintenance:install --verbose --database=pgsql --database-name=nextcloud \
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass adminpassword
php occ config:system:set debug --value=true --type=boolean
php -S localhost:8080 &

- uses: actions/checkout@v3
with:
path: apps/${{ env.APP_NAME }}

- name: Enable App
run: php occ app:enable ${{ env.APP_NAME }}

- name: Generate coverage report
working-directory: apps/${{ env.APP_NAME }}
run: |
python3 -m pip -v install ".[dev]"
coverage run -m pytest -s && coverage xml && coverage html
env:
SERVER_ROOT: "../.."
CPA_LOGLEVEL: debug

- name: HTML coverage to artifacts
uses: actions/upload-artifact@v3
with:
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.pgsql-version }}
path: apps/${{ env.APP_NAME }}/htmlcov
if-no-files-found: error

- name: Upload report to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: apps/${{ env.APP_NAME }}/coverage.xml
fail_ci_if_error: true
verbose: true

tests-mysql:
needs: [analysis]
runs-on: ubuntu-22.04
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • MySQL ${{ matrix.mysql-version }}
if: "!contains(github.event.head_commit.message, '[docs]')"
strategy:
fail-fast: false
matrix:
nextcloud: [ "25.0.2" ]
php-version: [ "7.4", "8.0" ]
mysql-version: [ "8" ]

services:
mysql:
image: mysql:${{ matrix.mysql-version }}
env:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: nextcloud
options: >-
--health-cmd mysqladmin ping
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306

steps:
- name: Set up php ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, fileinfo, intl, pdo_mysql, zip, gd

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: cache-nextcloud
id: nextcloud_setup
uses: actions/cache@v3
with:
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
key: ${{ matrix.nextcloud }}

- name: Download Nextcloud
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2

- name: Set up Nextcloud
run: |
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
mkdir data
php occ maintenance:install --verbose --database=mysql --database-name=nextcloud \
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass adminpassword
php occ config:system:set debug --value=true --type=boolean
php -S localhost:8080 &

- uses: actions/checkout@v3
with:
path: apps/${{ env.APP_NAME }}

- name: Enable App
run: php occ app:enable ${{ env.APP_NAME }}

- name: Generate coverage report
working-directory: apps/${{ env.APP_NAME }}
run: |
python3 -m pip -v install ".[dev]"
coverage run -m pytest -s && coverage xml && coverage html
env:
SERVER_ROOT: "../.."
CPA_LOGLEVEL: debug

- name: HTML coverage to artifacts
uses: actions/upload-artifact@v3
with:
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.mysql-version }}
path: apps/${{ env.APP_NAME }}/htmlcov
if-no-files-found: error

- name: Upload report to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: apps/${{ env.APP_NAME }}/coverage.xml
fail_ci_if_error: true
verbose: true

tests-mariadb:
needs: [analysis]
runs-on: ubuntu-22.04
name: ${{ matrix.nextcloud }} • PHP ${{ matrix.php-version }} • Maria ${{ matrix.mariadb-version }}
if: "!contains(github.event.head_commit.message, '[docs]')"
strategy:
fail-fast: false
matrix:
nextcloud: [ "25.0.2" ]
php-version: [ "7.4", "8.0" ]
mariadb-version: [ "10.3", "10.6", "10.10" ]

services:
mariadb:
image: mariadb:${{ matrix.mariadb-version }}
env:
MARIADB_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: nextcloud
options: >-
--health-cmd mysqladmin ping
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306

steps:
- name: Set up php ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, fileinfo, intl, pdo_mysql, zip, gd

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: cache-nextcloud
id: nextcloud_setup
uses: actions/cache@v3
with:
path: nextcloud-${{ matrix.nextcloud }}.tar.bz2
key: ${{ matrix.nextcloud }}

- name: Download Nextcloud
if: steps.nextcloud_setup.outputs.cache-hit != 'true'
run: wget -q https://download.nextcloud.com/server/releases/nextcloud-${{ matrix.nextcloud }}.tar.bz2

- name: Set up Nextcloud
run: |
tar -xjf nextcloud-${{ matrix.nextcloud }}.tar.bz2 --strip-components 1
mkdir data
php occ maintenance:install --verbose --database=mysql --database-name=nextcloud \
--database-host=127.0.0.1 --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass adminpassword
php occ config:system:set debug --value=true --type=boolean
php -S localhost:8080 &

- uses: actions/checkout@v3
with:
path: apps/${{ env.APP_NAME }}

- name: Enable App
run: php occ app:enable ${{ env.APP_NAME }}

- name: Generate coverage report
working-directory: apps/${{ env.APP_NAME }}
run: |
python3 -m pip -v install ".[dev]"
coverage run -m pytest -s && coverage xml && coverage html
env:
SERVER_ROOT: "../.."
CPA_LOGLEVEL: debug

- name: HTML coverage to artifacts
uses: actions/upload-artifact@v3
with:
name: coverage_${{ matrix.nextcloud }}_${{ matrix.php-version }}_${{ matrix.mariadb-version }}
path: apps/${{ env.APP_NAME }}/htmlcov
if-no-files-found: error

- name: Upload report to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: apps/${{ env.APP_NAME }}/coverage.xml
fail_ci_if_error: true
verbose: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down
1 change: 1 addition & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tests
/proto
/tmp
.readthedocs.yaml
.codecov.yml
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Nextcloud Python Framework

[![(Py)Analysis & Coverage](https://github.com/cloud-py-api/cloud_py_api/actions/workflows/py_analysis-coverage.yml/badge.svg)](https://github.com/cloud-py-api/cloud_py_api/actions/workflows/py_analysis-coverage.yml)
![PythonVersion](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11-blue)
![impl](https://img.shields.io/pypi/implementation/nc_py_api)
![pypi](https://img.shields.io/pypi/v/nc_py_api.svg)

Framework(App) for Nextcloud to develop apps, that using Python.

Consists of PHP part(**cloud_py_api app**) and a Python module(**nc-py-api**).
Expand All @@ -19,7 +24,7 @@ In your Nextcloud, simply enable the `cloud_py_api` app through the Apps managem

The Nextcloud `cloud_py_api` app supports Nextcloud version 25 and higher.

#### More information can be found on [Wiki page](https://github.com/cloud_py_api/cloud_py_api/wiki)
#### More information can be found on [Wiki page](https://github.com/cloud-py-api/cloud_py_api/wiki)

## Maintainers

Expand Down
2 changes: 2 additions & 0 deletions nc_py_api/db_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def execute_fetchall(query: str, args=None, connection_id: int = 0) -> list:
break
except Exception: # noqa # pylint: disable=broad-except
log.exception("DB: Exception during executing fetchall.")
log.debug(query)
close_connection(connection_id)
return result

Expand Down Expand Up @@ -87,5 +88,6 @@ def execute_commit(query: str, args=None, connection_id: int = 0) -> int:
break
except Exception: # noqa # pylint: disable=broad-except
log.exception("DB: Exception during executing commit.")
log.debug(query)
close_connection(connection_id)
return result
2 changes: 1 addition & 1 deletion nc_py_api/db_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create_connection(config: dict, log_errors=True):


def connection_test(config: dict, log_errors=False) -> bool:
if environ.get("LOGLEVEL", "").upper() == "DEBUG":
if environ.get("CPA_LOGLEVEL", "").upper() == "DEBUG":
log_errors = True
connection = create_connection(config, log_errors=log_errors)
if connection is not None:
Expand Down
2 changes: 1 addition & 1 deletion nc_py_api/db_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_storages_info(num_id: Optional[int] = None) -> list:
def get_mimetype_id(mimetype: str) -> int:
"""For string mimetype returns it number representation."""

query = f"SELECT id FROM {TABLES.mimetypes} WHERE mimetype = {mimetype};"
query = f"SELECT id FROM {TABLES.mimetypes} WHERE mimetype = '{mimetype}';"
result = execute_fetchall(query)
if not result:
return 0
Expand Down
6 changes: 3 additions & 3 deletions nc_py_api/mimetype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .db_requests import get_mimetype_id

DIR = get_mimetype_id("'httpd/unix-directory'")
IMAGE = get_mimetype_id("'image'")
VIDEO = get_mimetype_id("'video'")
DIR = get_mimetype_id("httpd/unix-directory")
IMAGE = get_mimetype_id("image")
VIDEO = get_mimetype_id("video")
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ strict_optional = true
[tool.pytest.ini_options]
minversion = "6.0"
testpaths = [
"tests",
"tests/nc_py_api",
]
filterwarnings = [
"ignore::DeprecationWarning",
]
log_cli = true
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ install_requires =
pg8000
pymysql

[options.extras_require]
dev =
pytest
pre-commit
pylint
coverage

[flake8]
max-line-length = 120
target-version = ["py39"]
Expand Down
Loading