Skip to content

Commit

Permalink
Apply linters
Browse files Browse the repository at this point in the history
  • Loading branch information
bdragon300 committed Oct 14, 2024
1 parent 8642b65 commit 7ab5c30
Show file tree
Hide file tree
Showing 44 changed files with 4,054 additions and 3,454 deletions.
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: 'pyzkaccess/cli.py' # It will not pass the checks, since it has been written specially for Fire library
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -12,19 +13,15 @@ repos:
rev: "24.8.0"
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: "7.1.1"
hooks:
- id: flake8
additional_dependencies: [Flake8-pyproject]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
- repo: https://github.com/PyCQA/pylint
rev: v3.0.2
rev: v3.2.7
hooks:
- id: pylint
additional_dependencies: ["wrapt>=1.16.0"]
- repo: https://github.com/python-poetry/poetry
rev: "1.6.1"
hooks:
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and this project adheres to
- Print one event by line and remove items collapsing in `EventLog` string representation
- Fix "no value" values handling in some paremeters
- Fix `search_devices` raises error when no devices found
- Rename `pyzkaccess.py` to `main.py` and `ctypes.py` to `ctypes_.py` in order to avoid
- Rename `pyzkaccess.py` to `main.py` and `ctypes.py` to `ctypes_.py` in order to avoid
possible import issues
- Change type of warning to `ImportWarning` when non-Windows platform is used

Expand Down Expand Up @@ -56,12 +56,12 @@ and this project adheres to
- BREAKING CHANGE. ZKAccess connstr constructor parameter now must be keyword parameter and be
`str` type instead of `bytes`
- Split project to several files
- BREAKING CHANGE. Split up `ZKAccess` class onto `ZKSDK` (implementation) and
`ZKAccess` (interface). Move `zk*` methods to `ZKSDK`
- BREAKING CHANGE. Split up `ZKAccess` class onto `ZKSDK` (implementation) and
`ZKAccess` (interface). Move `zk*` methods to `ZKSDK`
- BREAKING CHANGE. Convert `ControlOperation`, `RelayGroup`, `VERIFY_MODES` to python `Enum`

### Removed
- BREAKING CHANGE. Remove `enable_relay*` and `read_events` methods
- BREAKING CHANGE. Remove `enable_relay*` and `read_events` methods

## [0.1]
### Added
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
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.
limitations under the License.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![codecov](https://codecov.io/gh/bdragon300/pyzkaccess/branch/master/graph/badge.svg)](https://codecov.io/gh/bdragon300/pyzkaccess)
[![license](https://img.shields.io/github/license/bdragon300/pyzkaccess)](https://github.com/bdragon300/pyzkaccess/blob/master/LICENSE)

**PyZKAccess** is a library and command-line interface for working with ZKTeco ZKAccess
**PyZKAccess** is a library and command-line interface for working with ZKTeco ZKAccess
C3-100/200/400 access controllers.

[Read documentation](https://bdragon300.github.io/pyzkaccess)
Expand All @@ -15,7 +15,7 @@ C3-100/200/400 access controllers.

First, you need to install ZKTeco PULL SDK. See documentation for more info.

In order to make requests to your C3 device, you need to know its IP address. Let's scan a
In order to make requests to your C3 device, you need to know its IP address. Let's scan a
local network and find a device:

```console
Expand Down
6 changes: 3 additions & 3 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Commands not related to a particular device:
$ pyzkaccess <command> [parameters]
```

By default, all input data is consumed from stdin, and all output is printed to stdout. You can
By default, all input data is consumed from stdin, and all output is printed to stdout. You can
specify a file instead by setting `--file` parameter.

CLI gives access to most of PyZKAccess features. Also, it is supported the ascii tables in console
CLI gives access to most of PyZKAccess features. Also, it is supported the ascii tables in console
or CSV format.

Every command, group and subcommand has its own help contents, just type them and append
Every command, group and subcommand has its own help contents, just type them and append
`--help` at the end. For example, here is the help for `connect` command:

```console
Expand Down
36 changes: 18 additions & 18 deletions docs/data_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ history, input/output events, and where user can manage users, ACLs, local time

`pyzkaccess` provides interface to access, making queries and modify these tables. A table record
is presented as a python object with properties -- a model. Query objects helps to build a query
and to iterate over the results. Anyway, if you ever worked with any of popular ORM
and to iterate over the results. Anyway, if you ever worked with any of popular ORM
(Object-related mapping), such interface could be pretty familiar to you.

Device keeps all data in tables as strings, despite which type a particular field value has.
Model provides a convenient way to work with data depening on actual type. For example,
`transaction.Time_second` field contains an integer with encoded datetime, but appropriate
Device keeps all data in tables as strings, despite which type a particular field value has.
Model provides a convenient way to work with data depening on actual type. For example,
`transaction.Time_second` field contains an integer with encoded datetime, but appropriate
`Transaction.time` allows to work with that value using usual `datetime` objects.

The following sections describe how to work with table records, make queries and update the data.

## Model objects

`pyzkaccess` contains pre-defined models that represent built-in tables in ZK devices.
Model class represents whole data table, whereas a model object is a particular record in
this table.
`pyzkaccess` contains pre-defined models that represent built-in tables in ZK devices.
Model class represents whole data table, whereas a model object is a particular record in
this table.

In order to create an object, instantiate it with parameters.

Expand Down Expand Up @@ -115,7 +115,7 @@ Deleting object is similar to saving.

### `model.delete()` method

Manually created objects (unlike retrieved from a query, see below) must know which connection
Manually created objects (unlike retrieved from a query, see below) must know which connection
to use, so also set it by `with_zk()`:

```python
Expand Down Expand Up @@ -159,7 +159,7 @@ zk.table(User).delete(my_user)

### `queryset.delete_all()` method

This method deletes records that matched to a `QuerySet` object. If results was not fetched yet,
This method deletes records that matched to a `QuerySet` object. If results was not fetched yet,
fetches them first. Returns nothing.

The following example deletes all transactions related to card "123456":
Expand All @@ -174,7 +174,7 @@ The `QuerySet` class is intended to build a query to a data table, execute it an
Its operations are limited to the ZK PULL SDK capabilities. `QuerySet` supports filtering (only
for equal condition), limiting to unread records, to the certain fields, slicing results.

`QuerySet` uses lazy loading, which means that it will not make a query and fetch the results
`QuerySet` uses lazy loading, which means that it will not make a query and fetch the results
until you started to iterate over it or to get element by index.

The common approach to work with a QuerySet is:
Expand All @@ -185,11 +185,11 @@ for record in records:
...
```

`QuerySet` is binded with a particular Model class, where queries are targeted to. New
`QuerySet` is created by `ZKAccess.table(model)` function. As `model` parameter you can pass
`QuerySet` is binded with a particular Model class, where queries are targeted to. New
`QuerySet` is created by `ZKAccess.table(model)` function. As `model` parameter you can pass
model's name, or it's class, or it's object.

The following examples works identically, they return empty `QuerySet` object binded with
The following examples works identically, they return empty `QuerySet` object binded with
`User` model:

```python
Expand All @@ -207,11 +207,11 @@ Some `QuerySet` methods return new object, the others not. Let's see what you ca
#### Filtering

`where()` method returns a new `QuerySet` containing records that match the given filter parameters.
You can only use equality operation due to PULL SDK restriction. Several fields are AND'ed.
Filters in repeated `where()` calls are also AND'ed with fields from previous calls. If this
You can only use equality operation due to PULL SDK restriction. Several fields are AND'ed.
Filters in repeated `where()` calls are also AND'ed with fields from previous calls. If this
field has already set in previous call, it will be replaced with new value.

The following examples will produce identical queries:
The following examples will produce identical queries:

```python
qs = zk.table('User').where(group='4', super_authorize=True)
Expand All @@ -236,7 +236,7 @@ from previous calls.

As a field name you can pass either a field name or model field object.

The following examples will produce identical queries:
The following examples will produce identical queries:

```python
from pyzkaccess.tables import User
Expand All @@ -247,7 +247,7 @@ qs = zk.table('User').only_fields('pin').only_fields('password')
qs = zk.table('User').only_fields(User.pin).only_fields(User.password)
```

Resulting records will have only `pin` and `password` field values, retrieved from table,
Resulting records will have only `pin` and `password` field values, retrieved from table,
other fields will remain None.

### Data table size
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# PyZKAccess

* [Summary](#summary)
* [Summary](#summary)
* [Installing](#installing)
* [Usage](#usage)
* [Usage](#usage)
* [Device data tables](#device-data-tables)
* [Model objects](#model-objects)
* [Saving changes in objects](#saving-changes-in-objects)
* [Deleting objects](#deleting-objects)
* [Making queries](#making-queries)
* [Retrieving results](#retrieving-results)
* [Command-line interface](#command-line-interface)
* [Command-line interface](#command-line-interface)

PyZKAccess is a library for working with ZKTeco ZKAccess C3-100/200/400 access controllers.

Expand Down
10 changes: 5 additions & 5 deletions docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requirements:

## PULL SDK

Download a current version of PULL SDK and extract the archive:
Download a current version of PULL SDK and extract the archive:
[ZKTeco software downloads](https://www.zkteco.eu/index.php/downloads/software-downloads).

A downloaded archive contains **32-bit** `pl*.dll` DLL files and documentation.
Expand All @@ -27,8 +27,8 @@ Next, install the last [Python version for Windows](https://www.python.org/downl

`wine pip install pyzkaccess`

Finally, copy `pl*.dll` files from SDK archive to system directory in Wine. Usually it is
`/home/user/.wine/drive_c/windows/SysWOW64` (or`/home/user/.wine/drive_c/windows/system32`
Finally, copy `pl*.dll` files from SDK archive to system directory in Wine. Usually it is
`/home/user/.wine/drive_c/windows/SysWOW64` (or`/home/user/.wine/drive_c/windows/system32`
on older Windows versions). Registration via the `regsvr32` is not needed.

*(Sometimes Wine doesn't see dll files even if you have copied them right. In this case you may
Expand All @@ -41,6 +41,6 @@ open command window and install library from pip:

`pip install pyzkaccess`

Finally, copy `pl*.dll` files from SDK archive to system directory. Usually it is
`C:\Windows\SysWOW64` (or `C:\Windows\System32` on older Windows versions). Registration via the
Finally, copy `pl*.dll` files from SDK archive to system directory. Usually it is
`C:\Windows\SysWOW64` (or `C:\Windows\System32` on older Windows versions). Registration via the
`regsvr32` is not needed.
4 changes: 2 additions & 2 deletions docs/summary.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Summary

The ZKTeco PULL SDK is used as machinery. So the code is intended to be executed in Windows
The ZKTeco PULL SDK is used as machinery. So the code is intended to be executed in Windows
environment. *nix are also supported by Wine.

## Features
Expand All @@ -9,7 +9,7 @@ environment. *nix are also supported by Wine.
- [x] Working with data tables on a device (CRUD, filtering)
- [x] Relays switching
- [x] Reading events of whole device or separately for a certain reader, aux input or even door
- [x] Getting/setting device parameters such as datetime, network settings, entry modes, backup
- [x] Getting/setting device parameters such as datetime, network settings, entry modes, backup
time, etc.
- [x] Getting/setting door parameters such as smart card modes, intervals, entry modes, etc.
- [x] Searching for active C3 devices by scanning a local network
Expand Down
8 changes: 4 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ zk.readers[0].events.refresh() # By index
zk.readers[1:3].events.refresh() # By range
zk.readers[1:3].events.poll() # Await events for readers 2 and 3
zk.doors[0].reader.events.refresh() # By number of door which it belongs to
```
```

## Aux inputs

Expand All @@ -128,14 +128,14 @@ zk.aux_inputs[0].events.refresh() # By index
zk.aux_inputs[1:3].events.refresh() # By range
zk.aux_inputs[1:3].events.poll() # Await events for aux inputs 2 and 3
zk.doors[0].aux_input.events.refresh() # By number of door which it belongs to
```
```

## Events

Events are accessible through `.events` property. C3 controller keeps
maximum 30 last unread events. Events start to register just after making connection to a device.

Event log should be refreshed manually using `refresh()` method. Due to restriction of
Event log should be refreshed manually using `refresh()` method. Due to restriction of
maximum 30 entries described above, you should call `refresh()` periodically in order to avoid
losing new events.

Expand All @@ -160,7 +160,7 @@ zk.readers.events # Event log related to readers only
#
# Wait until an some event will occur on Door 1 reader
zk.door[0].reader.events.poll()
# Wait until unregistered card (event_type 27) with given number will appear on Door 1 reader
# Wait until unregistered card (event_type 27) with given number will appear on Door 1 reader
zk.door[0].reader.events.only(card='123456', event_type=27).poll()
# Take all records from log with given card which was occur after 2010-10-11 14:28:04
zk.events.only(card='123456').after_time(datetime(2010, 10, 11, 14, 28, 4))
Expand Down
Loading

0 comments on commit 7ab5c30

Please sign in to comment.