#NEWLINE# def _create_index_file( root_dir , location , image_files , dirs , force_no_processing = False ) : #NEWLINE# #INDENT# "\n    Create an index file in the given location, supplying known lists of\n    present image files and subdirectories.\n\n    @param {String} root_dir - The root directory of the entire crawl. Used to\n        ascertain whether the given location is the top level.\n\n    @param {String} location - The current directory of the crawl. The index\n        file will be created here.\n\n    @param {[String]} image_files - A list of image file names in the location.\n        These will be displayed in the index file's gallery.\n\n    @param {[String]} dirs - The subdirectories of the location directory.\n        These will be displayed as links further down the file structure.\n\n    @param {Boolean=False} force_no_processing - If True, do not attempt to\n        actually process thumbnails, PIL images or anything. Simply index\n        <img> tags with original file src attributes.\n\n    @return {String} The full path (location plus filename) of the newly\n        created index file. Intended for usage cleaning up created files.\n    " #NEWLINE# header_text = ( ( ( ( 'imageMe: ' + location ) + ' [' ) + str ( len ( image_files ) ) ) + ' image(s)]' ) #NEWLINE# html = [ '<!DOCTYPE html>' , '<html>' , '    <head>' , '        <title>imageMe</title>        <style>' , '            html, body {margin: 0;padding: 0;}' , '            .header {text-align: right;}' , '            .content {' , '                padding: 3em;' , '                padding-left: 4em;' , '                padding-right: 4em;' , '            }' , '            .image {max-width: 100%; border-radius: 0.3em;}' , ( ( '            td {width: ' + str ( ( 100.0 / IMAGES_PER_ROW ) ) ) + '%;}' ) , '        </style>' , '    </head>' , '    <body>' , '    <div class="content">' , ( ( '        <h2 class="header">' + header_text ) + '</h2>' ) ] #NEWLINE# directories = [ ] #NEWLINE# if ( root_dir != location ) : #NEWLINE# #INDENT# directories = [ '..' ] #NEWLINE# #UNINDENT# directories += dirs #NEWLINE# if ( len ( directories ) > 0 ) : #NEWLINE# #INDENT# html . append ( '<hr>' ) #NEWLINE# #UNINDENT# for directory in directories : #NEWLINE# #INDENT# link = ( ( directory + '/' ) + INDEX_FILE_NAME ) #NEWLINE# html += [ '    <h3 class="header">' , ( ( ( ( '    <a href="' + link ) + '">' ) + directory ) + '</a>' ) , '    </h3>' ] #NEWLINE# #UNINDENT# table_row_count = 1 #NEWLINE# html += [ '<hr>' , '<table>' ] #NEWLINE# for image_file in image_files : #NEWLINE# #INDENT# if ( image_file == 1 ) : #NEWLINE# #INDENT# html . append ( '<tr>' ) #NEWLINE# #UNINDENT# img_src = _get_thumbnail_src_from_file ( location , image_file , force_no_processing ) #NEWLINE# link_target = _get_image_link_target_from_file ( location , image_file , force_no_processing ) #NEWLINE# html += [ '    <td>' , ( ( '    <a href="' + link_target ) + '">' ) , ( ( '        <img class="image" src="' + img_src ) + '">' ) , '    </a>' , '    </td>' ] #NEWLINE# if ( table_row_count == IMAGES_PER_ROW ) : #NEWLINE# #INDENT# table_row_count = 0 #NEWLINE# html . append ( '</tr>' ) #NEWLINE# #UNINDENT# table_row_count += 1 #NEWLINE# #UNINDENT# html += [ '</tr>' , '</table>' ] #NEWLINE# html += [ '    </div>' , '    </body>' , '</html>' ] #NEWLINE# index_file_path = _get_index_file_path ( location ) #NEWLINE# print ( ( 'Creating index file %s' % index_file_path ) ) #NEWLINE# index_file = open ( index_file_path , 'w' ) #NEWLINE# index_file . write ( '\n' . join ( html ) ) #NEWLINE# index_file . close ( ) #NEWLINE# return index_file_path