<commit_before>#!/usr/bin/env python
# -*- coding: utf8 -*-
__version__ = "$Revision: 165 $ $Date: 2011-03-19 17:29:20 +0100 (sam. 19 mars 2011) $"
__author__  = "<NAME> <<EMAIL>>"
__license__ = """
	Copyright (C) 2010-2011, <NAME> <<EMAIL>>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, version 3.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import os, os.path

#from distutils.core                 import setup
#from distutils.command.install_lib  import install_lib
#from distutils.command.install      import install
#from distutils.dist                 import Distribution
from distutils.dir_util             import ensure_relative
from setuptools import setup, Command
from setuptools.command.install_lib  import install_lib
from setuptools.command.install      import install
from setuptools.dist                 import Distribution

class _Distribution(Distribution):
	def __init__(self, *args, **kwargs):
		# add new option for motherapps
		self.motherapps = []

		Distribution.__init__(self, *args, **kwargs)

		# automatically install our install_lib version
		if not 'install' in self.cmdclass:
			self.cmdclass['install']= _install
		if not 'install_lib' in self.cmdclass:
			self.cmdclass['install_lib']= _install_lib


class _install(install):
	def finalize_options(self):
		install.finalize_options(self)

		self.install_apps = self.install_base
		# manage --prefix option (i.e is set when in an environment created with *virtualenv*)
		if self.prefix_option is None and self.install_base == '/usr': # default prefix
			# TODO: specific install paths may not be changes if explicitly specified by user on command line (--install-scripts and --install-data options)
			(self.install_scripts, self.install_data, self.install_apps) = ('/usr/bin', '/', '/')

		# manage --root option (is set when doing "setup.py bdist")
		if self.root is not None:
			for p in ('scripts','data','apps'):
				setattr(self, 'install_'+p, os.path.join(self.root, ensure_relative(getattr(self, 'install_'+p))))
		

class _install_lib(install_lib):
	excludes = ['.svn']
	dest     = 'var/lib/mother/apps'
	_pyfiles = []

	def run(self):
		install_lib.run(self)

		if self.dry_run or len(self.distribution.motherapps) == 0:
			return

		inst = self.get_finalized_command('install')

		for app in self.distribution.motherapps:
			self._copy_tree(<commit_msg>[fix] setup.py: fix paths both in install.finalize_options() and install.run()<commit_after>#!/usr/bin/env python
# -*- coding: utf8 -*-
__version__ = "$Revision: 165 $ $Date: 2011-03-19 17:29:20 +0100 (sam. 19 mars 2011) $"
__author__  = "<NAME> <<EMAIL>>"
__license__ = """
	Copyright (C) 2010-2011, <NAME> <<EMAIL>>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, version 3.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
import os, os.path

#from distutils.core                 import setup
#from distutils.command.install_lib  import install_lib
#from distutils.command.install      import install
#from distutils.dist                 import Distribution
from distutils.dir_util             import ensure_relative
from setuptools import setup, Command
from setuptools.command.install_lib  import install_lib
from setuptools.command.install      import install
from setuptools.dist                 import Distribution

class _Distribution(Distribution):
	def __init__(self, *args, **kwargs):
		# add new option for motherapps
		self.motherapps = []

		Distribution.__init__(self, *args, **kwargs)

		# automatically install our install_lib version
		if not 'install' in self.cmdclass:
			self.cmdclass['install']= _install
		if not 'install_lib' in self.cmdclass:
			self.cmdclass['install_lib']= _install_lib


class _install(install):
	def _fix_paths(self):
		self.install_apps = self.install_base
		# manage --prefix option (i.e is set when in an environment created with *virtualenv*)
		if self.prefix_option is None and self.install_base == '/usr': # default prefix
			# TODO: specific install paths may not be changes if explicitly specified by user on command line (--install-scripts and --install-data options)
			(self.install_scripts, self.install_data, self.install_apps) = ('/usr/bin', '/', '/')

		# manage --root option (is set when doing "setup.py bdist")
		if self.root is not None:
			for p in ('scripts','data','apps'):
				setattr(self, 'install_'+p, os.path.join(self.root, ensure_relative(getattr(self, 'install_'+p))))
		
	def finalize_options(self):
		install.finalize_options(self)
		self._fix_paths()

	def run(self):
		self._fix_paths()
		install.run(self)


class _install_lib(install_lib):
	excludes = ['.svn']
	dest     = 'var/lib/mother/apps'
	_pyfiles = []

	def run(self):
		install_lib.run(self)

		if self.dry_run or len(self.distribution.motherapps) == 0:
			return

		inst = self.get_finalized_command('install')

		for app in self.distribution.motherapps:
			self._copy_tree(
{'fraction_non_alphanumeric': 0.10348378239231165, 'fraction_numerical': 0.013042732109147075, 'mean_word_length': 3.9769427839453457, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '544722', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1717, 'n_words': 590}