libjam 0.0.12__py3-none-any.whl → 0.0.14__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 +10 -8
- libjam/typewriter.py +15 -10
- {libjam-0.0.12.dist-info → libjam-0.0.14.dist-info}/METADATA +1 -1
- {libjam-0.0.12.dist-info → libjam-0.0.14.dist-info}/RECORD +6 -6
- {libjam-0.0.12.dist-info → libjam-0.0.14.dist-info}/WHEEL +0 -0
- {libjam-0.0.12.dist-info → libjam-0.0.14.dist-info}/licenses/LICENSE +0 -0
libjam/notebook.py
CHANGED
@@ -43,16 +43,16 @@ class Notebook:
|
|
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
|
-
def read_ini(self, ini_file: str,
|
46
|
+
def read_ini(self, ini_file: str, allow_duplicates=False):
|
47
47
|
if drawer.is_file(ini_file) is False:
|
48
48
|
return None
|
49
49
|
ini_file = drawer.absolute_path(ini_file)
|
50
|
-
|
51
|
-
parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
52
|
-
else:
|
53
|
-
parser = configparser.ConfigParser()
|
50
|
+
parser = configparser.ConfigParser()
|
54
51
|
try:
|
55
52
|
parser.read(ini_file)
|
53
|
+
except configparser.InterpolationSyntaxError:
|
54
|
+
parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
55
|
+
parser.read(ini_file)
|
56
56
|
except configparser.DuplicateSectionError:
|
57
57
|
if allow_duplicates is True:
|
58
58
|
ini_string = open(ini_file, 'r').read()
|
@@ -107,16 +107,18 @@ class Notebook:
|
|
107
107
|
parser.write(file)
|
108
108
|
|
109
109
|
# Reads a given json file as a dictionary.
|
110
|
+
# Returns None if file doesn't exist.
|
110
111
|
def read_json(self, json_file: str):
|
111
112
|
if drawer.is_file(json_file) is False:
|
112
113
|
return None
|
113
114
|
json_file = drawer.absolute_path(json_file)
|
114
115
|
json_string = open(json_file, 'r').read()
|
116
|
+
json_string = json_string.replace('null', 'None')
|
117
|
+
# Trying the sane method
|
115
118
|
try:
|
116
119
|
data = json.loads(json_string)
|
120
|
+
# Exception in case json contains multiline values
|
117
121
|
except json.decoder.JSONDecodeError:
|
118
|
-
json_string =
|
122
|
+
json_string = ' '.join(json_string.split())
|
119
123
|
data = ast.literal_eval(json_string)
|
120
|
-
except:
|
121
|
-
data = None
|
122
124
|
return data
|
libjam/typewriter.py
CHANGED
@@ -3,26 +3,31 @@ import shutil
|
|
3
3
|
|
4
4
|
# Responsible for formatting, modification and printing of strings
|
5
5
|
class Typewriter:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
self.CURSOR_UP = '\033[1A'
|
6
|
+
# Shorthand vars
|
7
|
+
BOLD = '\033[1m'
|
8
|
+
NORMAL = '\033[0m'
|
9
|
+
CLEAR = '\x1b[2K'
|
10
|
+
CURSOR_UP = '\033[1A'
|
12
11
|
|
13
12
|
# Gets a string, makes it bold, returns the string
|
14
13
|
def bolden(self, text: str):
|
15
14
|
text = f'{self.BOLD}{text}{self.NORMAL}'
|
16
15
|
return text
|
17
16
|
|
18
|
-
#
|
19
|
-
|
17
|
+
# Returns current terminal width and height (columns and lines) as a tuple.
|
18
|
+
def get_terminal_size(self):
|
19
|
+
size = shutil.get_terminal_size()
|
20
|
+
x, y = size[0], size[1]
|
21
|
+
return (x, y)
|
22
|
+
|
23
|
+
# Clears a given number of lines in the terminal.
|
24
|
+
# If the specified number of lines is 0 then the current line will be erased.
|
20
25
|
def clear_lines(self, lines: int):
|
21
26
|
if lines == 0:
|
22
27
|
print("\r" + self.CLEAR, end='')
|
23
28
|
return
|
24
29
|
for line in range(lines):
|
25
|
-
print(self.
|
30
|
+
print(self.CLEAR, end=self.CURSOR_UP)
|
26
31
|
|
27
32
|
# Clears current line to print a new one.
|
28
33
|
# Usecase: after typewriter.print_status()
|
@@ -38,7 +43,7 @@ class Typewriter:
|
|
38
43
|
# Prints on the same line
|
39
44
|
def print_progress(self, status: str, current: int, total: int):
|
40
45
|
width = 25
|
41
|
-
progress_float= (current / total)
|
46
|
+
progress_float = (current / total)
|
42
47
|
percent = int(round((progress_float* 100), 0))
|
43
48
|
percent_string = str(percent)
|
44
49
|
if percent < 100:
|
@@ -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=
|
7
|
-
libjam/typewriter.py,sha256=
|
8
|
-
libjam-0.0.
|
9
|
-
libjam-0.0.
|
10
|
-
libjam-0.0.
|
11
|
-
libjam-0.0.
|
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
|