Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved config.ini.example to config.defaults.ini #109

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 7 additions & 4 deletions FabLabKasse/cashPayment/client/PaymentDevicesManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ConfigParser import ConfigParser
import codecs


class PaymentDevicesManager(object):

def __init__(self, cfg):
Expand Down Expand Up @@ -157,7 +158,7 @@ def canPayout(self):
return None
if self.mode == "canPayout":
# commands already sent
if not None in self.canPayoutAmounts:
if None not in self.canPayoutAmounts:
# all devices sent replies
canPayoutAmounts = self.canPayoutAmounts
self.canPayoutAmounts = None # invalidate cache
Expand Down Expand Up @@ -232,7 +233,7 @@ def _updatePayinAmounts(self):
"""
for d in self.devices:
maximum = self.maximumPayin - self.getCurrentAmount()
if d.getCurrentAmount() != None:
if d.getCurrentAmount() is not None:
maximum += d.getCurrentAmount()
d.updateAcceptValue(maximum)

Expand All @@ -242,7 +243,7 @@ def getCurrentAmount(self):
"""
totalSum = self.finishedAmount
for d in self.devices:
if d.getCurrentAmount() != None:
if d.getCurrentAmount() is not None:
totalSum += d.getCurrentAmount()
return totalSum

Expand Down Expand Up @@ -346,6 +347,7 @@ def getFinalAmount(self):
self.mode = "idle"
return ret


class PaymentDevicesManagerTest(unittest.TestCase):
""" Test PaymentDevicesManager
"""
Expand All @@ -355,7 +357,7 @@ def test_canPayout_with_one_random_datapoint_on_example_server(self):
"""
# probably hacky, should be improved
cfg = ConfigParser()
cfg.readfp(codecs.open('./FabLabKasse/config.ini.example', 'r', 'utf8'))
cfg.readfp(codecs.open('./FabLabKasse/config.defaults.ini', 'r', 'utf8'))

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


def demo():
"""Simple demonstration using two exampleServer devices"""
# TODO this code seems to be broken, maybe adapt code from unittest or discard
Expand Down
File renamed without changes.
13 changes: 11 additions & 2 deletions FabLabKasse/scriptHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import signal
import logging
import logging.handlers
import os
import sys
import portalocker
import sqlite3
Expand Down Expand Up @@ -92,9 +93,17 @@ def myNewExceptionHook(exctype, value, tb):
def getConfig(path="./"):
cfg = ConfigParser()
try:
cfg.readfp(codecs.open(path + 'config.ini', 'r', 'utf8'))
cfg.readfp(codecs.open(path + 'config.defaults.ini', 'r', 'utf8')) # read default configs
except IOError:
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")
raise Exception("Cannot open config.defaults.ini.")
if os.path.isfile(path + 'config.ini'):
try:
cfg.readfp(codecs.open(path + 'config.ini', 'r', 'utf8'))
except IOError:
raise Exception("Cannot open config.ini.")
else:
print("[!] 'config.ini' not found. Using 'config.defaults.ini'"
" copy 'config.defaults.ini' to 'config.ini' to adapt the deafault config!")
return cfg


Expand Down
2 changes: 1 addition & 1 deletion INSTALLING
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Modem-Manager interferes with the serial port. It is highly recommended to remov
-----------------

cd FabLabKasse/
cp config.ini.example config.ini
cp config.defaults.ini config.ini
# now edit config.ini file

Please use database name "production" for the real terminal, and something else for tests and development!
Expand Down
2 changes: 1 addition & 1 deletion README.cashPayment
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Dies damit `./cash move muenz.manual muenz.tubeN /123x50c/` zurückgefüllt
Configuration
-------------

see config.ini.example
see config.defaults.ini

order of devices is important! Payout is in ascending order of the device number. Payin is in parallel.
Sort the devices from large to small denominations. (banknote payout first)
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TODO
Needed testing for FAU FabLab
-----------------------------

cp config.ini.example config.ini
cp config.defaults.ini config.ini
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this is not really true anymore...


edit config.ini:
- set [backend] backend=legacy_offline_kassenbuch
Expand Down
9 changes: 5 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def main():
currentDir = os.getcwd() + "/"
os.chdir(currentDir + "/FabLabKasse/")

# TODO restructure this: simply provide a --config-file parameter but
# always load config.defaults.ini first and the the users config
if "--example" in sys.argv:
# load example config
# test that there is no config.ini yet
Expand All @@ -59,11 +61,10 @@ def main():
time.sleep(2)
else:
print("loading example configuration file. edit FabLabKasse/config.ini to change. You do not need the --example parameter later.")
shutil.copyfile("config.ini.example", "config.ini")
shutil.copyfile("config.defaults.ini", "config.ini")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

if "--only-load-config" in sys.argv:
# the Vagrant VM provisioning script uses this to copy a default config before the first start.
sys.exit(0)

# the Vagrant VM provisioning script uses this to copy a default config before the first start.
sys.exit(0)

os.chdir(currentDir + "/FabLabKasse/UI/")
subprocess.call("./compile_all.py")
Expand Down