#NEWLINE# def make_index_for( package , index_dir , verbose = True ) : #NEWLINE# #INDENT# "\n    Create an 'index.html' for one package.\n\n    :param package:   Package object to use.\n    :param index_dir: Where 'index.html' should be created.\n    " #NEWLINE# index_template = '<html>\n<head><title>{title}</title></head>\n<body>\n<h1>{title}</h1>\n<ul>\n{packages}\n</ul>\n</body>\n</html>\n' #NEWLINE# item_template = '<li><a href="{1}">{0}</a></li>' #NEWLINE# index_filename = os . path . join ( index_dir , 'index.html' ) #NEWLINE# if ( not os . path . isdir ( index_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( index_dir ) #NEWLINE# #UNINDENT# parts = [ ] #NEWLINE# for pkg_filename in package . files : #NEWLINE# #INDENT# pkg_name = os . path . basename ( pkg_filename ) #NEWLINE# if ( pkg_name == 'index.html' ) : #NEWLINE# #INDENT# pkg_name = os . path . basename ( os . path . dirname ( pkg_filename ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pkg_name = package . make_pkgname_with_version ( pkg_filename ) #NEWLINE# #UNINDENT# pkg_relpath_to = os . path . relpath ( pkg_filename , index_dir ) #NEWLINE# parts . append ( item_template . format ( pkg_name , pkg_relpath_to ) ) #NEWLINE# #UNINDENT# if ( not parts ) : #NEWLINE# #INDENT# print ( ( 'OOPS: Package %s has no files' % package . name ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if verbose : #NEWLINE# #INDENT# root_index = ( not Package . isa ( index_dir . files [ 0 ] ) ) #NEWLINE# if root_index : #NEWLINE# #INDENT# info = ( 'with %d package(s)' % len ( package . files ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# package_versions = sorted ( set ( package . versions ) ) #NEWLINE# info = ', ' . join ( reversed ( package_versions ) ) #NEWLINE# #UNINDENT# message = ( '%-30s  %s' % ( package . name , info ) ) #NEWLINE# print ( message ) #NEWLINE# #UNINDENT# with open ( index_filename , 'w' ) as f : #NEWLINE# #INDENT# packages = '\n' . join ( parts ) #NEWLINE# text = index_template . format ( title = package . name , packages = packages ) #NEWLINE# f . write ( text . strip ( ) ) #NEWLINE# f . close ( )