libjam 0.0.11__py3-none-any.whl → 0.0.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
libjam/notebook.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Imports
|
2
|
-
import
|
2
|
+
import tomllib, configparser, json, ast, re
|
3
3
|
from .drawer import Drawer
|
4
4
|
|
5
5
|
# Jam classes
|
@@ -23,7 +23,7 @@ class Notebook:
|
|
23
23
|
|
24
24
|
# parsing a toml config
|
25
25
|
def read_toml(self, config_file: str):
|
26
|
-
config_file =
|
26
|
+
config_file = drawer.absolute_path(config_file)
|
27
27
|
# Parsing config
|
28
28
|
data = open(config_file, 'r').read()
|
29
29
|
try:
|
@@ -32,7 +32,7 @@ class Notebook:
|
|
32
32
|
for item in data.get(category):
|
33
33
|
path = data.get(category).get(item)
|
34
34
|
if type(path) == str:
|
35
|
-
data[category][item] =
|
35
|
+
data[category][item] = drawer.absolute_path(path)
|
36
36
|
return data
|
37
37
|
except:
|
38
38
|
print(f"Encountered error reading '{config_file}'")
|
@@ -40,17 +40,45 @@ class Notebook:
|
|
40
40
|
print(data)
|
41
41
|
return None
|
42
42
|
|
43
|
-
# Reads ini file and returns its contents in the form of a dict
|
44
|
-
|
43
|
+
# Reads ini file and returns its contents in the form of a dict.
|
44
|
+
# allow_duplicates is only to be used as a last resort due to the performance
|
45
|
+
# impact and inaccuracy in results.
|
46
|
+
def read_ini(self, ini_file: str, inline_comments=False, allow_duplicates=False):
|
45
47
|
if drawer.is_file(ini_file) is False:
|
46
48
|
return None
|
47
|
-
ini_file =
|
49
|
+
ini_file = drawer.absolute_path(ini_file)
|
48
50
|
if inline_comments is True:
|
49
51
|
parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
50
52
|
else:
|
51
53
|
parser = configparser.ConfigParser()
|
52
54
|
try:
|
53
55
|
parser.read(ini_file)
|
56
|
+
except configparser.DuplicateSectionError:
|
57
|
+
if allow_duplicates is True:
|
58
|
+
ini_string = open(ini_file, 'r').read()
|
59
|
+
ini_string = re.sub(';.*', '', ini_string) # Removing comments
|
60
|
+
ini_sections = ini_string.replace(' =', '=').replace('= ', '=')
|
61
|
+
ini_sections = ini_sections.replace('\n', ';')
|
62
|
+
ini_sections = ini_sections.replace('[', '\n[')
|
63
|
+
ini_sections = ini_sections.removeprefix('\n')
|
64
|
+
ini_sections = ini_sections.split('\n')
|
65
|
+
ini_dict = {}
|
66
|
+
for section in ini_sections:
|
67
|
+
section_name = re.sub('];.*', '', section).replace('[', '')
|
68
|
+
section_name = section_name.upper()
|
69
|
+
ini_dict[section_name] = {}
|
70
|
+
declarations = section.removeprefix(f"[{section_name}];")
|
71
|
+
declarations = declarations.split(';')
|
72
|
+
for declaration in declarations:
|
73
|
+
if declaration == '':
|
74
|
+
continue
|
75
|
+
info = declaration.split('=')
|
76
|
+
name = info[0].lower()
|
77
|
+
value = info[1]
|
78
|
+
ini_dict[section_name][name] = value
|
79
|
+
return ini_dict
|
80
|
+
else:
|
81
|
+
return None
|
54
82
|
except configparser.ParsingError:
|
55
83
|
return None
|
56
84
|
sections = parser.sections()
|
@@ -67,7 +95,7 @@ class Notebook:
|
|
67
95
|
def write_ini(self, ini_file: str, contents: dict):
|
68
96
|
if drawer.is_file(ini_file) is False:
|
69
97
|
return None
|
70
|
-
ini_file =
|
98
|
+
ini_file = drawer.absolute_path(ini_file)
|
71
99
|
parser = configparser.ConfigParser()
|
72
100
|
for section in contents:
|
73
101
|
for var_name in contents.get(section):
|
@@ -82,7 +110,7 @@ class Notebook:
|
|
82
110
|
def read_json(self, json_file: str):
|
83
111
|
if drawer.is_file(json_file) is False:
|
84
112
|
return None
|
85
|
-
json_file =
|
113
|
+
json_file = drawer.absolute_path(json_file)
|
86
114
|
json_string = open(json_file, 'r').read()
|
87
115
|
try:
|
88
116
|
data = json.loads(json_string)
|
@@ -3,9 +3,9 @@ libjam/captain.py,sha256=igx-ecKJBI_vBN-pW7KmSEnmYMIHQEb9tFzpy5qHmI8,5636
|
|
3
3
|
libjam/clipboard.py,sha256=5HxlO8ztLJPlnSCq4PncGvY4JGc9C4J2uHcepjC6zmg,3496
|
4
4
|
libjam/drawer.py,sha256=vKL1iN8chHjXZRsTdmhE8qpDaZAgh7Orx5KtrvgplcE,12100
|
5
5
|
libjam/flashcard.py,sha256=ulV4KPC3BRWLxwkQ87vsY0aM38nYpzOjUOISxTIRVDg,437
|
6
|
-
libjam/notebook.py,sha256=
|
6
|
+
libjam/notebook.py,sha256=ML-z5RVlahOcxoTVdskl5sEPDksYEF8QQ5EkW9KR6Rc,4395
|
7
7
|
libjam/typewriter.py,sha256=waKY1sDxGzI2ZT5dSzFmLGbaNTIpEM5Zhg_OlPFUAng,3730
|
8
|
-
libjam-0.0.
|
9
|
-
libjam-0.0.
|
10
|
-
libjam-0.0.
|
11
|
-
libjam-0.0.
|
8
|
+
libjam-0.0.12.dist-info/METADATA,sha256=VUUJKt2t-qY5P3m0T7OwkyfvYPAyAJ4oOcDcJfiyr5o,2141
|
9
|
+
libjam-0.0.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
libjam-0.0.12.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
|
11
|
+
libjam-0.0.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|