Opened 10 years ago

Closed 9 years ago

#1426 closed defect (fixed)

os.listdir gives error if directories do not exist

Reported by: marius2@… Owned by: kgk
Priority: normal Component: MoinToTracScript
Severity: normal Keywords:
Cc: Trac Release: 0.10


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) (2.6 KB) - added by anonymous 10 years ago.
moin2trac-tkt1426.patch (1.6 KB) - added by baby 9 years ago.
Same solution as above, only in 'patch' format :-)

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by anonymous

comment:1 Changed 10 years ago by anonymous

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

comment:2 Changed 9 years ago by baby

Maybe if I send the latest modifications here as a patch you can directly apply to the repository it will get applied?

Changed 9 years ago by baby

Same solution as above, only in 'patch' format :-)

comment:3 Changed 9 years ago by kgk

  • Resolution set to fixed
  • Status changed from new to closed

Applied patch in r3395

Add Comment

Modify Ticket

as closed The owner will remain kgk.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.