On Monday 7. October 2013 14.48.19 Philip Colmer wrote: > >> The MoinMoin.action.AttachFile module contains functions to work > >> with attachments in a nicer way than manipulating the filesystem > >> directly. > > Is there any documentation on how to programmatically attach a file to a > page? I can only see documentation for checking if an attachment exists and > getting the directory path and URL for a page.
Having suggested AttachFile as a way of adding attachments, I just looked at some code that I know adds attachments programmatically - the graphviz parser [1] - and it appears that it uses AttachFile only to discover the directory of attachments for a page. Here's what it does (edited slightly): # Use the request to create or obtain the directory for a given page. attach_dir = AttachFile.getAttachDir(request, page_name, create=1) # Obtain the pathname for the given leafname in the directory. pathname = join(attach_dir, leafname).encode(config.charset) After this, the extension just writes to the file with the given pathname (or rather it gets graphviz to do so). Looking inside the MoinMoin.action.AttachFile module, I see that the add_attachment function does more or less the same thing, but it also adds an entry to the history which might not be something the graphviz parser would want to do (since it is just using the attachments as temporary storage for generated images that can be shown conveniently by Moin). So, maybe add_attachment is what you want unless you don't want to add history entries to the edit log, in which case doing only some of what that function does (as described above) is probably satisfactory. And if you're doing this kind of thing from outside Moin and are just looking to import attachments in "batch" mode, you could instead use the page package infrastructure [2], but I'll leave that for another message if you're interested in that. Paul [1] http://moinmo.in/ParserMarket/graphviz [2] http://moinmo.in/HelpOnPackageInstaller ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk _______________________________________________ Moin-user mailing list Moin-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/moin-user