Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kort-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Libraries
kort-client
Compare revisions
ab1c94a69b45fd921b34f9a57f080d3e0d89cb33 to fe1635398410c85a5ab48e0dfbb27cf2b3560c2e
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
AlekSIS/libs/kort-client
Select target project
No results found
fe1635398410c85a5ab48e0dfbb27cf2b3560c2e
Select Git revision
Branches
master
renovate/flake8-7.x
renovate/isort-6.x
renovate/safety-3.x
Swap
Target
AlekSIS/libs/kort-client
Select target project
AlekSIS/libs/kort-client
1 result
ab1c94a69b45fd921b34f9a57f080d3e0d89cb33
Select Git revision
Branches
master
renovate/flake8-7.x
renovate/isort-6.x
renovate/safety-3.x
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (4)
Quote client id and client secret according to urlencode
· 95e8cc1c
Jonathan Weth
authored
1 year ago
Verified
95e8cc1c
Support NFC reader as card detector
· c2a26c3a
Jonathan Weth
authored
1 year ago
Verified
c2a26c3a
Merge remote-tracking branch 'origin/master'
· 98ae6c83
Jonathan Weth
authored
1 year ago
Verified
98ae6c83
Update dependency flake8-bandit to v4
· fe163539
Tine Wittler
authored
1 year ago
fe163539
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
kort_client/api.py
+5
-1
5 additions, 1 deletion
kort_client/api.py
kort_client/card_detectors.py
+41
-0
41 additions, 0 deletions
kort_client/card_detectors.py
kort_client/run.py
+24
-12
24 additions, 12 deletions
kort_client/run.py
pyproject.toml
+2
-1
2 additions, 1 deletion
pyproject.toml
with
72 additions
and
14 deletions
kort_client/api.py
View file @
fe163539
import
urllib
from
typing
import
Any
,
Optional
,
Sequence
from
typing
import
Any
,
Optional
,
Sequence
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
...
@@ -91,7 +92,10 @@ class KortAPI:
...
@@ -91,7 +92,10 @@ class KortAPI:
r
=
request
(
r
=
request
(
method
,
method
,
url
,
url
,
auth
=
(
self
.
settings
.
client_id
,
self
.
settings
.
client_secret
),
auth
=
(
urllib
.
parse
.
quote
(
self
.
settings
.
client_id
),
urllib
.
parse
.
quote
(
self
.
settings
.
client_secret
),
),
**
kwargs
**
kwargs
)
)
if
not
r
.
ok
:
if
not
r
.
ok
:
...
...
This diff is collapsed.
Click to expand it.
kort_client/card_detectors.py
View file @
fe163539
import
os
import
os
import
subprocess
# noqa
import
subprocess
# noqa
import
time
from
binascii
import
hexlify
import
click
from
nfc
import
ContactlessFrontend
from
.usb_barcode_scanner.scanner
import
BarcodeReader
from
.usb_barcode_scanner.scanner
import
BarcodeReader
class
CardDetector
:
class
CardDetector
:
id_
=
None
id_
=
None
interactive
=
False
def
read_id
(
self
):
def
read_id
(
self
):
raise
NotImplementedError
()
raise
NotImplementedError
()
...
@@ -100,3 +106,38 @@ class EvolisCardDetector(CardDetector):
...
@@ -100,3 +106,38 @@ class EvolisCardDetector(CardDetector):
def
abort
(
self
):
def
abort
(
self
):
self
.
clear
()
self
.
clear
()
class
NfcReadUidDetector
(
CardDetector
):
id_
=
"
nfc_read_uid
"
def
read_id
(
self
):
reader
=
ContactlessFrontend
()
reader
.
open
(
"
usb
"
)
from
kort_client.run
import
KortClientException
try
:
click
.
secho
(
"
→ Please hold your card to the reader
"
)
tag
=
reader
.
connect
(
rdwr
=
{
"
on-connect
"
:
lambda
tag
:
False
})
uid
=
hexlify
(
tag
.
_nfcid
).
decode
(
"
utf-8
"
)
click
.
secho
(
"
Card successfully detected
"
,
fg
=
"
green
"
)
click
.
secho
(
f
"
UID:
{
uid
}
"
,
fg
=
"
white
"
)
click
.
secho
(
"
Please remove the card from the reader
"
,
fg
=
"
red
"
)
while
True
:
started
=
time
.
time
()
after5s
=
lambda
:
time
.
time
()
-
started
>
0.5
tag
=
reader
.
connect
(
rdwr
=
{
"
on-connect
"
:
lambda
tag
:
False
},
terminate
=
after5s
)
if
not
tag
:
break
new_uid
=
hexlify
(
tag
.
_nfcid
).
decode
(
"
utf-8
"
)
if
uid
!=
new_uid
:
break
click
.
secho
(
"
The card has been removed.
"
,
fg
=
"
green
"
)
except
Exception
as
e
:
raise
KortClientException
(
e
.
args
)
return
uid
This diff is collapsed.
Click to expand it.
kort_client/run.py
View file @
fe163539
...
@@ -18,9 +18,12 @@ IPP_CODES = {y: x for x, y in cups.__dict__.items() if x.startswith("IPP_JOB")}
...
@@ -18,9 +18,12 @@ IPP_CODES = {y: x for x, y in cups.__dict__.items() if x.startswith("IPP_JOB")}
class
PrintClient
:
class
PrintClient
:
def
__init__
(
self
,
settings
,
api
):
def
__init__
(
self
,
settings
,
api
,
interactive
=
False
):
self
.
settings
=
settings
self
.
settings
=
settings
self
.
api
=
api
self
.
api
=
api
self
.
interactive
=
interactive
self
.
with_printer
=
True
self
.
printer_id
=
None
self
.
printer_id
=
None
self
.
conn
=
cups
.
Connection
()
self
.
conn
=
cups
.
Connection
()
self
.
card_detectors
=
CardDetector
.
get_card_detectors
()
self
.
card_detectors
=
CardDetector
.
get_card_detectors
()
...
@@ -36,7 +39,7 @@ class PrintClient:
...
@@ -36,7 +39,7 @@ class PrintClient:
printer_status
=
"
with_errors
"
printer_status
=
"
with_errors
"
status_text
=
str
(
e
)
status_text
=
str
(
e
)
click
.
secho
(
click
.
secho
(
"
An error occured, try again in five seconds: {}
"
.
format
(
e
),
"
An error occur
r
ed, try again in five seconds: {}
"
.
format
(
e
),
fg
=
"
red
"
,
fg
=
"
red
"
,
)
)
if
self
.
card_detector_in_process
and
self
.
card_detector
:
if
self
.
card_detector_in_process
and
self
.
card_detector
:
...
@@ -67,16 +70,27 @@ class PrintClient:
...
@@ -67,16 +70,27 @@ class PrintClient:
raise
raise
def
_validate_printer
(
self
):
def
_validate_printer
(
self
):
self
.
with_printer
=
self
.
printer_config
.
get
(
"
cups_printer
"
)
self
.
card_detector
=
self
.
card_detectors
.
get
(
self
.
printer_config
[
"
card_detector
"
],
None
)
if
not
self
.
printer_config
.
get
(
"
cups_printer
"
):
if
not
self
.
with_printer
and
not
self
.
card_detector
:
raise
KortClientException
(
"
No CUPS printer configured
"
)
cups_printers
=
self
.
conn
.
getPrinters
()
if
self
.
printer_config
[
"
cups_printer
"
]
not
in
cups_printers
:
raise
KortClientException
(
raise
KortClientException
(
"
CUPS printer {} not found
"
.
format
(
self
.
printer_config
[
"
cups_printer
"
]),
"
No printer or card detector configured for printer {}
"
.
format
(
self
.
printer_config
[
"
name
"
]
)
)
)
if
self
.
with_printer
:
cups_printers
=
self
.
conn
.
getPrinters
()
if
self
.
printer_config
[
"
cups_printer
"
]
not
in
cups_printers
:
raise
KortClientException
(
"
CUPS printer {} not found
"
.
format
(
self
.
printer_config
[
"
cups_printer
"
]
),
)
def
step
(
self
):
def
step
(
self
):
self
.
printer_config
=
self
.
api
.
get_printer
()
self
.
printer_config
=
self
.
api
.
get_printer
()
print
(
self
.
printer_config
)
print
(
self
.
printer_config
)
...
@@ -85,11 +99,9 @@ class PrintClient:
...
@@ -85,11 +99,9 @@ class PrintClient:
self
.
_validate_printer
()
self
.
_validate_printer
()
self
.
card_detector
=
self
.
card_detectors
.
get
(
self
.
printer_config
[
"
card_detector
"
],
None
)
self
.
card_detector_in_process
=
False
self
.
card_detector_in_process
=
False
if
self
.
card_detector
:
if
self
.
card_detector
:
self
.
interactive
=
self
.
card_detector
.
interactive
self
.
card_detector
.
clear
()
self
.
card_detector
.
clear
()
next_job
=
self
.
api
.
get_next_job
(
self
.
printer_id
)
next_job
=
self
.
api
.
get_next_job
(
self
.
printer_id
)
...
@@ -118,7 +130,7 @@ class PrintClient:
...
@@ -118,7 +130,7 @@ class PrintClient:
else
:
else
:
raise
KortClientException
(
"
No card detector configured
"
)
raise
KortClientException
(
"
No card detector configured
"
)
if
next_job
[
"
card
"
][
"
chip_number
"
]:
if
self
.
with_printer
and
next_job
[
"
card
"
][
"
chip_number
"
]:
# Download PDF file
# Download PDF file
with
tempfile
.
NamedTemporaryFile
(
"
wb
"
)
as
f
:
with
tempfile
.
NamedTemporaryFile
(
"
wb
"
)
as
f
:
r
=
requests
.
get
(
r
=
requests
.
get
(
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
fe163539
...
@@ -16,13 +16,14 @@ usersettings = "^1.1.5"
...
@@ -16,13 +16,14 @@ usersettings = "^1.1.5"
requests
=
"^2.27.1"
requests
=
"^2.27.1"
pycups
=
"^2.0.1"
pycups
=
"^2.0.1"
usb-barcode-scanner-julz
=
"^0.2"
usb-barcode-scanner-julz
=
"^0.2"
nfcpy
=
"^1.0.4"
[tool.poetry.dev-dependencies]
[tool.poetry.dev-dependencies]
safety
=
"^1.8.5"
safety
=
"^1.8.5"
flake8
=
"^4.0.0"
flake8
=
"^4.0.0"
flake8-fixme
=
"^1.1.1"
flake8-fixme
=
"^1.1.1"
flake8-mypy
=
"^17.8.0"
flake8-mypy
=
"^17.8.0"
flake8-bandit
=
"^
3
.0.0"
flake8-bandit
=
"^
4
.0.0"
flake8-builtins
=
"^2.0.0"
flake8-builtins
=
"^2.0.0"
flake8-docstrings
=
"^1.5.0"
flake8-docstrings
=
"^1.5.0"
flake8-rst-docstrings
=
"^0.3.0"
flake8-rst-docstrings
=
"^0.3.0"
...
...
This diff is collapsed.
Click to expand it.