summaryrefslogtreecommitdiffstats
path: root/segment.py
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-07-15 16:44:46 +0800
committerPeng Wu <alexepico@gmail.com>2011-07-15 16:44:46 +0800
commitfe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3 (patch)
tree1ad6db8b71997c918c7cc81b8589721edd947d80 /segment.py
parent61be0be890cba36e4b6915d2a1311c3a946cbb29 (diff)
downloadtrainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.tar.gz
trainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.tar.xz
trainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.zip
begin to write segment.py
Diffstat (limited to 'segment.py')
-rw-r--r--segment.py35
1 files changed, 35 insertions, 0 deletions
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