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
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((xbox|tests)/.+)?[^/]+\.py$
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
additional_dependencies:
# - flake8-docstrings==1.5.0
- pydocstyle==5.1.1
files: ^(xbox)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.6.2
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=bandit.yaml
files: ^(xbox|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.5.3
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
- repo: https://github.com/prettier/prettier
rev: 2.0.4
hooks:
- id: prettier
stages: [manual]

39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -fr {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/

lint: ## check style with flake8
flake8 onvif tests
pylint onvif

test: ## run tests quickly with the default Python
pytest --cov=onvif --cov-report html tests/

release: clean ## package and upload a release
python3 -m twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

install: clean ## install the package to the active Python's site-packages
pip3 install -r requirements.txt
pre-commit install
pip3 install -e .
17 changes: 17 additions & 0 deletions bandit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://bandit.readthedocs.io/en/latest/config.html

tests:
- B108
- B306
- B307
- B313
- B314
- B315
- B316
- B317
- B318
- B319
- B320
- B325
- B602
- B604
159 changes: 0 additions & 159 deletions examples/continuous_move.py

This file was deleted.

14 changes: 9 additions & 5 deletions examples/events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Example to fetch pullpoint events."""
import asyncio
import datetime as dt
from pytz import UTC
import logging

from pytz import UTC
from zeep import xsd

from onvif import ONVIFCamera
Expand All @@ -24,7 +25,7 @@ async def run():
print("PullPoint not supported")
return

event_service = mycam.get_service("events")
event_service = mycam.create_events_service()
properties = await event_service.GetEventProperties()
print(properties)
capabilities = await event_service.GetServiceCapabilities()
Expand All @@ -39,11 +40,14 @@ async def run():
print(messages)

subscription = mycam.create_subscription_service("PullPointSubscription")
# req = subscription.zeep_client.get_element("ns5:Renew")
# req.TerminationTime = str(dt.datetime.now(UTC) + dt.timedelta(minutes=10))
termination_time = (dt.datetime.now(UTC) + dt.timedelta(minutes=10)).isoformat()
termination_time = (
(dt.datetime.utcnow() + dt.timedelta(days=1))
.isoformat(timespec="seconds")
.replace("+00:00", "Z")
)
await subscription.Renew(termination_time)
await subscription.Unsubscribe()
await mycam.close()


if __name__ == "__main__":
Expand Down
14 changes: 9 additions & 5 deletions examples/rotate_image.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import asyncio

from onvif import ONVIFCamera


async def rotate_image_180():
''' Rotate the image '''
""" Rotate the image """

# Create the media service
mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345')
mycam = ONVIFCamera("192.168.0.112", 80, "admin", "12345")
await mycam.update_xaddrs()
media_service = mycam.create_media_service()

Expand All @@ -21,18 +23,20 @@ async def rotate_image_180():
video_source_configuration = configurations_list[0]

# Enable rotate
video_source_configuration.Extension[0].Rotate[0].Mode[0] = 'OFF'
video_source_configuration.Extension[0].Rotate[0].Mode[0] = "OFF"

# Create request type instance
request = media_service.create_type('SetVideoSourceConfiguration')
request = media_service.create_type("SetVideoSourceConfiguration")
request.Configuration = video_source_configuration

# ForcePersistence is obsolete and should always be assumed to be True
request.ForcePersistence = True

# Set the video source configuration
await media_service.SetVideoSourceConfiguration(request)
await mycam.close()


if __name__ == '__main__':
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(rotate_image_180())
Loading