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> (大前 潤)