Downloading all attachments

22 views
Skip to first unread message

Wätzold Plaum

unread,
Oct 23, 2024, 12:01:43 PM10/23/24
to Trac Users
Hi,
I want to backup all Attachments in a way that they can be linked to the tickets. I can download the attachments-folder, but there we have some kind of md5-hash encryption. The attachments tabel contains the clear names. Any attempt to encode the file name of the attachment to md5 or sh1 failed. 

Any idea how to get all the attachments with clear names?

I'm running track-admin 1.2.6

Best Regards,
Wätzold

Jun Omae

unread,
Oct 23, 2024, 2:38:15 PM10/23/24
to trac-...@googlegroups.com
See `Attachment._get_path()` at https://trac.edgewall.org/browser/tags/trac-1.2.6/trac/attachment.py#L727

[[[
import os, sys
from trac.env import Environment
from trac.attachment import Attachment

def main(args):
if not args:
sys.stderr.write('Usage: %s envpaths\n' % sys.argv[0])
sys.exit(1)
for arg in args:
env = Environment(arg)
list_attachments(env)
env.shutdown()

if hasattr(Environment, 'attachments_dir'):
get_attachments_dir = lambda env: env.attachments_dir
else:
get_attachments_dir = lambda env: \
os.path.join(os.path.normpath(env.path), 'files', 'attachments')

def list_attachments(env):
out = sys.stdout
if hasattr(out, 'buffer'):
out = out.buffer
attachments_dir = get_attachments_dir(env)
with env.db_query as db:
cursor = db.cursor()
cursor.execute('SELECT type, id, filename FROM attachment '
'ORDER BY type, id')
for type_, id_, filename in cursor:
local_path = Attachment._get_path(attachments_dir, type_, id_,
filename)
line = u'\t'.join([type_, id_, filename, local_path]) + u'\n'
out.write(line.encode('utf-8'))

if __name__ == '__main__':
main(sys.argv[1:])
]]]

--
Jun Omae <jun...@gmail.com> (大前 潤)

Clemens Feige

unread,
Oct 31, 2024, 4:09:28 AM10/31/24
to trac-...@googlegroups.com
Hello

Maybe you can utilize the "AllAttachmentsMacro".

https://trac-hacks.org/wiki/AllAttachmentsMacro
Quote:
> This is a wiki macro that can be used to show all attachments uploaded on a Trac site. The attachments are displayed as a list of filenames, showing filesize, author and the source of the attachment (wikipage or ticket).

For mass downloading you could then use a browser tool like "DownThemAll":

https://www.downthemall.net/

Clemens
Reply all
Reply to author
Forward
0 new messages