# Copyright (c) 2007-2008 The PyAMF Project.
# See LICENSE for details.

#from ez_setup import use_setuptools

#use_setuptools()

import glob
from setuptools import setup, find_packages
from setuptools.command import test
from setuptools.command.install import install

import sys
import os

install_requires = []

keyw = """\
"""

# yuk, spew, hurl.  but it works.  anyone got any better ideas?
if sys.platform == "win32":
    datadir = "share/pyjamas"
else:
    # last thing we want on unix systems is the data files ending
    # up in a random egg subdirectory, where no-one can find them.
    # windows platform, i couldn't care less where they end up but
    # it musn't be a fixed path, it must be a relative path.
    datadir = "/usr/share/pyjamas"

bp_data_files = glob.glob("builder/boilerplate/*")
test_files = glob.glob("pyjs/tests/*")
stub_files = glob.glob("stubs/*")
addons_data_files = glob.glob("addons/*.py")

data_files = [
    (os.path.join(datadir, "builder/boilerplate"), bp_data_files),
    (os.path.join(datadir, "pyjs/tests"), test_files),
    (os.path.join(datadir, "stubs"), stub_files),
    (os.path.join(datadir, "addons"), addons_data_files)
]

# main purpose of this function is to exclude "output" which
# could have been built by a developer.
def get_files(d):
    res = []
    for p in glob.glob(os.path.join(d, "*")):
        if not p:
            continue
        (pth, fname) = os.path.split(p)
        if fname == "output":
            continue
        if fname[-4:] == ".pyc": # ehmm.. noooo.
            continue 
        if os.path.isdir(p):
            get_dir(p)
        else:
            res.append(p)
    return res

def get_dir(dirname):
    for d in glob.glob("%s/*" % dirname):
        if os.path.isdir(d):
            (pth, fname) = os.path.split(d)
            expath = get_files(d)
            pth = os.path.join(os.path.join(datadir, dirname), fname)
            data_files.append((pth, expath))
        else:
            data_files.append((os.path.join(datadir, dirname), [d]))

# recursively grab the library and the examples subdirectories - all contents
get_dir("library")
get_dir("examples")

from pprint import pprint
pprint(data_files)

if __name__ == '__main__':
    setup(name = "Pyjamas",
        version = "0.5",
        description = "Pyjamas Widget API for Web applications, in Python",
        long_description = open('README', 'rt').read(),
        url = "http://pyjs.org",
        author = "The Pyjamas Project",
        author_email = "lkcl@lkcl.net",
        keywords = keyw,
        entry_points = {'console_scripts':[
                       'pyjsbuild=pyjs.build:main',
                       'pyjscompile=pyjs:main',
                       ]},
        packages=["pyjs"],
        install_requires = install_requires,
        data_files = data_files,
        zip_safe=False,
        license = "Apache Software License",
        platforms = ["any"],
        classifiers = [
            "Development Status :: 5 - Production/Stable",
            "Natural Language :: English",
            "Intended Audience :: Developers",
            "License :: OSI Approved :: Apache Software License",
            "Operating System :: OS Independent",
            "Programming Language :: Python"
        ])


@@ -435,23 +435,39 @@
 r = 
+os.path.join(
 %22share
-/
+%22, %22
 pyjamas%22
 %0Aels
@@ -462,16 +462,17 @@
 pyjamas%22
+)
 %0Aelse:%0A 
@@ -793,24 +793,37 @@
 ob.glob(
+os.path.join(
 %22builder
 /boilerp
@@ -806,33 +806,36 @@
 th.join(%22builder
-/
+%22, %22
 boilerplate/*%22)%0A
@@ -829,20 +829,24 @@
 lerplate
-/
+%22, %22
 *%22)
+)
 %0Atest_fi
@@ -865,23 +865,43 @@
 lob(
+os.path.join(
 %22pyjs
-/
+%22, %22
 tests
-/
+%22, %22
 *%22)
+)
 %0Astu
@@ -924,18 +924,35 @@
 lob(
+os.path.join(
 %22stubs
-/
+%22, %22
 *%22)
+)
 %0Aadd
@@ -982,16 +982,32 @@
 lob(
+os.path.join(
 %22addons
-/
+%22, %22
 *.py
@@ -1060,17 +1060,20 @@
 %22builder
-/
+%22, %22
 boilerpl
@@ -1127,17 +1127,20 @@
 r, %22pyjs
-/
+%22, %22
 tests%22),

windows. cant stand it