Exemple #1
0
def run():
    usage = """usage: %prog INFILE OUTFILE

This program changes the number of spaces between sentences from 1 to 2 in
a Open Document Word Processing *.odt file.
    """

    parser = OptionParser(usage)
# @todo?
    #parser.add_option("-s", "--styles", dest="styles",
            #help="Comma delimited set of text style-names\nDefaults to 'Default'")
    options, args = parser.parse_args()

    if len(args) != 2:
        parser.error("Incorrect number of arguments; please supply file to convert from and to.")
    if not os.path.exists(args[0]):
        parser.error("Input file does not exist.")

    with UnZip(args[0]) as zip_content_dir:
        respacer = Respace(zip_content_dir)
        with open(os.path.join(zip_content_dir, 'content.new.xml'), 'w') as newcontent:
            newcontent.write(respacer.run())
        os.rename(os.path.join(zip_content_dir, 'content.new.xml'),
                os.path.join(zip_content_dir, 'content.xml'))
# prevent overwriting a file that isn't closed yet
        if args[0] == args[1]:
            zipper = Zip(zip_content_dir, args[1] + '.temp')
            zipper.zip()
        else:
            zipper = Zip(zip_content_dir, args[1])
            zipper.zip()

    if args[0] == args[1]:
        os.rename(args[1] + '.temp', args[1])
Exemple #2
0
 def testRespaceDefault1_2(self):
     test_file = os.path.join(tests_dir, 'data',
             'lorem_ipsum_oo_3.1.1_odf_1.2.odt')
     with UnZip(test_file) as zip_content_dir:
         respacer = Respace(zip_content_dir)
         respaced_content = respacer.run()
         self.assertEqual(respaced_content.count('<text:s/>'), 74)