Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit 60f7722

Browse files
committed
Add debug messages & location display
1 parent 4a54c69 commit 60f7722

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

tests/berlinium/gui_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tilde.core.settings import settings
1313

1414

15-
logging.basicConfig(level=logging.INFO)
15+
logging.basicConfig(level=logging.DEBUG)
1616
START_TIME = time.time()
1717

1818
class RespHandler(object):
@@ -32,20 +32,20 @@ def on_open(self, ws):
3232

3333
@classmethod
3434
def on_message(self, ws, message):
35-
logging.debug("Received: %s" % message[:100])
35+
logging.debug("Received: %s" % message[:200])
3636
message = json.loads(message)
37-
37+
3838
if message['act'] == 'login':
3939
ws.send(json.dumps({'act': 'tags', 'req': {}}))
4040

4141
elif message['act'] == 'tags':
4242
ws.send(json.dumps({'act': 'browse', 'req': {'tids': [2]}}))
4343

4444
elif message['act'] == 'browse':
45-
ws.send(json.dumps({'act': 'summary', 'req': {'datahash': 'QZAKBZE26UUMBYJBDDG7XBNYN5IZJJAAW3VI5OJ2CJPXCCI'}}))
45+
ws.send(json.dumps({'act': 'summary', 'req': {'datahash': 'UwrPlqexHZjtgKjK4awu4KBxArdSJdwmPq5GShdF9qY7lQPzPDF'}}))
4646

4747
elif message['act'] == 'summary':
48-
ws.send(json.dumps({'act': 'estory', 'req': {'datahash': 'OLRUC4GMJKHKOFIEQIDNQBJDII4UH5WQCGQRO5MXD36GSCI'}}))
48+
ws.send(json.dumps({'act': 'estory', 'req': {'datahash': '46AISOZQVLHNZZVZ53PPOTHRNHF3JRYYTECKNJ7QNMQXQCI'}}))
4949

5050
elif message['act'] == 'estory':
5151
logging.info("Client done in: %1.2f sc" % (time.time() - START_TIME))

tilde/berlinium/async_impl.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from tilde.core.settings import settings, connect_database
1818

1919

20-
thread_pool = ThreadPoolExecutor(max_workers=5*multiprocessing.cpu_count())
20+
thread_pool = ThreadPoolExecutor(max_workers=4*multiprocessing.cpu_count())
2121

2222
class Connection(SockJSConnection):
2323
Type = 'asynchronous'
@@ -52,12 +52,18 @@ def on_message(self, message):
5252

5353
def worker(frame):
5454
db_session = connect_database(settings, default_actions=False, no_pooling=True)
55+
logging.debug("New DB connection to %s" % (
56+
settings['db']['default_sqlite_db']
57+
if settings['db']['engine'] == 'sqlite'
58+
else settings['db']['dbname'] + '@' + settings['db']['engine']
59+
))
5560

5661
frame['result'], frame['error'] = getattr(self.GUIProvider, frame['act'])( frame['req'], frame['client_id'], db_session )
5762

5863
# must explicitly close db connection inside a thread
5964
db_session.close()
6065
del db_session
66+
logging.debug("DB connection closed")
6167

6268
return frame
6369

tilde/berlinium/block_impl.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def on_message(self, message):
4444
frame['error'] = 'No server handler for action: %s' % frame['act']
4545
return self.respond(frame)
4646

47-
if not Connection.Clients[frame['client_id']].db: Connection.Clients[frame['client_id']].db = connect_database(settings, default_actions=False, no_pooling=True)
47+
if not Connection.Clients[frame['client_id']].db:
48+
Connection.Clients[frame['client_id']].db = connect_database(settings, default_actions=False, no_pooling=True)
49+
logging.debug("New DB connection to %s" % (
50+
settings['db']['default_sqlite_db']
51+
if settings['db']['engine'] == 'sqlite'
52+
else settings['db']['dbname'] + '@' + settings['db']['engine']
53+
))
4854

4955
frame['result'], frame['error'] = getattr(self.GUIProvider, frame['act'])( frame['req'], frame['client_id'], Connection.Clients[frame['client_id']].db )
5056
self.respond(frame)
@@ -65,5 +71,6 @@ def on_close(self):
6571
try:
6672
self.Clients[client_id].db.close()
6773
self.Clients[client_id].db = None
74+
logging.debug("DB connection closed")
6875
except: pass
6976
del self.Clients[client_id]

tilde/berlinium/categs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

2+
import os
3+
24
from tilde.core.common import html_formula, num2name
35

6+
47
def wrap_cell(entity, json_obj, mapping, table_view=False):
58
'''
69
Cell wrappers
@@ -35,6 +38,9 @@ def wrap_cell(entity, json_obj, mapping, table_view=False):
3538
elif entity['source'] == 'dims':
3639
out = "%4.2f" % json_obj['dims'] if json_obj['periodicity'] in [2, 3] else '—'
3740

41+
elif entity['source'] == 'location':
42+
out = json_obj['location'].split(os.sep)[-1]
43+
3844
else:
3945
out = num2name(json_obj.get(entity['source']), entity, mapping) or '—'
4046

0 commit comments

Comments
 (0)