[Tutor] converting all files in a directory with subprocess

Tim Michelsen timmichelsen at gmx-topmail.de
Thu May 8 22:08:00 CEST 2008


Hello,
I am working on a automatic documentation program to convert my txt2tags 
based documentations sources into HTMl files. I want to use txt2tags via 
command line.

Here's my code:

#####

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import fnmatch

documentation_directory = './doc/'

for file in os.listdir(documentation_directory):
     if fnmatch.fnmatch(file, '*.t2t'):
         print file
         subprocess.call('txt2tags', '-t html', '--toc')

##### END ####

When I run the script it exits with the following error message:

#### START OUTPUT ####
python ./make_documentation.py
index.t2t
Traceback (most recent call last):
   File "./make_documentation.py", line 12, in <module>
     subprocess.call('txt2tags', '-t html', '--toc')
   File "/usr/lib/python2.5/subprocess.py", line 444, in call
     return Popen(*popenargs, **kwargs).wait()
   File "/usr/lib/python2.5/subprocess.py", line 545, in __init__
     raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
#### END OUTPUT ####

I am stuck here. Why would the script not let txt2tags convert every 
file in my directory?
like
txt2tags -t html --toc THEFILE

I already tried

subprocess.call('txt2tags', '-t html', '--toc', file)

But without success.

I'd appreciate any pointer here.

Thanks and regards,
Timmie



More information about the Tutor mailing list