Modify

Opened 14 years ago

Last modified 6 years ago

#6299 new enhancement

Doesn't import the attachments for a page

Reported by: srevill@… Owned by: Tristan Rivoallan
Priority: normal Component: WikiImportPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

The reason I installed this plugin was to save me from manually importing the very many image attachments we have on a number of tutorial wiki pages. Sadly, this plugin only imports wiki pages and none of their attachments. I could've done that manually in the time it took to install the plugin :(

Any chance this feature could be added? Something along these lines would do it for a single file...

import os
from trac.attachment import Attachment
from trac.admin.console import TracAdmin

wikidir = r'C:\Path\To\My\TracProject'

admin = TracAdmin()
admin.env_set(wikidir)

filename = r'c:\Path\To\My\Images\2_0.jpg'

attachment = Attachment(admin.env_open(), 'wiki', 'tutorials/page1')

size = os.stat(filename)[6]
attfile = open(filename,'rb')

attachment.insert(os.path.basename(filename), attfile, size)

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by solstice333

Is this still an open enhancement? I was hoping for the same feature as well...

Last edited 6 years ago by solstice333 (previous) (diff)

comment:2 Changed 6 years ago by solstice333

What I ended up doing as a workaround was copying the files/attachments/wiki folder from the trac project source into the same relative path in the trac project destination. Then I went into the source trac project's db folder and did a sqlite3 trac.db. I exported out the attachment entries I was interested in using

sqlite> .mode csv
sqlite> .output foo.csv
sqlite> SELECT ... FROM attachment WHERE ...

where ... is replaced with what I actually needed it to be.

I then invoked sqlite3 trac.db in the trac project destination db folder, and ran

sqlite> .mode csv
sqlite> .import path/to/foo.csv attachment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Tristan Rivoallan.

Add Comment


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

 
Note: See TracTickets for help on using tickets.