#!/usr/bin/env python

"""
Create a index.html file, so when we go to this directory with a
browser we see the list of binaries available.
"""

import os
import time

# Directory with the binary files.
BIN_DIR = os.path.dirname(os.path.realpath(__file__))
# It is the directory where this script exists!


with open('%s/index.html' % BIN_DIR, 'w') as f:
    f.write("""<!DOCTYPE html>
<html>
<head>
  <title>Scipion Binary Releases</title>
</head>
<body>

<!-- Autogenerated file, if you edit it, it may be overwritten.
     Don't say you were not warned :) -->

<p><a href="http://scipionwiki.cnb.csic.es">Scipion</a> binary releases.</p>

<ul>
""")
    for fname in sorted(os.listdir(BIN_DIR), reverse=True):
        # If we wanted to sort by date: os.stat(fname).st_mtime
        if fname.endswith('.tgz'):
            f.write('<li> <a href="%s">%s</a> </li>\n' % (fname, fname))

    f.write("""</ul>

<p>Last generated: %s</p>

</body>
</html>
""" % time.asctime())
