Skip to content

Commit c6b6bbe

Browse files
committed
added parsing for all labels in the project
1 parent 9a4726b commit c6b6bbe

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

RTE/models/labels.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Label:
2+
def __init__(self, name, linenum, fname):
3+
self.name = name
4+
self.linenum = linenum
5+
self.filename = fname

RTE/models/project.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import git
22
import os
3+
import re
4+
import glob
5+
from .labels import Label
36

47
class Project:
58
def __init__(self, path):
@@ -10,8 +13,28 @@ def __init__(self, path):
1013
self.notes = f.read()
1114
else:
1215
self.notes = ""
16+
17+
self.labels = self.get_all_labels()
1318
pass
1419

1520
def save_notes(self):
1621
with open(os.path.join(self.path, ".rte-notes"), "w") as f:
1722
f.write(self.notes)
23+
24+
def get_all_labels(self):
25+
label_re = re.compile(r'(label) (\S+) ?:')
26+
labels = []
27+
for filename in self.get_all_files("rpy"):
28+
path = os.path.join(self.path, filename)
29+
with open(path, "r") as f:
30+
for i, line in enumerate(f):
31+
match = label_re.match(line)
32+
if match:
33+
labels.append(Label(match.group(2), i, path))
34+
return labels
35+
36+
def get_all_files(self, ext="rpy"):
37+
rv = []
38+
for filename in glob.iglob(os.path.join(self.path, f'**/*.{ext}'), recursive=True):
39+
rv.append(filename)
40+
return rv

config/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"wm_width": 1597,
3-
"wm_height": 752,
2+
"wm_width": 1270,
3+
"wm_height": 575,
44
"theme_name": "monokai",
55
"insert_spaces_instead_of_tabs": true,
66
"tabs_length": 4,
@@ -9,6 +9,6 @@
99
"start_maximized": false,
1010
"locale": "en-US",
1111
"path_to_git": "",
12-
"side_notebook_width": 200,
13-
"scrollbar_width": 20
12+
"side_notebook_width": 200
13+
} "scrollbar_width": 20
1414
}

0 commit comments

Comments
 (0)