#!/usr/bin/env python

import os
import sys
import time

from distutils.core import setup

NAME =               'bionet.utils'
VERSION =            '0.015'
IS_RELEASED =        True
AUTHOR =             'Lev Givon'
AUTHOR_EMAIL =       'lev@columbia.edu'
URL =                'http://bionet.ee.columbia.edu/code/'
MAINTAINER =         'Lev Givon'
MAINTAINER_EMAIL =   'lev@columbia.edu'
DESCRIPTION =        'Bionet utilities'
DOWNLOAD_URL =       URL
LICENSE =            'BSD'
CLASSIFIERS = [
    'Development Status :: 4 - Beta',
    'Intended Audience :: Developers',
    'Intended Audience :: Science/Research',
    'License :: OSI Approved :: BSD License',
    'Operating System :: OS Independent',
    'Programming Language :: Python',
    'Topic :: Scientific/Engineering',
    'Topic :: Software Development']

def get_version(version, is_released=True):

    full_version = version
    if not is_released and os.path.exists('.hg'):

        # Do not read any config file when running mercurial:
        os.environ['HGRCPATH'] = '' 
        cmd = '%s /usr/bin/hg id -it' % sys.executable

        try:
            l = os.popen(cmd).read().split()
        except OSError, e:
            print "warning: could not determine version: %s" % e

        # Toss non-numbered tags:
        while len(l) > 1 and l[-1][0].isalpha(): 
            l.pop()
        if l:

            # Get the latest tag or revision number:
            version = l[-1] 

            # Append the current time if the source code has been
            # modified but not checked in:
            if version.endswith('+'):
                version += time.strftime('%Y%m%d')

        # Append the global Mercurial revision:
        full_version += '.dev.'+version

    return full_version

def write_version_py(version,filename='bionet/utils/version.py'):
    f = file(filename,"w")
    f.write("# THIS FILE IS GENERATED BY THE BIONET UTILS SETUP.PY FILE\n")
    f.write("__version__ = '"+version+"'\n")
    f.close()
                           
if __name__=="__main__":
    if os.path.exists('MANIFEST'):
        os.remove('MANIFEST')

    write_version_py(get_version(VERSION,IS_RELEASED))

    setup(name = NAME,
          version = get_version(VERSION,IS_RELEASED),
          author = AUTHOR,
          author_email = AUTHOR_EMAIL,
          url = URL,
          maintainer = MAINTAINER,
          maintainer_email = MAINTAINER_EMAIL,
          description = DESCRIPTION,
          license = LICENSE,
          classifiers = CLASSIFIERS,
          packages = ['bionet','bionet.utils'],
          package_dir = {'bionet.utils': 'bionet/utils'})


@@ -856,16 +856,129 @@
 d=True):
+%0A    %22%22%22%0A    Return package version. If %60is_released%60 is True, append the%0A    package Mercurial revision.%0A    %22%22%22
 %0A%0A    fu
@@ -1835,17 +1835,19 @@
  '.dev.'
-+
+ + 
 version%0A
@@ -1901,16 +1901,17 @@
 version,
+ 
 filename
@@ -1935,24 +1935,111 @@
 rsion.py'):%0A
+    %22%22%22%0A    Write the indicated package version to the specified Python file.%0A    %22%22%22%0A%0A
     f = file
@@ -2162,17 +2162,21 @@
 = '%22
-+
+ + 
 version
-+
+ + 
 %22'%5Cn
@@ -2235,19 +2235,21 @@
 me__
+ 
 ==
-%22
+ '
 __main__
 %22:%0A 
@@ -2244,17 +2244,17 @@
 __main__
-%22
+'
 :%0A    if

Add comments to setup.py.