Add files via upload
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# You are free to use and/or change this code for
|
||||
# your own needs.
|
||||
|
||||
# Original code (c)2018 Jan Lerking
|
||||
# Program to test various scenarios of
|
||||
# single thread, multi thread, pool and process
|
||||
|
||||
import os
|
||||
import sys
|
||||
import multiprocessing
|
||||
import time
|
||||
import magic
|
||||
|
||||
num_cores = multiprocessing.cpu_count()
|
||||
print(num_cores)
|
||||
|
||||
filelist = []
|
||||
|
||||
def sourcedir_filecnt(sourcedir):
|
||||
### Return the number of files, ending with '.h', in sourcedir - including subdirectories ###
|
||||
cnt = 0
|
||||
global filelist
|
||||
for folderName, subfolders, files in os.walk(sourcedir):
|
||||
for file in files:
|
||||
if file.lower().endswith('.h'):
|
||||
cnt += 1
|
||||
filelist += [folderName+'/'+file]
|
||||
print(folderName+'/'+file)
|
||||
#print(filelist)
|
||||
return cnt
|
||||
|
||||
def process_files(sourcedir, destdir):
|
||||
global filelist
|
||||
outfile = ''
|
||||
for f in filelist:
|
||||
inputfile = f
|
||||
blob = open(f).read()
|
||||
m = magic.open(magic.MAGIC_MIME_ENCODING)
|
||||
m.load()
|
||||
encoding = m.buffer(blob) # "utf-8" "us-ascii" etc
|
||||
open(f, encoding=str(encoding))
|
||||
print(os.path.basename(f))
|
||||
for lines in filehandle:
|
||||
print(lines)
|
||||
outfile = outfile+lines
|
||||
fh.close()
|
||||
outputfile = os.path.splitext(inputfile)[0]+'.inc'
|
||||
outputfile = str(outputfile).replace(sourcedir, destdir)
|
||||
print(outputfile)
|
||||
if not os.path.exists(os.path.dirname(outputfile)):
|
||||
try:
|
||||
os.makedirs(os.path.dirname(outputfile))
|
||||
except OSError as exc: # Guard against race condition
|
||||
if exc.errno != errno.EEXIST:
|
||||
raise
|
||||
newfile = open(outputfile, "w")
|
||||
newfile.write(outfile)
|
||||
newfile.close()
|
||||
|
||||
def single_thread():
|
||||
t1 = time.time()
|
||||
sourcedir_filecnt(sourcedir)
|
||||
process_files(sourcedir, destdir)
|
||||
print('Single thread process time: '+str(time.time()-t1))
|
||||
|
||||
sourcedir = 'C:/Users/dksojlg/Documents/gtk+-3.22.26'
|
||||
destdir = 'C:/Users/dksojlg/Documents/include'
|
||||
|
||||
single_thread()
|
||||
Reference in New Issue
Block a user