2020from premailer import transform
2121import os
2222import argparse
23- import multiprocessing
23+ import concurrent .futures
24+
25+ def preprocess_html_merge_css (src_path , dst_path ):
26+ with open (src_path , 'r' ) as a_file :
27+ content = transform (a_file .read (), base_url = src_path )
28+ head = os .path .dirname (dst_path )
29+ os .makedirs (head , exist_ok = True )
30+ f = open (dst_path ,"w" )
31+ f .write (content )
2432
2533def main ():
2634
@@ -44,18 +52,16 @@ def main():
4452 tuple = (src_path , dst_path )
4553 paths_list .append (tuple )
4654
47- count = 0
48- for i , tuple in enumerate (paths_list , 1 ):
49- src_path = tuple [0 ]
50- dst_path = tuple [1 ]
51- with open (src_path , 'r' ) as a_file :
52- content = transform (a_file .read (), base_url = src_path )
53- head = os .path .dirname (dst_path )
54- os .makedirs (head , exist_ok = True )
55- f = open (dst_path ,"w" )
56- f .write (content )
57- print ('Processing file: {}/{}' .format (i , len (paths_list )))
58-
55+ with concurrent .futures .ProcessPoolExecutor () as executor :
56+ futures = [ (executor .submit (preprocess_html_merge_css ,
57+ src_path , dst_path ), i )
58+ for i , (src_path , dst_path ) in enumerate (paths_list ) ]
59+
60+ for tuple in futures :
61+ future , i = tuple
62+ future .result ()
63+ print ('Processed file: {}/{}' .format (i , len (paths_list )))
64+
5965if __name__ == "__main__" :
6066 main ()
6167
0 commit comments