Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/knittingneedles.py
1677 views
1
import copy
2
import re
3
4
BOXES = r"^([\s>]*>[\s>]*)"
5
BOX_PREFIX = r"\s*{% raw %}"
6
BOX_OPEN = r"\s*```diff"
7
BOX_CLOSE = r'\s*{: data-commit="([^"]*)"([^}]*)}'
8
BOX_CLOSE_ALL = r'\s*{:\s*(.spoken|data-commit|.code-in\s*data-cmd).*}'
9
WHITESPACE = r"^(\s*)"
10
11
CMD_OPEN = r"\s*```bash"
12
CMD_CLOSE = r'\s*{: data-cmd="true"([^}]*)}'
13
14
TEST_OPEN = r"\s*```bash"
15
TEST_CLOSE = r'\s*{: data-test="true"([^}]*)}'
16
17
18
def stripN(line, count):
19
c = copy.copy(line)
20
for i in range(count):
21
c = c.lstrip()
22
c = c.lstrip(">")
23
removed = len(line) - len(c)
24
return (c, line[0:removed])
25
26
27
def removeWhitespacePrefix(lines):
28
# Obtain whitespace amount
29
whitespace_prefix = [len(re.match(WHITESPACE, line).group(1)) for line in lines]
30
# Remove zeros (blank lines have no whitespace, not even the standard of
31
# the rest)
32
whitespace_prefix = [x for x in whitespace_prefix if x != 0]
33
amount = min(whitespace_prefix)
34
diff = [x[amount:] for x in lines]
35
return (amount, diff)
36
37
38
def extractCommitMsg(lines):
39
return re.match(BOX_CLOSE, lines[-1].strip()).group(1)
40
41