-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Noah Kantrowitz skrev 23-06-2008 21:56:
|
| On Jun 23, 2008, at 3:54 PM, Noah Kantrowitz wrote:
|
|>
|> On Jun 23, 2008, at 3:41 PM, Eirik Schwenke wrote:
|>
|>> -----BEGIN PGP SIGNED MESSAGE-----
|>> Hash: SHA1
|>>
|>> Noah Kantrowitz skrev 23-06-2008 16:54:
|>> | On Jun 23, 2008, at 5:28 AM, Jani Tiainen wrote:
|>> |> So I need to do it by hand to all about 60 of my trac configs.. :D
|>> |>
|>> |> I wouldn't say it more "flexible" while upgrading, when creating
|>> new
|>> |> instances it might be more flexible.
|>> |
|>> | for f in `ls /var/trac`
|>> | do
|>> |      echo -e '\n[inherit]\nfile = /usr/share/trac/conf/trac.ini\n'
|>>>> "/
|>> | var/trac/$f"
|>> | done
|>>
|>> Indeed. And I imagine most people running 60 parallel instances of
|>> trac would
|>> have a posix shell available.
|>>
|>> However, does anyone know of a "reasonable" package that would
|>> allow a
|>> similarly short example in python, that remained somewhat portable ?
|>>
|>> I'm not looking for something like ipython, the defunct pysh or
|>> pythonShell --
|>> just some helpful filesystem iterators that aren't quite as verbose
|>> as os.path.*
|>>
|>> Maybe a utility package that would the above be done in some
|>> reasonably
|>> intuitive 5-6 lines of python.
|>>
|>> Any ideas?
|>>
|> Using IPython:
|>
|>   for file in iglob('/var/trac/*/conf/trac.ini'):
|>       open(file, 'a').write('\n[inherit].....')
|
| Apparently the normal glob.glob works fine too here (I just like ipipe
| stuffs).

Hm,

as I just commented off-list to someone else, I guess what I'm really missing
is something like:

import find

for file in find("/var/trac",iname="trac.ini"):
~  with open(file, 'a') as f:
~    f.writelines(["[inherit]", "blah=something"])

(or. better yet, a nice "appendline()/appendlines()"-convenience method on all
file objects that allows for doing the same thing (ie equivalent to the shell
">>" operator):

for file in find("/var/trac",iname="trac.ini"):
~  file.appendlines(["[inherit]", "blah=something"])


But I suppoose the "meme" i was missing was glob and/or os.walk. So coding
"around" the "lack" of a find module:

import os

for root, files, dirs in os.walk("/var/trac"):
~  for file in files:
~    if file.lower() == "trac.ini":
~      with open(os.path.join(root,file), "a") as f:
~        f.writelines(["[inherit]", "blah=something"])


I suppose I can live with glob and os.walk -- but it's a bit painful that
os.walk returns only names as strings, and that there are no "reasonable"
file/path objects (note the main reason that this is necessary is of course the
fact that not all os' agree on path separators and/or 
mountpoints/"driveletters").

Still a python find-module seems like a good (and pretty simple) idea.


Best regards,

- --
~ .---.  Eirik Schwenke <[EMAIL PROTECTED]>
( NSD ) Harald HÃ¥rfagresgate 29            Rom 150
~ '---'  N-5007 Bergen            tlf: (555) 889 13

~  GPG-key at pgp.mit.edu  Id 0x8AA3392C
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIYMaFxUW7FIqjOSwRAv+bAKC+eE+MeLkXa/zISCjXs466B3hsWQCfRCAk
jzk9MU9OJiutQgeRgeAuxNg=
=Hfxa
-----END PGP SIGNATURE-----

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to