Skip to content

Commit fafec04

Browse files
author
sedrubal
committed
Moved config.ini.example to config.defaults.ini
- see #43 - can fix #63
1 parent 4a4d884 commit fafec04

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

FabLabKasse/cashPayment/client/PaymentDevicesManager.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ConfigParser import ConfigParser
3030
import codecs
3131

32+
3233
class PaymentDevicesManager(object):
3334

3435
def __init__(self, cfg):
@@ -157,7 +158,7 @@ def canPayout(self):
157158
return None
158159
if self.mode == "canPayout":
159160
# commands already sent
160-
if not None in self.canPayoutAmounts:
161+
if None not in self.canPayoutAmounts:
161162
# all devices sent replies
162163
canPayoutAmounts = self.canPayoutAmounts
163164
self.canPayoutAmounts = None # invalidate cache
@@ -232,7 +233,7 @@ def _updatePayinAmounts(self):
232233
"""
233234
for d in self.devices:
234235
maximum = self.maximumPayin - self.getCurrentAmount()
235-
if d.getCurrentAmount() != None:
236+
if d.getCurrentAmount() is not None:
236237
maximum += d.getCurrentAmount()
237238
d.updateAcceptValue(maximum)
238239

@@ -242,7 +243,7 @@ def getCurrentAmount(self):
242243
"""
243244
totalSum = self.finishedAmount
244245
for d in self.devices:
245-
if d.getCurrentAmount() != None:
246+
if d.getCurrentAmount() is not None:
246247
totalSum += d.getCurrentAmount()
247248
return totalSum
248249

@@ -346,6 +347,7 @@ def getFinalAmount(self):
346347
self.mode = "idle"
347348
return ret
348349

350+
349351
class PaymentDevicesManagerTest(unittest.TestCase):
350352
""" Test PaymentDevicesManager
351353
"""
@@ -355,7 +357,7 @@ def test_canPayout_with_one_random_datapoint_on_example_server(self):
355357
"""
356358
# probably hacky, should be improved
357359
cfg = ConfigParser()
358-
cfg.readfp(codecs.open('./FabLabKasse/config.ini.example', 'r', 'utf8'))
360+
cfg.readfp(codecs.open('./FabLabKasse/config.defaults.ini', 'r', 'utf8'))
359361

360362
for _ in range(0, 9):
361363
history = []
@@ -406,6 +408,7 @@ def myRandInt(n): # 0 ... n, with a finite >0 probability for both endpoints
406408
self.assertTrue(requested - canRemain <= paidOut <= requested, msg=msg)
407409
self.assertTrue(paidOut >= 0, msg=msg)
408410

411+
409412
def demo():
410413
"""Simple demonstration using two exampleServer devices"""
411414
# TODO this code seems to be broken, maybe adapt code from unittest or discard

FabLabKasse/config.ini.example renamed to FabLabKasse/config.defaults.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[general]
2+
; support mail will be displayed when error occur
3+
support_mail = [email protected]
4+
25
; Path to sqlite3 file
36
db_file = development.sqlite3
47

FabLabKasse/scriptHelper.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import signal
2323
import logging
2424
import logging.handlers
25+
import os
2526
import sys
2627
import portalocker
2728
import sqlite3
@@ -92,9 +93,17 @@ def myNewExceptionHook(exctype, value, tb):
9293
def getConfig(path="./"):
9394
cfg = ConfigParser()
9495
try:
95-
cfg.readfp(codecs.open(path + 'config.ini', 'r', 'utf8'))
96+
cfg.readfp(codecs.open(path + 'config.defaults.ini', 'r', 'utf8')) # read default configs
9697
except IOError:
97-
raise Exception("Cannot open configuration file. If you want to try the program and do not have a config, start ./run.py --example or just copy config.ini.example to config.ini")
98+
raise Exception("Cannot open config.defaults.ini.")
99+
if os.path.isfile(path + 'config.ini'):
100+
try:
101+
cfg.readfp(codecs.open(path + 'config.ini', 'r', 'utf8'))
102+
except IOError:
103+
raise Exception("Cannot open config.ini.")
104+
else:
105+
print("[!] 'config.ini' not found. Using 'config.defaults.ini'"
106+
" copy 'config.defaults.ini' to 'config.ini' to adapt the deafault config!")
98107
return cfg
99108

100109

INSTALLING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Modem-Manager interferes with the serial port. It is highly recommended to remov
7272
-----------------
7373

7474
cd FabLabKasse/
75-
cp config.ini.example config.ini
75+
cp config.defaults.ini config.ini
7676
# now edit config.ini file
7777

7878
Please use database name "production" for the real terminal, and something else for tests and development!

README.cashPayment

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Dies damit `./cash move muenz.manual muenz.tubeN /123x50c/` zurückgefüllt
122122
Configuration
123123
-------------
124124

125-
see config.ini.example
125+
see config.defaults.ini
126126

127127
order of devices is important! Payout is in ascending order of the device number. Payin is in parallel.
128128
Sort the devices from large to small denominations. (banknote payout first)

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TODO
44
Needed testing for FAU FabLab
55
-----------------------------
66

7-
cp config.ini.example config.ini
7+
cp config.defaults.ini config.ini
88

99
edit config.ini:
1010
- set [backend] backend=legacy_offline_kassenbuch

run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def main():
4949
currentDir = os.getcwd() + "/"
5050
os.chdir(currentDir + "/FabLabKasse/")
5151

52+
# TODO restructure this: simply provide a --config-file parameter but
53+
# always load config.defaults.ini first and the the users config
5254
if "--example" in sys.argv:
5355
# load example config
5456
# test that there is no config.ini yet
@@ -59,11 +61,10 @@ def main():
5961
time.sleep(2)
6062
else:
6163
print("loading example configuration file. edit FabLabKasse/config.ini to change. You do not need the --example parameter later.")
62-
shutil.copyfile("config.ini.example", "config.ini")
64+
shutil.copyfile("config.defaults.ini", "config.ini")
6365
if "--only-load-config" in sys.argv:
64-
# the Vagrant VM provisioning script uses this to copy a default config before the first start.
65-
sys.exit(0)
66-
66+
# the Vagrant VM provisioning script uses this to copy a default config before the first start.
67+
sys.exit(0)
6768

6869
os.chdir(currentDir + "/FabLabKasse/UI/")
6970
subprocess.call("./compile_all.py")

0 commit comments

Comments
 (0)