<s> from __future__ import unicode_literals <EOL> import frappe <EOL> from frappe . model . meta import is_single <EOL> def execute ( ) : <EOL> """<STR_LIT>""" <EOL> fix_file_urls ( ) <EOL> fix_attach_field_urls ( ) <EOL> def fix_file_urls ( ) : <EOL> for file in frappe . db . sql_list ( """<STR_LIT>""" ) : <EOL> file = frappe . get_doc ( "<STR_LIT>" , file ) <EOL> file . db_set ( "<STR_LIT>" , "<STR_LIT:/>" + file . file_url , update_modified = False ) <EOL> try : <EOL> file . validate_file ( ) <EOL> file . db_set ( "<STR_LIT>" , file . file_name , update_modified = False ) <EOL> if not file . content_hash : <EOL> file . generate_content_hash ( ) <EOL> file . db_set ( "<STR_LIT>" , file . content_hash , update_modified = False ) <EOL> except IOError : <EOL> pass <EOL> def fix_attach_field_urls ( ) : <EOL> attach_fields = ( frappe . db . sql ( """<STR_LIT>""" ) + <EOL> frappe . db . sql ( """<STR_LIT>""" ) ) <EOL> for doctype , fieldname in attach_fields : <EOL> if is_single ( doctype ) : <EOL> frappe . db . sql ( """<STR_LIT>""" , { "<STR_LIT>" : doctype , "<STR_LIT>" : fieldname } ) <EOL> else : <EOL> frappe . db . sql ( """<STR_LIT>""" . format ( doctype = doctype , fieldname = fieldname ) ) </s>
