Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Simmons <jim@simmons.olpc>2009-09-06 22:17:00 (GMT)
committer James Simmons <jim@simmons.olpc>2009-09-06 22:17:00 (GMT)
commit73e671a6ce86308d61b95264953aa79d63d30cdc (patch)
treefbe0a938db9609d4771aec3733540c13bf727907
parent95a1ab0f394bb41b3e3aa9eeb9b4dd02ce78ba0d (diff)
modified: ReadEtextsActivity.pyv17
modified: rtfconvert.py Support conversion of RTF documents.
-rw-r--r--ReadEtextsActivity.py9
-rwxr-xr-xrtfconvert.py21
2 files changed, 27 insertions, 3 deletions
diff --git a/ReadEtextsActivity.py b/ReadEtextsActivity.py
index c40ec76..f77184d 100644
--- a/ReadEtextsActivity.py
+++ b/ReadEtextsActivity.py
@@ -41,6 +41,7 @@ import cPickle as pickle
import speech
import xopower
+import rtfconvert
PAGE_SIZE = 38
TOOLBAR_READ = 2
@@ -796,6 +797,14 @@ class ReadEtextsActivity(activity.Activity):
i = i + 1
else:
current_file_name = filename
+
+ if rtfconvert.check(current_file_name):
+ converted_file_name = os.path.join(self.get_activity_root(), 'instance',
+ 'convert%i' % time.time())
+ rtfconvert.convert(current_file_name, converted_file_name)
+ os.remove(current_file_name)
+ current_file_name = converted_file_name
+ self.tempfile = converted_file_name
self.etext_file = open(current_file_name,"r")
diff --git a/rtfconvert.py b/rtfconvert.py
index 8b61cb1..2e875f0 100755
--- a/rtfconvert.py
+++ b/rtfconvert.py
@@ -21,10 +21,21 @@ import sys
# This is a script to take the a file in RTF format and convert it to a text file readable by Read Etexts.
-def convert(file_path):
+def check(file_path):
rtf_file = open(file_path,"r")
- out = open("book.txt", 'w')
+ line = rtf_file.readline()
+ rtf_file.close()
+
+ if line.startswith('{\\rtf1'):
+ return True
+ else:
+ return False
+
+def convert(file_path, output_path):
+
+ rtf_file = open(file_path,"r")
+ out = open(output_path, 'w')
brace_count = 0
while rtf_file:
@@ -78,7 +89,11 @@ def count_braces(string):
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "")
- convert(args[0])
+ if check(args[0]):
+ print 'It is an RTF file'
+ convert(args[0], args[1])
+ else:
+ print 'It is NOT an RTF file'
except getopt.error, msg:
print msg
print "This program has no options"