#!/usr/bin/env python

__version__ = "1.2a1"

import os, sys, glob, string

if sys.platform == 'win32':
    print """This setup.py script is intended  for use on Unix platforms.
We recommend you to use the windows installer to install Narval on your Windows
machine, which sets some configuration information in the windows registry.
You can get the windows installer from ftp://ftp.logilab.org/pub/narval/

If you still want to install Narval throught this script, please refer to the
Narval technical manual to see which registry variables should be set for
Narval proper operation. You will also have to edit this script to remove the
sys.exit(0) statement on line 18"""
    
    sys.exit(0)


import distutils
from distutils import version, util
from distutils.core import setup, Extension
from tools import DistExt
from tools.DistExt import Document,PyModules,CommandLineApp,Localization
from tools.install_data import Data_Files, install_Data_Files

############################################################
#
#  Overriding/extending functionality of DistUtils
#
############################################################

DistExt.InstallSubCommands()


############################################################
#
#  Actual Setup Code
#
############################################################


longDesc = """Narval (Network Assistant Reasoning with a Validating Agent Language) is a personal network assistant based on artificial intelligence and agent technologies.
It executes recipes (sequences of actions) to perform tasks. It is easy to specify a new action using XML and to implement it using Python. Recipes can be constructed graphically by linking blocks representing the actions without programming."""

v = version.StrictVersion(__version__)
package_version = str(v)
doc_version = string.join(map(str,v.version),'.')

documentation_files=[Data_Files(copy_to='.',
                       files=['README','license.txt'
                              ]),
            Data_Files(copy_to='.',
                       files=['doc/ANNOUNCE.en',
                              'doc/ANNOUNCE.fr',
                              'doc/CHANGELOG',
                              'doc/CONTRIBUTORS',
                              'doc/README.WIN32',
                              'doc/README.UNIX',
                              'doc/faq.en.xml',
                              ]),
##            Data_Files(copy_to='doc/manuals',
##                       files=glob.glob('*.sgml')),
##            Data_Files(copy_to='doc/manuals/modules_programmer_handbook',
##                       files=glob.glob('*.sgml')),
##            Data_Files(copy_to='doc/manuals/narval_technical_manual',
##                       files=glob.glob('*.sgml')),
##            Data_Files(copy_to='doc/manuals/narval_user_manual',
##                       files=glob.glob('*.sgml')),
##            Data_Files(copy_to='doc/manuals/narval_technical_manual/images',
##                       files=glob.glob('*.png')+glob.glob('*.eps')),
##            Data_Files(copy_to='doc/manuals/narval_user_manual/images',
##                       files=glob.glob('*.png')+glob.glob('*.eps')),
##            Data_Files(copy_to='doc/manuals/tutorial',
##                       files=glob.glob('*.sgml')),
##            Data_Files(copy_to='doc/UML',
##                       files=['README']+glob.glob('*.argo')+glob.glob('*.xmi')+glob.glob('*.pgml')+glob.glob('*.ps')),
            Data_Files(copy_to='NEP/',
                       files=glob.glob('doc/NEP/*.html')+glob.glob('doc/NEP/*.xml')),
            ]

shared_files = [
            Data_Files(copy_to='data',
                       files=glob.glob('share/data/*.xml')),
            Data_Files(copy_to='data',
                       files=glob.glob('share/data/*.png')),
            Data_Files(copy_to='dtd',
                       files=glob.glob('share/dtd/*.dtd')+glob.glob('share/dtd/*.ent')+glob.glob('share/dtd/CATALOG')),
            Data_Files(copy_to='extensions',
                       files=glob.glob('share/extensions/*.py')),
            Data_Files(copy_to='extensions/classify',
                       files=glob.glob('share/extensions/classify/*.py')),
            Data_Files(copy_to='extensions/html',
                       files=glob.glob('share/extensions/html/*.py')),
            Data_Files(copy_to='extensions/language',
                       files=glob.glob('share/extensions/language/*.py')),
            Data_Files(copy_to='extensions/language',
                       files=glob.glob('share/extensions/language/*.txt')),
            Data_Files(copy_to='extensions/xmlrep',
                       files=glob.glob('share/extensions/xmlrep/*.py')),
            Data_Files(copy_to='graphics',
                       files=glob.glob('share/graphics/*.xpm')),
            Data_Files(copy_to='modules',
                       files=glob.glob('share/modules/*.py')),
            Data_Files(copy_to='recipes',
                       files=glob.glob('share/recipes/*.xml')),
            Data_Files(copy_to='transforms/Email',
                       files=glob.glob('share/transforms/*.xslt')+glob.glob('share/transforms/*.xsl')),
            Data_Files(copy_to='transforms/Basic',
                       files=glob.glob('share/transforms/Basic/*.xslt')+glob.glob('share/transforms/Basic/*.xsl')),
            Data_Files(copy_to='transforms/extensions',
                       files=glob.glob('share/transforms/extensions/*.py')),
            ]


for df in documentation_files:
    df.base_dir = '$base/doc/$dist_name-$dist_version'
for sf in shared_files:
    sf.base_dir = '$base/share/narval'
 
data_files = documentation_files + shared_files
#Do this after we set the base_dir on all of the rest
data_files.append(Data_Files(copy_to='',
                             files=['conf/narval.conf',
                                    ]))
data_files[-1].base_dir='$base/etc'

l10n = [Localization(package='narval',
                     domain='Horn',
                     sources=['narval/gui/*.py'])
       ]

dist = setup(
    name="Narval",
    version=package_version,
    description="Network Assistant Reasoning with a Validating Agent Language",
    author="Logilab",
    author_email="contact@logilab.fr",
    url="http://www.logilab.org/narval",
    long_description=longDesc,

    distclass=DistExt.Dist,

    # Command function overrides
    cmdclass=DistExt.Commands,

    # Install data files to doc/{name}-{version}/
    options={'install' : {'install_data' :
                          '$base/doc/$dist_name'+'-'+doc_version,
                          },
             },

    packages=['narval',
              'narval.dom',
              'narval.gui',
              'narval.core',
              'narval.utils',
              'narval.services',
              'narval.communication',
              'narval.protocol_handlers',
              ],

    data_files = data_files,

    scripts=DistExt.EnsureScripts('exec/narval','exec/horn','exec/npm'),
    verbose=1,
    l10n=l10n
    )

if dist.have_run.get('install') and not dist.have_run.get('bdist'):
    install = dist.get_command_obj('install')
    
