-
Notifications
You must be signed in to change notification settings - Fork 0
/
ez_preferences.py
171 lines (143 loc) · 5.51 KB
/
ez_preferences.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
This module encapsulates personal user preferences and should be used where
appropriate
"""
from os import path, makedirs
from sys import exit
#==============================================================================#
# DomainError #
#==============================================================================#
class DomainError(Exception):
"""
DomainError exception is raised if the user specified a wrong domain, i.e. a
line height that is not in the given ranges.
"""
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
#==============================================================================#
# FUNCTIONS #
#==============================================================================#
def join(var, file_name=None):
"""
VAR = ('SUBDIR', "DESCRIPTION")
Makes sure that SUBDIR exists and create it if necessary. Return the SUBDIR
joined with the file_name
"""
subdir, desc = var
location = path.join(local_path, subdir)
if not path.isdir(location):
print("Creating " + location + " for " + desc)
makedirs(location)
if file_name:
return path.join(location, file_name)
else:
return location
#============================================#
# CLI prefs. - Appearance and key bindings #
#============================================#
cli_edit_range = range(1, 30)
cli_msg_range = range(1, 30)
cli_status_range = range(0, 20)
cli_option_frac_range = range(10, 50)
# TODO: JNicL the actual settings should be read from a rc file Sa 04 Okt 2014 12:29:28 CEST
# Hardcoded for now
def init_cli_preferences():
#==============#
# Appearance #
#==============#
global cli_edit_height
cli_edit_height = 5 # 10 rows + built in scrolling
if not cli_edit_height in cli_edit_range:
raise DomainError('cli_edit_height(' + str(cli_edit_height) +
') out of range')
global cli_msg_height
cli_msg_height = 20 # 25 rows + scrolling possible, however,
# no focus yet
if not cli_msg_height in cli_msg_range:
raise DomainError('cli_msg_height(' + str(cli_msg_height) +
') out of range ')
global cli_status_height
cli_status_height = 4 # 4 rows = 4 status msges. Can be disabled by
# setting to 0
if not cli_status_height in cli_status_range:
raise DomainError('cli_status_height(' + str(cli_status_height) +
') out of range ')
global cli_options_fraction
cli_options_fraction = 25 # 25 %
if not cli_options_fraction in cli_option_frac_range:
raise DomainError('cli_options_fraction(' + str(cli_options_fraction) +
') out of range ')
global cli_start_in_insertmode
cli_start_in_insertmode = False
#================#
# Key bindings #
#================#
global cli_command_dict
cli_command_dict = {}
#abbreviation
ccd = cli_command_dict
# do not worry that I wrapped the keys as tuples, I need it to iterate over
# keys mapped on the same command. The user will not have to specify the keys
# in this way, and the keys will be read from an rc file.
ccd['cli_enter_cmdline'] = (':',)
ccd['cli_delete_one'] = ('x',)
ccd['cli_delete'] = ('d',)
ccd['cli_insert'] = ('i',)
ccd['cli_append'] = ('a',)
ccd['cli_delete'] = ('d',)
ccd['cli_newline_low'] = ('o',)
ccd['cli_newline_high'] = ('O',)
ccd['cli_move_left'] = ('h', 'left')
ccd['cli_move_right'] = ('l', 'right')
ccd['cli_move_down'] = ('j', 'up')
ccd['cli_move_up'] = ('k', 'down')
ccd['cli_scroll_msg_up'] = ('K',)
ccd['cli_scroll_msg_down'] = ('J',)
#=======================#
# process preferences #
#=======================#
global process_preferences
process_preferences = {}
# time period(seconds) with which all users are are requested to sync msges
process_preferences['db_bgsync_timeout'] = 60
# time period with which all users are passively pinged
process_preferences['ping_bg_timeout'] = 10
# pingreply waittime
process_preferences['ping_reply_timeout'] = 4
process_preferences['silent_ping'] = False
#===================#
# acception rules #
#===================#
global acception_rules
acception_rules = {}
acception_rules['global_rule'] = 'Allow'
#acception_rules['distributeIPs'] = 'Auth'
process_preferences['acception_rules'] = acception_rules
#==============#
# User prefs #
#==============#
# ------- Directorys --------
"""
Here we define the local path, and the subdirectories for user specific files.
The existence is ensured by join()
format:
VAR = ('SUBDIR', "DESCRIPTION")
"""
# TODO: (bcn 2014-10-18) This should become ~/.local/share/ezchat/
local_path = 'local'
location = {}
location['key'] = ('keys', "private key files")
location['hist'] = ('history', "history files")
location['db'] = ('database', "database files for users and messages")
location['log'] = ('log', "log files")
location['gpg'] = ('.ez_gpg', "GnuPG Keys for eZchat")
# ------- Files --------
command_history = join(location['hist'], 'command_history.txt')
default_db = join(location['db'], 'ez.db')
# ------- Colors --------
palette = [
('online', 'light green', 'dark green'),
('offline', 'dark red', 'light red'),
]