libjam 0.0.14__py3-none-any.whl → 0.0.16__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/drawer.py +2 -3
- libjam/notebook.py +22 -30
- libjam/typewriter.py +5 -2
- {libjam-0.0.14.dist-info → libjam-0.0.16.dist-info}/METADATA +1 -1
- libjam-0.0.16.dist-info/RECORD +11 -0
- libjam-0.0.14.dist-info/RECORD +0 -11
- {libjam-0.0.14.dist-info → libjam-0.0.16.dist-info}/WHEEL +0 -0
- {libjam-0.0.14.dist-info → libjam-0.0.16.dist-info}/licenses/LICENSE +0 -0
libjam/drawer.py
CHANGED
@@ -90,13 +90,12 @@ class Drawer:
|
|
90
90
|
|
91
91
|
# Returns a list of files in a given folder
|
92
92
|
def get_files(self, path: str):
|
93
|
-
path = realpath(path)
|
94
93
|
unfiltered_files = self.get_all(path)
|
95
94
|
files = []
|
96
95
|
for file in unfiltered_files:
|
97
|
-
if self.is_file:
|
96
|
+
if self.is_file(path):
|
98
97
|
files.append(file)
|
99
|
-
return
|
98
|
+
return files
|
100
99
|
|
101
100
|
# Returns a list of folders in a given folder
|
102
101
|
def get_folders(self, path: str):
|
libjam/notebook.py
CHANGED
@@ -8,9 +8,17 @@ drawer = Drawer()
|
|
8
8
|
# Deals with configs and reading/writing files
|
9
9
|
class Notebook:
|
10
10
|
|
11
|
+
# Reads a text file and returns a string.
|
12
|
+
def read_file(self, path):
|
13
|
+
if drawer.is_folder(path):
|
14
|
+
raise FileExistsError(f"Attempted to read folder '{path}' as a text file.")
|
15
|
+
elif drawer.is_file(path) is False:
|
16
|
+
raise FileNotFoundError(f"File '{path}' not found.")
|
17
|
+
return open(path, 'r').read()
|
18
|
+
|
11
19
|
# Checking if config exists, and creating one if it does not
|
12
20
|
def check_config(self, config_template_file: str, config_file: str):
|
13
|
-
config_template =
|
21
|
+
config_template = self.read_file(config_template_file)
|
14
22
|
config_folder = drawer.get_parent(config_file)
|
15
23
|
if drawer.is_folder(config_folder) is False:
|
16
24
|
drawer.make_folder(config_folder)
|
@@ -23,36 +31,24 @@ class Notebook:
|
|
23
31
|
|
24
32
|
# parsing a toml config
|
25
33
|
def read_toml(self, config_file: str):
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if type(path) == str:
|
35
|
-
data[category][item] = drawer.absolute_path(path)
|
36
|
-
return data
|
37
|
-
except:
|
38
|
-
print(f"Encountered error reading '{config_file}'")
|
39
|
-
print(f"Contents of '{config_file}':")
|
40
|
-
print(data)
|
41
|
-
return None
|
34
|
+
data = self.read_file(config_file)
|
35
|
+
data = tomllib.loads(data)
|
36
|
+
for category in data:
|
37
|
+
for item in data.get(category):
|
38
|
+
path = data.get(category).get(item)
|
39
|
+
if type(path) == str:
|
40
|
+
data[category][item] = drawer.absolute_path(path)
|
41
|
+
return data
|
42
42
|
|
43
43
|
# Reads ini file and returns its contents in the form of a dict.
|
44
44
|
# allow_duplicates is only to be used as a last resort due to the performance
|
45
45
|
# impact and inaccuracy in results.
|
46
46
|
def read_ini(self, ini_file: str, allow_duplicates=False):
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
parser = configparser.ConfigParser()
|
47
|
+
# Checking file
|
48
|
+
data = self.read_file(ini_file)
|
49
|
+
parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
51
50
|
try:
|
52
|
-
parser.
|
53
|
-
except configparser.InterpolationSyntaxError:
|
54
|
-
parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
55
|
-
parser.read(ini_file)
|
51
|
+
parser.read_string(data)
|
56
52
|
except configparser.DuplicateSectionError:
|
57
53
|
if allow_duplicates is True:
|
58
54
|
ini_string = open(ini_file, 'r').read()
|
@@ -95,7 +91,6 @@ class Notebook:
|
|
95
91
|
def write_ini(self, ini_file: str, contents: dict):
|
96
92
|
if drawer.is_file(ini_file) is False:
|
97
93
|
return None
|
98
|
-
ini_file = drawer.absolute_path(ini_file)
|
99
94
|
parser = configparser.ConfigParser()
|
100
95
|
for section in contents:
|
101
96
|
for var_name in contents.get(section):
|
@@ -109,10 +104,7 @@ class Notebook:
|
|
109
104
|
# Reads a given json file as a dictionary.
|
110
105
|
# Returns None if file doesn't exist.
|
111
106
|
def read_json(self, json_file: str):
|
112
|
-
|
113
|
-
return None
|
114
|
-
json_file = drawer.absolute_path(json_file)
|
115
|
-
json_string = open(json_file, 'r').read()
|
107
|
+
json_string = self.read_file(json_file)
|
116
108
|
json_string = json_string.replace('null', 'None')
|
117
109
|
# Trying the sane method
|
118
110
|
try:
|
libjam/typewriter.py
CHANGED
@@ -83,7 +83,10 @@ class Typewriter:
|
|
83
83
|
# Adding spaces
|
84
84
|
current_text = 0
|
85
85
|
for text in column:
|
86
|
-
|
86
|
+
if current_column == len(columns) - 1:
|
87
|
+
spaces = ''
|
88
|
+
else:
|
89
|
+
spaces = ' ' * ((column_width - len(text)) + 1)
|
87
90
|
columns[current_column][current_text] = text + spaces
|
88
91
|
current_text += 1
|
89
92
|
current_column += 1
|
@@ -121,4 +124,4 @@ class Typewriter:
|
|
121
124
|
for text in row:
|
122
125
|
output += text
|
123
126
|
# Returning string
|
124
|
-
return output
|
127
|
+
return output.rstrip()
|
@@ -0,0 +1,11 @@
|
|
1
|
+
libjam/__init__.py,sha256=iLE2y9r0Sfe3oIeoFHKwFIyLL6d_KcLP7fINd7pPAlY,145
|
2
|
+
libjam/captain.py,sha256=igx-ecKJBI_vBN-pW7KmSEnmYMIHQEb9tFzpy5qHmI8,5636
|
3
|
+
libjam/clipboard.py,sha256=5HxlO8ztLJPlnSCq4PncGvY4JGc9C4J2uHcepjC6zmg,3496
|
4
|
+
libjam/drawer.py,sha256=O9OdUaS_eTmcpoB2K92iKQoZ0w-wr2WWxP88Rpt7YuY,12071
|
5
|
+
libjam/flashcard.py,sha256=ulV4KPC3BRWLxwkQ87vsY0aM38nYpzOjUOISxTIRVDg,437
|
6
|
+
libjam/notebook.py,sha256=uGHqQD01SLrCIqMmzQayyk6PNeE15nJXJYUmmcJvf9U,4289
|
7
|
+
libjam/typewriter.py,sha256=6XcYIsCwoNkyyuwiDm3-QP52Dl70sJSGbO8ikjrPNvo,3996
|
8
|
+
libjam-0.0.16.dist-info/METADATA,sha256=vME3zfJLi3jOOi8OG9ZbcpMIDJhNmh5MuhHjuaeCXzQ,2141
|
9
|
+
libjam-0.0.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
libjam-0.0.16.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
|
11
|
+
libjam-0.0.16.dist-info/RECORD,,
|
libjam-0.0.14.dist-info/RECORD
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
libjam/__init__.py,sha256=iLE2y9r0Sfe3oIeoFHKwFIyLL6d_KcLP7fINd7pPAlY,145
|
2
|
-
libjam/captain.py,sha256=igx-ecKJBI_vBN-pW7KmSEnmYMIHQEb9tFzpy5qHmI8,5636
|
3
|
-
libjam/clipboard.py,sha256=5HxlO8ztLJPlnSCq4PncGvY4JGc9C4J2uHcepjC6zmg,3496
|
4
|
-
libjam/drawer.py,sha256=vKL1iN8chHjXZRsTdmhE8qpDaZAgh7Orx5KtrvgplcE,12100
|
5
|
-
libjam/flashcard.py,sha256=ulV4KPC3BRWLxwkQ87vsY0aM38nYpzOjUOISxTIRVDg,437
|
6
|
-
libjam/notebook.py,sha256=3Loo76CGAWK5LmyBKB8UwZhs_STH-U93aqqSav93oJI,4545
|
7
|
-
libjam/typewriter.py,sha256=_fdXGGn2fpSwfco0bwR8LPm-DVRJgvwiX7n4HllUHuY,3902
|
8
|
-
libjam-0.0.14.dist-info/METADATA,sha256=8aPT0aG-SPlPtGZgabG6kpU5ijEhX8DwikBVR11yq8o,2141
|
9
|
-
libjam-0.0.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
-
libjam-0.0.14.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
|
11
|
-
libjam-0.0.14.dist-info/RECORD,,
|
File without changes
|
File without changes
|