run imposm commands from a python script
Question: I'm just getting started using imposm to help get openstreetmap data into a
postgis database. All the docs point to making all commands via Terminal. This
is fine for one off imports but I plan to have many many imports of varying
bounding boxes and would like to script the loading of the data in the
database.

Currently I use:

    
    
    imposm --overwrite-cache --read --write -d postgis_test --user postgres -p ""  /Users/Me/MapnikTest/osmXML.osm
    

Which works fine from the command line but as osmXML.osm is being created many
times I would like somehow to import this at the point of creation.

Putting the same thing in a python script as:

    
    
    os.system("imposm --overwrite-cache --read --write -d postgis_test --user postgres -p ""  /Users/Ali\ Mac\ Pro/Desktop/MapnikTest/osmXML.osm")
    

just returns:

    
    
    /bin/sh: imposm: command not found
    

Solving this would be the final step to automate the acquisition of data to
render small maps on demand but I'm falling at the final hurdle!

** Edit full path to imposm solved the first problem but imputing the password
for the postgres user happens when prompted. Is there a way to send the
password in the same single line command? (maybe this needs to be a new post?,
happy if someone points me in the right direction)**


Answer: This is probably because `os.system()` is calling `/bin/sh` which uses a
different shell environment from the one you use when working on the command
line.

To work around this, in your script, get the full path to the `imposm` script
and then use that in your command. Use can use [some code like
this](http://stackoverflow.com/questions/377017/test-if-executable-exists-in-
python) to find the executable.

Or you can fix your shell definitions so that `/bin/sh` has the proper `PATH`
defined, but that depends greatly on your setup...

