Skip to content

Commit 48aab6a

Browse files
committed
Preproces: move reusable functions to separate file
1 parent 33c784e commit 48aab6a

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

commands/preprocess_cssless.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (C) 2018 Monika Kairaityte <monika@kibit.lt>
2+
#
3+
# This file is part of cppreference-doc
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see http://www.gnu.org/licenses/.
17+
18+
from premailer import transform
19+
import cssutils
20+
import logging
21+
import os
22+
import warnings
23+
import io
24+
25+
def preprocess_html_merge_css(src_path, dst_path):
26+
log = logging.Logger('ignore')
27+
output = io.StringIO()
28+
handler = logging.StreamHandler(stream=output)
29+
formatter = logging.Formatter('%(levelname)s, %(message)s')
30+
handler.setFormatter(formatter)
31+
log.addHandler(handler)
32+
cssutils.log.setLog(log)
33+
34+
with open(src_path, 'r') as a_file:
35+
with warnings.catch_warnings():
36+
warnings.simplefilter("ignore")
37+
content = transform(a_file.read(), base_url=src_path)
38+
head = os.path.dirname(dst_path)
39+
os.makedirs(head, exist_ok=True)
40+
f = open(dst_path,"w")
41+
f.write(content)
42+
43+
return output.getvalue()

preprocess_qch.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,12 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with this program. If not, see http://www.gnu.org/licenses/.
1919

20-
from premailer import transform
20+
from commands.preprocess_cssless import *
2121
import argparse
2222
import concurrent.futures
23-
import cssutils
24-
import logging
2523
import os
26-
import warnings
27-
import io
2824
import shutil
2925

30-
def preprocess_html_merge_css(src_path, dst_path):
31-
log = logging.Logger('ignore')
32-
output = io.StringIO()
33-
handler = logging.StreamHandler(stream=output)
34-
formatter = logging.Formatter('%(levelname)s, %(message)s')
35-
handler.setFormatter(formatter)
36-
log.addHandler(handler)
37-
cssutils.log.setLog(log)
38-
39-
with open(src_path, 'r') as a_file:
40-
with warnings.catch_warnings():
41-
warnings.simplefilter("ignore")
42-
content = transform(a_file.read(), base_url=src_path)
43-
head = os.path.dirname(dst_path)
44-
os.makedirs(head, exist_ok=True)
45-
f = open(dst_path,"w")
46-
f.write(content)
47-
48-
return output.getvalue()
49-
5026
def main():
5127

5228
parser = argparse.ArgumentParser(prog='preprocess_qch.py')

0 commit comments

Comments
 (0)