#!/usr/bin/python

from distutils.core import setup
from distutils.extension import Extension
import Pyrex.Distutils, time, re
from version import *

LONG_DESC = '''\
This is ClamAV native support for python via libclamav for SAGATOR,
but may be used for any python script.
Script "example.py" is a part of this package.
'''

# update spec file
if re.compile('^[0-9]+$').search(RELEASE):
  UNSTABLE_RELEASE=''
else:
  UNSTABLE_RELEASE='-'+RELEASE
open(PROJECT+'.spec','w').write(
  open(PROJECT+'.spec.in','r').read(
  ).replace(
    '%VERSION%', VERSION
  ).replace(
    '%RELEASE%', RELEASE
  ).replace(
    '%UNSTABLE_RELEASE%', UNSTABLE_RELEASE
  )
)

# update debian changelog file
open('debian/changelog','w').write('''\
%s (%s-%s) unstable; urgency=low

  * This file is automatically generated by sagator's configure script.
  
 -- Jan ONDREJ (SAGATOR) <ondrejj@salstar.sk>  %s
''' % (PROJECT,VERSION,RELEASE,time.strftime('%a, %d %b %Y %H:%M:%S %z'))
)

# update gentoo ebuild
rel_path='%s-%s-%s.tar.bz2' % (PROJECT, VERSION, RELEASE)
if ('beta' in RELEASE) or ('rc' in RELEASE):
  rel_path='unstable/' + rel_path
  eb_name='%s-%s.ebuild' % (PROJECT, VERSION)
                            #re.compile('^[0-9]*').sub('_', RELEASE))
else:
  eb_name='%s-%s.ebuild' % (PROJECT, VERSION)
open(eb_name, 'w').write(
  open(PROJECT+'.ebuild.in').read() % rel_path
)

# check clamav.h version
if 'CL_SUCCESS' not in open('/usr/include/clamav.h').read():
  print "Please update to clamav 0.90 or higher!"
  import sys
  sys.exit(1)

setup(
  name=PROJECT,
  version=VERSION,
  description="ClamAV module for python, created for SAGATOR project",
  long_description=LONG_DESC,
  author="Jan ONDREJ (SAL)",
  author_email="ondrejj(at)salstar.sk",
  url="http://www.salstar.sk/sagator/",
  license="LGPL",
  ext_modules=[
    Extension(
      "libclamav",
      ["libclamav.pyx"],
      libraries=['clamav']
    )
  ],
  cmdclass = {'build_ext': Pyrex.Distutils.build_ext}
)
