diff options
author | Peng Wu <alexepico@gmail.com> | 2013-01-16 13:06:23 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-01-16 13:06:42 +0800 |
commit | 938a50962f8f4173ca71171532d2d88e9bcfaffa (patch) | |
tree | f7d829fcd50df04fc349dfad819857bebdfabc6a /populatebigram.py | |
parent | 1a6fb6cc5eabf5774738885c4558c519371a67a8 (diff) | |
download | trainer-938a50962f8f4173ca71171532d2d88e9bcfaffa.tar.gz trainer-938a50962f8f4173ca71171532d2d88e9bcfaffa.tar.xz trainer-938a50962f8f4173ca71171532d2d88e9bcfaffa.zip |
switch to walkIndex
Diffstat (limited to 'populatebigram.py')
-rw-r--r-- | populatebigram.py | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/populatebigram.py b/populatebigram.py index cad54ca..a71fe72 100644 --- a/populatebigram.py +++ b/populatebigram.py @@ -5,7 +5,7 @@ import sqlite3 from argparse import ArgumentParser import utils from myconfig import MyConfig - +from dirwalk import walkIndex CREATE_BIGRAM_DDL = ''' CREATE TABLE bigram ( @@ -32,10 +32,6 @@ os.chdir(words_dir) #chdir done -def handleError(error): - sys.exit(error) - - def createBigramSqlite(indexpath, workdir): print(indexpath, workdir, 'create bigram') @@ -116,21 +112,6 @@ def handleOneIndex(indexpath, subdir, indexname): utils.store_status(indexstatuspath, indexstatus) -def walkThroughIndex(path): - for root, dirs, files in os.walk(path, topdown=True, onerror=handleError): - for onefile in files: - filepath = os.path.join(root, onefile) - indexpostfix = config.getIndexPostfix() - if onefile.endswith(indexpostfix): - subdir = os.path.relpath(root, path) - indexname = onefile[:-len(indexpostfix)] - handleOneIndex(filepath, subdir, indexname) - elif onefile.endswith(config.getStatusPostfix()): - pass - else: - print('Unexpected file:' + filepath) - - if __name__ == '__main__': parser = ArgumentParser(description='Populate bi-gram.') parser.add_argument('--indexdir', action='store', \ @@ -139,5 +120,5 @@ if __name__ == '__main__': args = parser.parse_args() print(args) - walkThroughIndex(args.indexdir) + walkIndex(handleOneIndex, args.indexdir) print('done') |