libjam 0.0.10__tar.gz → 0.0.12__tar.gz
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-0.0.10 → libjam-0.0.12}/PKG-INFO +1 -1
- {libjam-0.0.10 → libjam-0.0.12}/build.sh +1 -1
- {libjam-0.0.10 → libjam-0.0.12}/libjam/drawer.py +5 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/notebook.py +36 -8
- {libjam-0.0.10 → libjam-0.0.12}/pyproject.toml +2 -2
- libjam-0.0.10/requirements.txt +0 -3
- {libjam-0.0.10 → libjam-0.0.12}/.gitignore +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/LICENSE +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/README.md +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/__init__.py +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/captain.py +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/clipboard.py +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/flashcard.py +0 -0
- {libjam-0.0.10 → libjam-0.0.12}/libjam/typewriter.py +0 -0
@@ -40,6 +40,11 @@ def realpaths(path: list):
|
|
40
40
|
# Deals with files
|
41
41
|
class Drawer:
|
42
42
|
|
43
|
+
# Converts the given path to absolute
|
44
|
+
def absolute_path(self, path):
|
45
|
+
path = realpath(path)
|
46
|
+
return outpath(path)
|
47
|
+
|
43
48
|
# Returns True if give a path to folder
|
44
49
|
def is_folder(self, path: str):
|
45
50
|
if path == '':
|
@@ -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)
|
@@ -14,7 +14,7 @@ include = [
|
|
14
14
|
|
15
15
|
[project]
|
16
16
|
name = "libjam"
|
17
|
-
version = "0.0.
|
17
|
+
version = "0.0.12"
|
18
18
|
authors = [
|
19
19
|
{ name="Philipp Kosarev", email="philipp.kosarev@gmail.com" },
|
20
20
|
]
|
@@ -30,4 +30,4 @@ license-files = ["LICEN[CS]E*"]
|
|
30
30
|
|
31
31
|
[project.urls]
|
32
32
|
Homepage = "https://github.com/philippkosarev/libjam"
|
33
|
-
Issues = "https://github.com/philippkosarev/libjam/issues"
|
33
|
+
Issues = "https://github.com/philippkosarev/libjam/issues"
|
libjam-0.0.10/requirements.txt
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|