o k` @sHddlZddlmZddlmZmZmZddlm Z ddZ ddZ dS) N) Attachment)exception_to_unicodeprinterr unicode_quote)_c Csrtj|jd}tj|sdSt|}tj|js"t|j|d|D] }t|g|Rq)t tj|jdD];\}}}z-t tdrQt ||j t tdrbt |drbt ||jt tdrpt||j|jWq?tyzYq?wztj |d d D] \}}}t|qWdSty} z|jd |t| ttd |t| d WYd} ~ dSd} ~ ww)ziMove attachments from the `attachments` directory into `files`, hashing the filenames in the process. attachmentsNzM SELECT type, id, filename FROM attachment ORDER BY type, id fileschmodchflagsst_flagschownF)topdownz-Can't delete old attachments directory %s: %sauThe upgrade of attachments was successful, but the old attachments directory: %(src_dir)s couldn't be removed, possibly due to the presence of files that weren't referenced in the database. The error was: %(exception)s This error can be ignored, but for keeping your environment clean you should backup any remaining files in that directory and remove it manually. )src_dir exception)ospathjoinexistsstatattachments_dirmakedirsexecutemove_attachment_filewalkhasattrr st_moder r r st_uidst_gidOSErrorrmdirlogwarningrrr) envversioncursorold_attachments_dirold_statrowdirdirsrer+4/usr/lib/python3/dist-packages/trac/upgrades/db28.py do_upgradesD          r-c Cstj|jd|t|}|rtj|t|}tj|}tj|rGt|j|||}z t ||WdSt yFt t d||dw|j d|||dS)NrzEUnable to move attachment from: %(old_path)s to: %(new_path)s )old_pathnew_pathz3Can't find file for 'attachment:%s:%s:%s', ignoring)rrrrnormpathisfiler _get_pathrrenamesrrrr r!)r" parent_realm parent_idfilenamer.r/r+r+r,rIs*    r) os.pathrtrac.attachmentrtrac.util.textrrrtrac.util.translationrr-rr+r+r+r,s    4