[PyQt] Copying Directory structure from a template one

Patrick Boucher pboucher at patrickboucher.com
Wed Apr 8 17:44:37 BST 2009


This answer may or may not be useful to you because what I'm
suggesting is an alternative route but still... Up to you to decide.

I have to do this 'create a dir structure from template' regularly in
my line of work and the solution I've come to like a lot is to use a
template file in the form of an xml dialect that could look somewhat
like follows:

<dir name="foo">
  <dir name="bar" />
  <dir name="flip">
    <dir name="flop" />
  </dir>
</dir>

You can then walk this xml node structure creating the directories as you go.
This can be extended to support tag replacement in name attributes
(name="[specialComputedValue]_dir"), <file /> nodes, a chmod="0755"
attribute for permissions or even an include system whereby you can
nest templates in each other.

Eventually if the people maintaining these templates aren't xml savvy
you can build a template editor in Qt with a QTreeWidget (or View)
that exposes all the nifty features of your dialect.

You can have multiple templates and if needed you could even copy the
template into the directory structure itself as a hidden file or in a
hidden directory, a bit like a .svn directory. It all depends where
you're going with this.

Hope this can give you a few ideas...

Cheers,
Patrick



On Wed, Apr 8, 2009 at 10:52 AM, F.A. Pinkse <fapinkse at gmail.com> wrote:
> Hello All,
>
> For very new job in my CAD work I make a copy of an old Job Directory
> structure and rename the directories/files as needed by hand.
> Finally I decided to throw Python at it.
> I hard coded the structure, but I felt I could do better, like copying a
> template and do a rename in the process.
> But somehow I got stuck.
>
> Here is what I did so far.
>
> Used the QDirModel(), giving me the whole file system.
> Using filters will narrow this down, right?
> I can do a .hasChildren(), but I fail on the . findChildren() bit which is
> needed for navigation, I think.
>
>
> Has anyone a good source of examples on this.
>
> Thanks,
>
>
> Frans.
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list