summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xevaluate.py4
-rwxr-xr-xgenerate.py5
-rw-r--r--lib/utils.py5
-rwxr-xr-xtryprune.py7
4 files changed, 11 insertions, 10 deletions
diff --git a/evaluate.py b/evaluate.py
index 3485ace..e83eb22 100755
--- a/evaluate.py
+++ b/evaluate.py
@@ -1,7 +1,6 @@
#!/usr/bin/python3
import os
import os.path
-import shutil
import sys
from subprocess import Popen, PIPE
from argparse import ArgumentParser
@@ -148,8 +147,7 @@ if __name__ == '__main__':
destfile = os.path.join(libpinyin_dir, 'data', \
config.getFinalModelFileName())
- print('copying from ' + modelfile + ' to ' + destfile)
- shutil.copyfile(modelfile, destfile)
+ utils.copyfile(modelfile, destfile)
print('cleaning')
cleanUpData()
diff --git a/generate.py b/generate.py
index 9862734..58c4d80 100755
--- a/generate.py
+++ b/generate.py
@@ -2,7 +2,6 @@
import os
import os.path
import sys
-import shutil
from subprocess import Popen, PIPE
from argparse import ArgumentParser
import utils
@@ -83,9 +82,9 @@ def handleOneIndex(indexpath, subdir, indexname, fast):
reportfile = modelfile + config.getReportPostfix()
if os.access(inmemoryfile, os.F_OK):
- shutil.copyfile(inmemoryfile, modelfile)
+ utils.copyfile(inmemoryfile, modelfile)
if os.access(inmemoryreportfile, os.F_OK):
- shutil.copyfile(inmemoryreportfile, reportfile)
+ utils.copyfile(inmemoryreportfile, reportfile)
def cleanupFiles(modelnum):
modeldir = os.path.join(config.getModelDir(), subdir, indexname)
diff --git a/lib/utils.py b/lib/utils.py
index a0d23a1..e734ee9 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1,6 +1,7 @@
import io
import os
import json
+import shutil
from myconfig import MyConfig
@@ -40,6 +41,10 @@ def get_file_length(infile):
f.close()
return length
+def copyfile(src, dst):
+ print('copying from ' + src + ' to ' + dst)
+ shutil.copyfile(src, dst)
+
#JSON Load/Store
def load_status(infile):
diff --git a/tryprune.py b/tryprune.py
index f181a70..27cf69d 100755
--- a/tryprune.py
+++ b/tryprune.py
@@ -1,7 +1,6 @@
#!/usr/bin/python3
import os
import os.path
-import shutil
import sys
from subprocess import Popen, PIPE
from argparse import ArgumentParser
@@ -200,13 +199,13 @@ if __name__ == '__main__':
if os.access(shmmodel, os.F_OK):
os.unlink(shmmodel)
#copy to memory
- shutil.copyfile(mergedmodel, shmmodel)
+ utils.copyfile(mergedmodel, shmmodel)
pruneModel(shmmodel, args.k, args.CDF)
#copy to filesystem
- shutil.copyfile(shmmodel, prunedmodel)
+ utils.copyfile(shmmodel, prunedmodel)
else:
#backup merged model
- shutil.copyfile(mergedmodel, prunedmodel)
+ utils.copyfile(mergedmodel, prunedmodel)
pruneModel(prunedmodel, args.k, args.CDF)
#validate pruned model