From fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 15 Jul 2011 16:44:46 +0800 Subject: begin to write segment.py --- segment.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 segment.py (limited to 'segment.py') diff --git a/segment.py b/segment.py new file mode 100644 index 0000000..942a70e --- /dev/null +++ b/segment.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 +import os +import os.path +from subprocess import Popen, PIPE + + +def handleError(error): + sys.exit(error) + +def segmentOneText(infile, outfile): + pass + +def handleOneIndex(indexpath): + indexfile = open(indexpath, 'r') + for oneline in indexfile.readlines(): + (title, textpath) = oneline.split('#') + infile = config.getTextDir() + textpath + outfile = config.getTextDir() + textpath + config.getSegmentPostfix() + print("Processing " + title) + segmentOneText(infile, outfile) + print("Processed "+ title) + indexfile.close() + +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) + if onefile.endswith(config.getIndexPostfix()): + handleOneIndex(filepath) + else: + print('Unexpected file:' + filepath) + + +if __name__ == '__main__': + pass -- cgit