forked from vim-vdebug/vdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopts.py
More file actions
55 lines (44 loc) · 1.33 KB
/
Copy pathopts.py
File metadata and controls
55 lines (44 loc) · 1.33 KB
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
class Options:
instance = None
def __init__(self,options):
self.options = options
@classmethod
def set(cls,options):
"""Create an Options instance with the provided dictionary of
options"""
cls.instance = Options(options)
@classmethod
def inst(cls):
"""Get the Options instance.
"""
if cls.instance is None:
raise OptionsError("No options have been set")
return cls.instance
@classmethod
def get(cls,name,as_type = str):
"""Get an option by name.
Raises an OptionsError if the option doesn't exist.
"""
inst = cls.inst()
if name in inst.options:
return as_type(inst.options[name])
else:
raise OptionsError("No option with key '%s'" % name)
@classmethod
def overwrite(cls,name,value):
inst = cls.inst()
inst.options[name] = value
@classmethod
def isset(cls,name):
"""Checks whether the option exists and is set.
By set, it means whether the option has length. All the option
values are strings.
"""
inst = cls.inst()
if name in inst.options and \
len(inst.options[name]) > 0:
return True
else:
return False
class OptionsError(Exception):
pass