Commit c17027df by Owo Sugiana

read_conf.py menjalankan module.init()

1 parent e1aed41f
0.1.4 2020-04-22
----------------
- Parser.run() mencatat kesalahan tak terduga
- web-client.py bisa untuk inquiry dan payment
- read_conf.py kini menjalankan init() dari setiap module.
0.1.3 2020-01-16
----------------
- Log yang lebih baik
......
......@@ -15,7 +15,7 @@ Buat Python virtual environment::
Awali dengan memasang paket `ebcdic <https://pypi.org/project/ebcdic/>`_
yang dibutuhkan `ISO8583 <https://pypi.org/project/ISO8583/>`_::
$ ~/env/bin/pip install ebcdic
$ ~/env/bin/pip install -r requirements.txt
Pemasangan yang tidak otomatis ini agar tidak menimbulkan kegagalan. Lanjut::
......@@ -66,7 +66,7 @@ menjadi::
Simpan, lalu jalankan::
../env/bin/iso8583 test-bjb.ini
$ ~/env/bin/iso8583 test-bjb.ini
Log File
--------
......@@ -107,7 +107,7 @@ membuat aplikasi teller bank. Pada ``test-bjb.ini`` aktifkan section
Kemudian restart daemon-nya. Setelah *echo established* dengan daemon pemda
lakukan *echo request* dengan cara::
$ ../env/bin/python contrib/web-client.py
$ ~/env/bin/python contrib/web-client.py
Hasilnya menjadi seperti ini::
......
......@@ -10,6 +10,7 @@ from threading import Thread
from optparse import OptionParser
headers = {'content-type': 'application/json'}
threads = {}
end_threads = []
durations = {}
......@@ -47,27 +48,35 @@ def log_info(s):
default_url = 'http://localhost:7000/rpc'
default_host = 'pemda'
default_count = 1
default_method = 'echo'
help_url = 'default ' + default_url
help_host = 'default ' + default_host
help_count = 'default {}'.format(default_count)
help_method = 'default ' + default_method
help_invoice_id = 'dibutuhkan saat --method inquiry, payment, atau reversal'
help_amount = 'dibutuhkan saat --method=payment'
parser = OptionParser()
parser.add_option('', '--url', default=default_url, help=help_url)
parser.add_option('', '--host', default=default_host, help=help_host)
parser.add_option(
'-c', '--count', type='int', default=default_count, help=help_count)
parser.add_option('', '--method', default=default_method, help=help_method)
parser.add_option('', '--invoice-id', help=help_invoice_id)
parser.add_option('', '--amount', type=int, help=help_amount)
option, args = parser.parse_args(sys.argv[1:])
url = option.url
count = option.count
headers = {'content-type': 'application/json'}
p = {'host': option.host}
data = {
'method': 'echo',
'params': [p],
'jsonrpc': '2.0',
}
p = dict(host=option.host)
if option.method != 'echo':
p['invoice_id'] = option.invoice_id
if option.method == 'payment':
p['amount'] = option.amount
p['ntb'] = datetime.now().strftime('%Y%m%d%H%m%s')
data = dict(method=option.method, params=[p], jsonrpc='2.0')
for i in range(count):
data['id'] = i
thread = create_thread(send, [dict(data)])
......
......@@ -123,6 +123,7 @@ def read_conf(conf_file):
if conf.has_section(module_section):
for key in conf.options(module_section):
cfg[key] = conf.get(module_section, key)
cfg['module_obj'].init(cfg)
append_others(cfg, conf, section)
if cfg['listen']:
if port not in listen_ports:
......
......@@ -332,7 +332,12 @@ class Parser(Log):
def run(self):
from_iso = self.connection.job.raw_to_iso(self.raw)
self.log_decode(from_iso)
iso = self.connection.job.process(from_iso)
try:
iso = self.connection.job.process(from_iso)
except:
self.log_unknown()
self.running = False
return
if iso:
self.log_ack(iso)
self.log_encode(iso)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!