-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelves.py
80 lines (69 loc) · 2.73 KB
/
shelves.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
###
##
# Copyright (C) 2021 James A. Bowery
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see: <http://www.gnu.org/licenses/>.
##
###
import logging
import redisshelve
from redis import Redis
import os
import shelve
from global_utils import dd_path
from dotenv import load_dotenv
load_dotenv(override=True)
try:
nick2REGN_NUMs = shelve.open(str(dd_path/'nicks2REGN_NUMS.shelf'))
except:
nick2REGN_NUMs = dict()
# nick2REGN_NUMs = shelve.open(str(dd_path/'nicks2REGN_NUMS.shelf'),flag='r')
REDIS_SOCKET= os.getenv("REDIS_SOCKET")
def Redis_Connect(db=0):
#REDIS_SOCKET_URL=redis.from_url('unix://@/var/run/redis-myname/redis-server.sock')
# return Redis(unix_socket_path=REDIS_SOCKET, db=db) if REDIS_SOCKET else Redis(db=db)
return Redis(unix_socket_path=REDIS_SOCKET, db=db)
def Redis_Connect_Public_Audit(db=0):
#REDIS_SOCKET_URL=redis.from_url('unix://@/var/run/redis-myname/redis-server.sock')
return Redis(db=db,port=6380)
transactions_shelve_db_number = os.getenv("REDIS_TRANSACTIONS_DB") or 0
transactions_redis = Redis_Connect_Public_Audit(db=transactions_shelve_db_number)
transactions_shelve = redisshelve.RedisShelf(redis=transactions_redis)
sessions_shelve_db_number = os.getenv("REDIS_SESSIONS_DB") or 1
sessions_redis = Redis_Connect(db=sessions_shelve_db_number)
sessions_shelve = redisshelve.RedisShelf(redis=sessions_redis)
voters_shelve_db_number = os.getenv("REDIS_VOTERS_DB") or 2
voters_redis = Redis_Connect(db=voters_shelve_db_number)
voters_shelve = redisshelve.RedisShelf(redis=voters_redis)
properties_shelve_db_number = os.getenv("REDIS_PROPERTIES_DB") or 4
properties_redis = Redis_Connect(db=properties_shelve_db_number)
properties_shelve = redisshelve.RedisShelf(redis=properties_redis)
def purge_all():
# to purge all shelves, in ipython execute:
#from shelves import *
for x in ['properties','voters','transactions','sessions']:
logging.debug(x)
purge(x)
def purge(x):
shelve = eval(x+'_shelve')
for k in shelve:
# print(f'deleting {k}: {shelve[k]}')
print(f'deleting {k}')
del shelve[k]
shelve.sync()
def show(sn):
shelve = eval(sn+'_shelve')
for k in shelve:
print(f'{k}:')
print(f'{shelve[k]}')