Johannes Radinger wrote:

> maybe someone can help me with the cleanup process in a
> GRASS python script I am writing. The script uses the 
> gparser functionality to get the needed files etc via
> the GUI.
> 
> I also try to include a proper cleanup process within
> the script which deletes all the tmp maps created. This
> should also work if the script stops (e.g due to an error).
> So I think I FIRST need to define all the files which
> should be removed. The problem is that my script includes
> a while loop (iteration) so I can't really say which
> files will be created in advance. How can I define a proper
> cleanup in such cases?

Define a list of map names which starts out empty and has names
appended to it as the names are generated.

E.g.:

        tmp_rast = []
        
        def cleanup():
            for rast in tmp_rast:
                grass.run_command("g.remove", 
                                  rast = rast,
                                  quiet = True)
        
        def main():
            ...
            while ...:
                next_rast = ...
                tmp_rast.append(next_rast)
                ...

        if __name__ == "__main__":
            options, flags = grass.parser()
            atexit.register(cleanup)
            sys.exit(main())

-- 
Glynn Clements <[email protected]>
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to