Modify

Opened 17 years ago

Closed 16 years ago

#1426 closed defect (fixed)

os.listdir gives error if directories do not exist

Reported by: marius2@… 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)

mointotracscript.zip (2.6 KB) - added by anonymous 17 years ago.
moin2trac-tkt1426.patch (1.6 KB) - added by Mariano Absatz 17 years ago.
Same solution as above, only in 'patch' format :-)

Download all attachments as: .zip

Change History (5)

Changed 17 years ago by anonymous

Attachment: mointotracscript.zip added

comment:1 Changed 17 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 17 years ago by Mariano Absatz

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 Mariano Absatz

Attachment: moin2trac-tkt1426.patch added

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

comment:3 Changed 16 years ago by Kristian Kvilekval

Resolution: fixed
Status: newclosed

Applied patch in r3395

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Kristian Kvilekval.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.