Opened 18 years ago
Closed 17 years ago
#1426 closed defect (fixed)
os.listdir gives error if directories do not exist
Reported by: | Owned by: | Kristian Kvilekval | |
---|---|---|---|
Priority: | normal | Component: | MoinToTracScript |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.10 |
Description
First thanks for the script, after a few modifications it gave good results for me.
On first use I got errors from os.listdir because the directories it tried to list (revisions and attachments) don't exist for all pages. The script ended therefore with an error. After adding two lines:
admin = trac.scripts.admin.TracAdmin() admin.env_set (wikidir) revdir = moindir + '/' + page + '/revisions' if os.path.exists(revdir):
revisions = os.listdir(revdir) for rev in revisions:
cmd='wiki import %s %s' % ( page, revdir +'/'+rev) print cmd, "->", wikidir admin.onecmd(cmd)
# Process attachments attdir = moindir + '/' + page + '/attachments' if os.path.exists(attdir):
attachments = os.listdir(attdir) for att in attachments:
attachment = Attachment(admin.env_open(), 'wiki', page) size = os.stat(attdir + '/'+ att)[6] print "attaching " + att + ' = ' + str(size) attfile = open (attdir + '/'+ att) attachment.insert (att, attfile, size)
(the boldfaced lines), it worked fine. regards, Marius de Vink
Attachments (2)
Change History (5)
Changed 18 years ago by
Attachment: | mointotracscript.zip added |
---|
comment:1 Changed 18 years ago by
comment:2 Changed 17 years ago by
Maybe if I send the latest modifications here as a patch you can directly apply to the repository it will get applied?
Changed 17 years ago by
Attachment: | moin2trac-tkt1426.patch added |
---|
Same solution as above, only in 'patch' format :-)
I added a new zip file to solve the problem Marius already had and solved. I solved it on a different way, but i worked for me. I added "if os.access(revdir, os.F_OK):" instead of "if os.path.exists(revdir):". Would one please add it to the mainpage, so that every user use the old one. Thanks