<commit_before>#!/usr/bin/python
# vim:ts=4:sw=4:softtabstop=0:smarttab
# 
#    Copyright (C) 1999-2007  <NAME> <<EMAIL>>
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Master builder (custom script).
This top-level setup script helps with dealing with all sub-packages at
once. It also provides an installer for a nicer developer mode. 

Invoke it like a standard setup.py script. However, Any names after the
operation name are taken as sub-package names that are operated on. If no
names are given then all packages are operated on.

Commands:
 list         -- List available subpackages. These are the names you may optionally supply.
 publish      -- Put source distribution on pypi.
 build        -- Run setuptools build phase on named sub-packages (or all of them).
 install      -- Run setuptools install phase.
 eggs         -- Build distributable egg package.
 rpms         -- Build RPMs on platforms that support building RPMs.
 msis         -- Build Microsoft .msi on Windows.
 wininst      -- Build .exe installer on Windows.
 develop      -- Developer mode, as defined by setuptools.
 develophome  -- Developer mode, installing .pth and script files in user directory.
 clean        -- Run setuptools clean phase.
 squash       -- Squash (flatten) all named sub-packages into single tree
                 in $PYCOPIA_SQUASH, or user site-directory if no $PYCOPIA_SQUASH defined.
                 This also removes the setuptools runtime dependency.

Most regular setuptools commands also work. They are passed through by
default.

NOTE: The install operation requires that the sudo command be configured for you.

"""

import sys
import os

try:
    WEXITSTATUS = os.WEXITSTATUS
except AttributeError: # running on Windows
    def WEXITSTATUS(arg):
        return arg
    os.environ["HOME"] = os.environ["USERPROFILE"]
    RSYNCCHECK = "rsync --version >nul"
    SCRIPT_DIR = os.path.join(sys.prefix, "Scripts")
else:
    RSYNCCHECK = "rsync --version >/dev/null"
    SCRIPT_DIR = "/usr/local/bin"

PACKAGES = [
"aid",
"utils",
"core",
"CLI",
"debugger",
"process",
"SMI",
"mibs",
"SNMP",
"storage",
"QA",
"net",
"audio",
"XML",
"WWW",
"vim",
"fepy",
]

# newer Pythons also search this location in user's directory.  We can use
# this for storing the .pth files in develop mode. Should we also support
# older Python?

HOMESITE = os.path.join(os.path.expandvars("$HOME"), ".local", "lib",
                        "python%s" % (sys.version[:3],), "site-packages")
PYCOPIA_SQUASH = os.environ.get("PYCOPIA_SQUASH", HOMESITE)
PYCOPIA_BIN = os.environ.get("PYCOPIA_BIN", os.path.join(os.path.expandvars("$HOME"), "bin"))


def _do_commands(name, cmds, root):
    # use sudo on Linux and possibly other platforms. On Windows it's
    # assumed you're running as Administrator (everybody does it...)
    if root and sys.platform not in ("win32", "cli"):
        sudo = "sudo "
    else:
        sudo = ""
    cmd = "%s%s setup.py %s" % (sudo, sys.executable, " ".join(cmds))
    print "========", name, "==", cmd
    rv = False
    os.chdir(name)
    try:
        rv = WEXITSTATUS(os.system(cmd)) == 0
    finally:
        os.chdir("..")
        print "====================== END", name
        print
    return rv

def do_eggs(name):
    return _do_commands(name, ["bdist_egg"], False)

def do_rpms(name):
    return _do_commands(name, ["bdist_rpm"], False)

def do_msis(name):
    return _do_commands(name, ["bdist_msi"], False)

def do_wininst(name):
    return _do_commands(name, ["bdist_wininst"], False)

# "scripts", those files in bin/, may require some special interpreter
# flags, such as -S, that the setuptools developer mode mangles. Therefore,
# there is this special script installer that does a regular install for
# developer mode.
def _do_scripts(name, scriptdir):
    os.chdir(name)
    try:
        cmd = "%s setup.py install_scripts --force --install-dir %s" % (sys.executable, scriptdir)
        print "======== SCRIPTS", name, "==", cmd
        rv = WEXITSTATUS(os.system(cmd)) == 0
    finally:
        os.chdir("..")
    if not rv:
        print "Warning: scripts for %r may not have installed." % (name,)
    print "====================== END SCRIPTS", name
    return rv

def do_develophome(name):
    if not os.path.isdir(HOMESITE):
        os.makedirs(HOMESITE)
    rv = _do_commands(name, ["develop", "--install-dir", HOMESITE, "--script-dir", PYCOPIA_BIN, "-l -N"], False)
    rvs = _do_scripts(name, PYCOPIA_BIN)
    return rv and rvs

def do_develop(name):
    rv = _do_commands(name, ["develop", "--script-dir", PYCOPIA_BIN, "-l -N"], False)
    rvs = _do_scripts(name, PYCOPIA_BIN)
    return rv and rvs

def do_publish(name):
    return _do_commands(name, ['egg_info -RDb ""', "sdist", "register", "upload"], False)

def do_egg_info(name):
    return _do_commands(name, ['egg_info'], False)

def do_install(name):
    return _do_commands(name, ["install -O2", "--install-scripts",  SCRIPT_DIR], True)

def do_clean(name):
    return _do_commands(name, ["clean"], False)

def do_list(name):
    print name,<commit_msg>Also fix script wrapper problem for regular installs. Scripts now go in /usr/local/bin also (if installed from source).<commit_after>#!/usr/bin/python
# vim:ts=4:sw=4:softtabstop=0:smarttab
# 
#    Copyright (C) 1999-2007  <NAME> <<EMAIL>>
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Master builder (custom script).
This top-level setup script helps with dealing with all sub-packages at
once. It also provides an installer for a nicer developer mode. 

Invoke it like a standard setup.py script. However, Any names after the
operation name are taken as sub-package names that are operated on. If no
names are given then all packages are operated on.

Commands:
 list         -- List available subpackages. These are the names you may optionally supply.
 publish      -- Put source distribution on pypi.
 build        -- Run setuptools build phase on named sub-packages (or all of them).
 install      -- Run setuptools install phase.
 eggs         -- Build distributable egg package.
 rpms         -- Build RPMs on platforms that support building RPMs.
 msis         -- Build Microsoft .msi on Windows.
 wininst      -- Build .exe installer on Windows.
 develop      -- Developer mode, as defined by setuptools.
 develophome  -- Developer mode, installing .pth and script files in user directory.
 clean        -- Run setuptools clean phase.
 squash       -- Squash (flatten) all named sub-packages into single tree
                 in $PYCOPIA_SQUASH, or user site-directory if no $PYCOPIA_SQUASH defined.
                 This also removes the setuptools runtime dependency.

Most regular setuptools commands also work. They are passed through by
default.

NOTE: The install operation requires that the sudo command be configured for you.

"""

import sys
import os

try:
    WEXITSTATUS = os.WEXITSTATUS
except AttributeError: # running on Windows
    def WEXITSTATUS(arg):
        return arg
    os.environ["HOME"] = os.environ["USERPROFILE"]
    RSYNCCHECK = "rsync --version >nul"
    SCRIPT_DIR = os.path.join(sys.prefix, "Scripts")
else:
    RSYNCCHECK = "rsync --version >/dev/null"
    SCRIPT_DIR = "/usr/local/bin"

PACKAGES = [
"aid",
"utils",
"core",
"CLI",
"debugger",
"process",
"SMI",
"mibs",
"SNMP",
"storage",
"QA",
"net",
"audio",
"XML",
"WWW",
"vim",
"fepy",
]

# newer Pythons also search this location in user's directory.  We can use
# this for storing the .pth files in develop mode. Should we also support
# older Python?

HOMESITE = os.path.join(os.path.expandvars("$HOME"), ".local", "lib",
                        "python%s" % (sys.version[:3],), "site-packages")
PYCOPIA_SQUASH = os.environ.get("PYCOPIA_SQUASH", HOMESITE)
PYCOPIA_BIN = os.environ.get("PYCOPIA_BIN", os.path.join(os.path.expandvars("$HOME"), "bin"))


def _do_commands(name, cmds, root):
    # use sudo on Linux and possibly other platforms. On Windows it's
    # assumed you're running as Administrator (everybody does it...)
    if root and sys.platform not in ("win32", "cli"):
        sudo = "sudo "
    else:
        sudo = ""
    cmd = "%s%s setup.py %s" % (sudo, sys.executable, " ".join(cmds))
    print "========", name, "==", cmd
    rv = False
    os.chdir(name)
    try:
        rv = WEXITSTATUS(os.system(cmd)) == 0
    finally:
        os.chdir("..")
        print "====================== END", name
        print
    return rv

def do_eggs(name):
    return _do_commands(name, ["bdist_egg"], False)

def do_rpms(name):
    return _do_commands(name, ["bdist_rpm"], False)

def do_msis(name):
    return _do_commands(name, ["bdist_msi"], False)

def do_wininst(name):
    return _do_commands(name, ["bdist_wininst"], False)

# "scripts", those files in bin/, may require some special interpreter
# flags, such as -S, that the setuptools developer mode mangles. Therefore,
# there is this special script installer that does a regular install for
# developer mode.
def _do_scripts(name, scriptdir):
    os.chdir(name)
    try:
        cmd = "%s setup.py install_scripts --force --install-dir %s" % (sys.executable, scriptdir)
        print "======== SCRIPTS", name, "==", cmd
        rv = WEXITSTATUS(os.system(cmd)) == 0
    finally:
        os.chdir("..")
    if not rv:
        print "Warning: scripts for %r may not have installed." % (name,)
    print "====================== END SCRIPTS", name
    return rv

def do_develophome(name):
    if not os.path.isdir(HOMESITE):
        os.makedirs(HOMESITE)
    rv = _do_commands(name, ["develop", "--install-dir", HOMESITE, "--script-dir", PYCOPIA_BIN, "-l -N"], False)
    rvs = _do_scripts(name, PYCOPIA_BIN)
    return rv and rvs

def do_develop(name):
    rv = _do_commands(name, ["develop", "--script-dir", PYCOPIA_BIN, "-l -N"], False)
    rvs = _do_scripts(name, PYCOPIA_BIN)
    return rv and rvs

def do_publish(name):
    return _do_commands(name, ['egg_info -RDb ""', "sdist", "register", "upload"], False)

def do_egg_info(name):
    return _do_commands(name, ['egg_info'], False)

def do_install(name):
    rv1 = _do_commands(name, ["install -O2", "--install-scripts",  SCRIPT_DIR], True)
    # Don't use the setuptools script wrapper for Pycopia scripts. This
    # command seems to bypass that.
    rv2 = _do_commands(name, ["install_scripts", "--force", "--install-dir",  SCRIPT_DIR], True)
    return rv1 and rv2

def do_clean(name):
    return _do_commands(name, ["clean"], False)

def do_list(name):
    print name,
{'fraction_non_alphanumeric': 0.12603793374705008, 'fraction_numerical': 0.0036710077790402936, 'mean_word_length': 3.27418752334703, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5114650', 'n_tokens_mistral': 3682, 'n_tokens_neox': 3564, 'n_words': 1262}