-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzip-turbo.py
45 lines (29 loc) · 1020 Bytes
/
gzip-turbo.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
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import sys
import subprocess as sp
import multiprocessing
import concurrent.futures
import re
import glob
#compresses files in a folder in parallel
#gzip-turbo.py files.list gzipfiles/ 24
def tokenize(filename):
digits = re.compile(r'(\d+)')
return tuple(int(token) if match else token for token, match in ((fragment, digits.search(fragment)) for fragment in digits.split(filename)))
def gzturbo(i):
print('gzipping',i)
name1=i.split("/")[-1]
p0=sp.Popen("gzip -c %s >%s/%s" %(i,outfolder,name1+".gz"),shell=True).wait()
f=open(sys.argv[1],'r')
filelist=[]
for x in f:
filelist.append(x.rstrip("\n"))
outfolder = sys.argv[2] #outfolder
p1=sp.Popen("mkdir -p %s" %outfolder,shell=True).wait()
threads=int(sys.argv[3])
if __name__ == '__main__':
print("gzipping..",threads,"threads")
executor1 = concurrent.futures.ProcessPoolExecutor(threads)
futures1 = [executor1.submit(gzturbo,i) for i in filelist]
concurrent.futures.wait(futures1)
print("gzip-turbo completed")