forked from adamchainz/google_lifelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
33 lines (26 loc) · 789 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding=utf-8
import re
import sys
import subprocess
from terminal_colours import *
from django.utils.encoding import smart_str
def say(string):
sys.stdout.write(smart_str(string))
sys.stdout.flush()
def run(comm, with_stderr=False):
proc = subprocess.Popen(comm,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = proc.communicate()
if with_stderr:
# Concat stdout & stderr, because we don't care
return output[0] + "\n" + output[1]
else:
return output[0]
def format_tags(str):
def tag_highlight(match):
return header(match.group(0))
return re.sub(r'\#\w+\b',
tag_highlight,
str,
flags=re.MULTILINE)