Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
plushkatze
foobarpay
Commits
c57452b9
Commit
c57452b9
authored
Apr 06, 2016
by
anthraxx
Browse files
PEP compliant linting
parent
1f19224f
Changes
8
Hide whitespace changes
Inline
Side-by-side
foobarpay.py
View file @
c57452b9
...
...
@@ -3,7 +3,6 @@
import
logging
from
sys
import
exit
from
signal
import
signal
,
SIGINT
from
sqlalchemy
import
create_engine
from
argparse
import
ArgumentParser
from
foobarpay.db
import
Database
...
...
@@ -13,9 +12,10 @@ from foobarpay.logic import Logic
from
foobarpay.model.product
import
Product
from
foobarpay.tokens
import
TokenGenerator
class
FooBarPay
:
DEFAULT_SCANNER
=
'/dev/input/by-id/usb-©_Symbol_Technologies__Inc__2000_Symbol_Bar_Code_Scanner_S_N:ac08a7010000_Rev:NBRXUAAQ3-event-kbd'
DEFAULT_DISPLAY
=
'/dev/hidraw1'
DEFAULT_SCANNER
=
'/dev/input/by-id/usb-©_Symbol_Technologies__Inc__2000_Symbol_Bar_Code_Scanner_S_N:ac08a7010000_Rev:NBRXUAAQ3-event-kbd'
DEFAULT_DISPLAY
=
'/dev/hidraw1'
DEFAULT_DATABASE
=
'sqlite:///foobarpay.sqlite'
ALLOW_CUSTOMER_CREATION
=
False
...
...
foobarpay/db.py
View file @
c57452b9
...
...
@@ -2,11 +2,10 @@ from sqlalchemy import create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.sql.expression
import
ClauseElement
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm.exc
import
NoResultFound
from
sqlalchemy.exc
import
IntegrityError
Base
=
declarative_base
()
class
Database
(
object
):
def
__init__
(
self
,
engine
,
debug
=
False
):
self
.
engine
=
create_engine
(
engine
,
echo
=
debug
)
...
...
@@ -15,7 +14,7 @@ class Database(object):
Base
.
metadata
.
create_all
(
self
.
engine
)
def
get
(
self
,
model
,
defaults
=
None
,
**
kwargs
):
return
self
.
session
.
query
(
model
).
filter_by
(
**
kwargs
).
first
()
return
self
.
session
.
query
(
model
).
filter_by
(
**
kwargs
).
first
()
def
get_or_create
(
self
,
model
,
defaults
=
None
,
**
kwargs
):
instance
=
self
.
get
(
model
,
defaults
,
**
kwargs
)
...
...
foobarpay/display.py
View file @
c57452b9
...
...
@@ -36,6 +36,7 @@ class HIDrawDisplay(object):
self
.
device
.
write
(
message
)
self
.
device
.
flush
()
class
FifoDisplay
(
HIDrawDisplay
):
def
set_position
(
self
,
pos_x
,
pos_y
):
self
.
__send_command__
(
b
"
\n
"
+
b
" "
*
pos_x
)
...
...
foobarpay/logic.py
View file @
c57452b9
...
...
@@ -5,6 +5,7 @@ import logging
from
time
import
sleep
from
enum
import
Enum
class
Logic
(
object
):
class
State
(
Enum
):
Idle
=
0
...
...
@@ -38,14 +39,14 @@ class Logic(object):
return
logging
.
debug
(
"Name: {}"
.
format
(
self
.
customer
.
name
))
logging
.
debug
(
"Saldo: {}"
.
format
(
self
.
customer
.
saldo
))
self
.
display
.
show_two_messages
(
"Hello {}"
.
format
(
self
.
customer
.
name
),
"S: {:+.2f}"
.
format
(
self
.
customer
.
saldo
/
100
))
self
.
display
.
show_two_messages
(
"Hello {}"
.
format
(
self
.
customer
.
name
),
"S: {:+.2f}"
.
format
(
self
.
customer
.
saldo
/
100
))
self
.
state
=
self
.
State
.
Started
self
.
cart
=
0
def
transaction_end
(
self
):
logging
.
info
(
"Completing transaction"
)
self
.
display
.
clear
()
self
.
display
.
set_position
(
1
,
1
)
self
.
display
.
set_position
(
1
,
1
)
self
.
customer
.
modify_saldo
(
self
.
cart
)
self
.
database
.
commit
()
self
.
display
.
show_two_messages
(
"Transaction"
,
"completed"
)
...
...
@@ -64,36 +65,37 @@ class Logic(object):
else
:
self
.
transaction_end
()
elif
scanned_text
.
startswith
(
self
.
LOAD_PREFIX
):
if
self
.
state
==
self
.
State
.
Idle
:
# Product without active transaction
if
self
.
state
==
self
.
State
.
Idle
:
# Product without active transaction
self
.
display
.
show_two_messages
(
"Error"
,
"Scan UID first"
)
sleep
(
3
)
self
.
display
.
show_welcome
()
else
:
# Add credit loading to transaction
else
:
# Add credit loading to transaction
load_amount
=
int
(
scanned_text
[
len
(
self
.
LOAD_PREFIX
):
12
])
self
.
cart
+=
load_amount
self
.
display
.
show_two_messages
(
"Credits loaded: {:.2f}"
.
format
(
load_amount
/
100
),
"Cart: {:+.2f}"
.
format
(
self
.
cart
/
100
)
"Credits loaded: {:.2f}"
.
format
(
load_amount
/
100
),
"Cart: {:+.2f}"
.
format
(
self
.
cart
/
100
)
)
else
:
# Product ID
if
self
.
state
==
self
.
State
.
Idle
:
# Product without active transaction
else
:
# Product ID
if
self
.
state
==
self
.
State
.
Idle
:
# Product without active transaction
self
.
display
.
show_two_messages
(
"Error"
,
"Scan UID first"
)
sleep
(
3
)
self
.
display
.
show_welcome
()
else
:
# Add product to transaction
else
:
# Add product to transaction
product_id
=
int
(
scanned_text
)
product
=
self
.
database
.
get
(
Product
,
id
=
product_id
)
if
product
is
None
:
self
.
display
.
show_two_messages
(
"Error"
,
"Unknown product"
)
sleep
(
2
)
self
.
display
.
show_two_messages
(
"Hello {}"
.
format
(
self
.
customer
.
name
[:
12
]),
"S: {:+.2f} / C: {:+.2f}"
.
format
(
self
.
customer
.
saldo
/
100
,
self
.
cart
/
100
)
"Hello {}"
.
format
(
self
.
customer
.
name
[:
12
]),
"S: {:+.2f} / C: {:+.2f}"
.
format
(
self
.
customer
.
saldo
/
100
,
self
.
cart
/
100
)
)
else
:
self
.
cart
-=
product
.
price
self
.
display
.
show_two_messages
(
"{}: {:.2f}"
.
format
(
product
.
name
,
product
.
price
/
100
),
"Cart: {:+.2f}"
.
format
(
self
.
cart
/
100
)
"{}: {:.2f}"
.
format
(
product
.
name
,
product
.
price
/
100
),
"Cart: {:+.2f}"
.
format
(
self
.
cart
/
100
)
)
except
ValueError
:
pass
except
ValueError
:
pass
foobarpay/model/customer.py
View file @
c57452b9
from
foobarpay.db
import
Base
from
sqlalchemy
import
Column
,
Integer
,
String
class
Customer
(
Base
):
__tablename__
=
'customer'
id
=
Column
(
Integer
,
primary_key
=
True
)
...
...
foobarpay/model/product.py
View file @
c57452b9
...
...
@@ -2,6 +2,7 @@ from foobarpay.db import Base
from
sqlalchemy
import
Column
,
Integer
,
String
from
sqlalchemy.ext.hybrid
import
hybrid_property
class
Product
(
Base
):
__tablename__
=
'product'
id
=
Column
(
Integer
,
primary_key
=
True
)
...
...
foobarpay/scanner.py
View file @
c57452b9
from
enum
import
Enum
from
evdev
import
InputDevice
,
ecodes
class
EvdevScanner
(
object
):
def
__init__
(
self
,
device
):
self
.
device
=
InputDevice
(
device
)
...
...
foobarpay/tokens.py
View file @
c57452b9
...
...
@@ -10,6 +10,7 @@ from time import time
from
foobarpay.model.customer
import
Customer
from
foobarpay.logic
import
Logic
class
TokenGenerator
(
object
):
def
__init__
(
self
,
db
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment