<commit_before>#!/usr/bin/env python
# Copyright (c) 2011-2012 Turbulenz Limited

"""
Init script for manipulating the Turbulenz Engine project.
"""
import os
import sys
import re
import time
import os.path
from glob import iglob
from subprocess import call
import argparse

from scripts import TURBULENZ_ENGINE_VERSION
from scripts.utils import TURBULENZOS, TURBULENZROOT, PYTHON, ENV
from scripts.utils import command_no_arguments, command_with_arguments, command_requires_env
from scripts.utils import CalledProcessError, echo, log, warning, error, ok, sh, rmdir, find_devenv, rm, mkdir, cp
from scripts.utils import check_documentation_links

#######################################################################################################################

@command_no_arguments
def command_env():
    if sys.version_info[1] != 7:
        error('Turbulenz requires python 2.7')
        return -1

    if not os.path.isdir(ENV):
        if TURBULENZOS == 'win32':
            sh('%s -m virtualenv --no-site-packages %s' % (sys.executable, ENV))
        else:
            print "PYTHON: %s" % PYTHON
            cmd = 'virtualenv -p %s --no-site-packages %s' % (PYTHON, ENV)
            print "CMD: %s" % cmd
            sh(cmd, console=True)

    if TURBULENZOS == 'win32':
        env_bin = os.path.join('env', 'scripts')
        with open(os.path.join(env_bin, 'activate.bat'), 'a') as f:
            f.write('set PATH=%PATH%;%VIRTUAL_ENV%\\..\\tools\\scripts\n')
    else:
        env_bin = os.path.join('env', 'bin')
        with open(os.path.join(env_bin, 'activate'), 'a') as f:
            f.write('export PATH=$PATH:$VIRTUAL_ENV/../tools/scripts\n')

    def _easy_install(package):
        cmd = [os.path.join(env_bin, 'easy_install'), package]
        sh(cmd)

    _easy_install('simplejson>=2.1.5')
    _easy_install('PyYAML>=3.10')

    _easy_install('logilab-common==0.57.1')
    _easy_install('logilab-astng==0.23.1')
    _easy_install('pylint==0.25.1')

    _easy_install('roman>=1.4.0')
    _easy_install('docutils>=0.9.1')
    _easy_install('Sphinx>=1.1.3')

    _easy_install('turbulenz_tools>=1.0')
    _easy_install('turbulenz_local>=1.0')

    cmd = [os.path.join(env_bin, 'python'), os.path.join('scripts', 'install_nodejs.py'), '--typescript']
    if not TURBULENZOS in [ 'linux32', 'linux64' ]:
        cmd.append('-f')
    sh(cmd, console=True)

@command_no_arguments
def command_env_clean():
    rmdir(ENV)

#######################################################################################################################

@command_requires_env
@command_with_arguments
def command_jslib(options):

    parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is"
                                                 " given, builds or cleans all the listed apps (except samples).")
    parser.add_argument('--clean', action='store_true', help="Clean jslib (completely removes directory!)")
    parser.add_argument('--outdir', default=None, help="Build jslib to an alternative directory")
    parser.add_argument('--closure', action='store_true', help="Verify the generated .js files with closure")
    parser.add_argument('-v', '--verbose', action='store_true', help="Verbose output")
    parser.add_argument('-j', type=int, default=_get_num_cpus() + 1, help="Up to N processes (default is num CPUS + 1)")
    parser.add_argument('--check', help="Syntax check the given file under tslib")
    parser.add_argument('--refcheck', action='store_true', help="Enable the reference checking build")
    parser.add_argument('-m', '--modular', action='store_true', help="Build modules only (in dependency order)")
    parser.add_argument('--crude', action='store_true', help="Build jslib only (no error checking)")

    args = parser.parse_args(options)

    if args.modular:
        mode = 'modular'
    elif args.crude:
        mode = 'crude'
    else:
        mode = 'all'

    # Clean any make env vars in case we have been invoked from a
    # parent make process.
    os.environ['MAKEFLAGS'] = ""
    os.environ['MFLAGS'] = ""

    # Determine the make command line
    cmd = "%s -j %s" % (_get_make_command(), args.j)

    if args.outdir:
        cmd += " TZ_OUTPUT_DIR=%s" % args.outdir
    if args.verbose:
        cmd += " CMDVERBOSE=1"
    if args.closure:
        cmd += " VERIFY_CLOSURE=1"

    # If mode == "all", run the modular build, then crude
    if "all" == mode:
        if 0 != command_jslib(options + [ '--modular' ]):
            return 1
        mode = "crude"
    elif "modular" == mode:
        cmd += " MODULAR=1"
    elif "refcheck" == mode:
        cmd += " REFCHECK=1"

    # Select the appropriate target based on whether we are syntax
    # checking or doing a full build.
    if args.check:
        cmd += " CHK_SOURCES=%s SYNTAX_CHECK_MODE=1 REFCHECK=1 check-syntax" \
            % args.check
    elif args.clean:
        cmd += " distclean_ts"
    else:
        cmd += " jslib"

    print "BUILD CMD IS:\n  %s" % cmd

    start_time = time.time()
    retval = call(cmd, shell=True)
    print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)

    if 0 != retval:
        error(cmd)

    return retval


@command_requires_env
@command_with_arguments
def command_jslib_clean(options):
    command_jslib([ '--clean' ] + options)

def _get_num_cpus():
    import multiprocessing
    return multiprocessing.cpu_count()

def _get_make_command():
    if TURBULENZOS in ['win32', 'win64']:
        return "external\\gnumake-win32\\3.81\\bin\\make.exe"
    return "make"

#######################################################################################################################

@command_no_arguments
def command_tools():
    tools = 'tools'
    tools_bin = 'tools/bin/%s' % TURBULENZOS

    mkdir(tools_bin)
    if TURBULENZOS == 'win32':
        devenv = find_devenv()

        cgfx2json_proj = os.path.normpath(os.path.join(TURBULENZROOT, tools, 'cgfx2json', 'cgfx2json.vcproj'))
        sh([devenv, cgfx2json_proj, '/build', 'Release'], console=True)
        cp('tools/cgfx2json/Release/cgfx2json.exe', tools_bin)
        cp('external/Cg/bin/cg.dll', tools_bin)
        cp('external/Cg/bin/cgGL.dll', tools_bin)

        nvtristrip_sln = os.path.normpath(os.path.join(TURBULENZROOT, tools, 'NvTriStrip', 'NvTriStrip.sln'))
        sh([devenv, nvtristrip_sln, '/build', 'Release'], console=True)
        cp('tools/NvTriStrip/NvTriStripper/Release/NvTriStripper.exe', tools_bin)

    else:
        sh('make', tools, console=True)
        cp('tools/cgfx2json/bin/release/cgfx2json', tools_bin)
        cp('tools/NvTriStrip/NvTriStripper/bin/release/NvTriStripper', tools_bin)


@command_no_arguments
def command_tools_clean():
    tools = 'tools'<commit_msg>Fix paths for windows binary copies<commit_after>#!/usr/bin/env python
# Copyright (c) 2011-2012 Turbulenz Limited

"""
Init script for manipulating the Turbulenz Engine project.
"""
import os
import sys
import re
import time
import os.path
from glob import iglob
from subprocess import call
import argparse

from scripts import TURBULENZ_ENGINE_VERSION
from scripts.utils import TURBULENZOS, TURBULENZROOT, PYTHON, ENV
from scripts.utils import command_no_arguments, command_with_arguments, command_requires_env
from scripts.utils import CalledProcessError, echo, log, warning, error, ok, sh, rmdir, find_devenv, rm, mkdir, cp
from scripts.utils import check_documentation_links

#######################################################################################################################

@command_no_arguments
def command_env():
    if sys.version_info[1] != 7:
        error('Turbulenz requires python 2.7')
        return -1

    if not os.path.isdir(ENV):
        if TURBULENZOS == 'win32':
            sh('%s -m virtualenv --no-site-packages %s' % (sys.executable, ENV))
        else:
            print "PYTHON: %s" % PYTHON
            cmd = 'virtualenv -p %s --no-site-packages %s' % (PYTHON, ENV)
            print "CMD: %s" % cmd
            sh(cmd, console=True)

    if TURBULENZOS == 'win32':
        env_bin = os.path.join('env', 'scripts')
        with open(os.path.join(env_bin, 'activate.bat'), 'a') as f:
            f.write('set PATH=%PATH%;%VIRTUAL_ENV%\\..\\tools\\scripts\n')
    else:
        env_bin = os.path.join('env', 'bin')
        with open(os.path.join(env_bin, 'activate'), 'a') as f:
            f.write('export PATH=$PATH:$VIRTUAL_ENV/../tools/scripts\n')

    def _easy_install(package):
        cmd = [os.path.join(env_bin, 'easy_install'), package]
        sh(cmd)

    _easy_install('simplejson>=2.1.5')
    _easy_install('PyYAML>=3.10')

    _easy_install('logilab-common==0.57.1')
    _easy_install('logilab-astng==0.23.1')
    _easy_install('pylint==0.25.1')

    _easy_install('roman>=1.4.0')
    _easy_install('docutils>=0.9.1')
    _easy_install('Sphinx>=1.1.3')

    _easy_install('turbulenz_tools>=1.0')
    _easy_install('turbulenz_local>=1.0')

    cmd = [os.path.join(env_bin, 'python'), os.path.join('scripts', 'install_nodejs.py'), '--typescript']
    if not TURBULENZOS in [ 'linux32', 'linux64' ]:
        cmd.append('-f')
    sh(cmd, console=True)

@command_no_arguments
def command_env_clean():
    rmdir(ENV)

#######################################################################################################################

@command_requires_env
@command_with_arguments
def command_jslib(options):

    parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is"
                                                 " given, builds or cleans all the listed apps (except samples).")
    parser.add_argument('--clean', action='store_true', help="Clean jslib (completely removes directory!)")
    parser.add_argument('--outdir', default=None, help="Build jslib to an alternative directory")
    parser.add_argument('--closure', action='store_true', help="Verify the generated .js files with closure")
    parser.add_argument('-v', '--verbose', action='store_true', help="Verbose output")
    parser.add_argument('-j', type=int, default=_get_num_cpus() + 1, help="Up to N processes (default is num CPUS + 1)")
    parser.add_argument('--check', help="Syntax check the given file under tslib")
    parser.add_argument('--refcheck', action='store_true', help="Enable the reference checking build")
    parser.add_argument('-m', '--modular', action='store_true', help="Build modules only (in dependency order)")
    parser.add_argument('--crude', action='store_true', help="Build jslib only (no error checking)")

    args = parser.parse_args(options)

    if args.modular:
        mode = 'modular'
    elif args.crude:
        mode = 'crude'
    else:
        mode = 'all'

    # Clean any make env vars in case we have been invoked from a
    # parent make process.
    os.environ['MAKEFLAGS'] = ""
    os.environ['MFLAGS'] = ""

    # Determine the make command line
    cmd = "%s -j %s" % (_get_make_command(), args.j)

    if args.outdir:
        cmd += " TZ_OUTPUT_DIR=%s" % args.outdir
    if args.verbose:
        cmd += " CMDVERBOSE=1"
    if args.closure:
        cmd += " VERIFY_CLOSURE=1"

    # If mode == "all", run the modular build, then crude
    if "all" == mode:
        if 0 != command_jslib(options + [ '--modular' ]):
            return 1
        mode = "crude"
    elif "modular" == mode:
        cmd += " MODULAR=1"
    elif "refcheck" == mode:
        cmd += " REFCHECK=1"

    # Select the appropriate target based on whether we are syntax
    # checking or doing a full build.
    if args.check:
        cmd += " CHK_SOURCES=%s SYNTAX_CHECK_MODE=1 REFCHECK=1 check-syntax" \
            % args.check
    elif args.clean:
        cmd += " distclean_ts"
    else:
        cmd += " jslib"

    print "BUILD CMD IS:\n  %s" % cmd

    start_time = time.time()
    retval = call(cmd, shell=True)
    print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)

    if 0 != retval:
        error(cmd)

    return retval


@command_requires_env
@command_with_arguments
def command_jslib_clean(options):
    command_jslib([ '--clean' ] + options)

def _get_num_cpus():
    import multiprocessing
    return multiprocessing.cpu_count()

def _get_make_command():
    if TURBULENZOS in ['win32', 'win64']:
        return "external\\gnumake-win32\\3.81\\bin\\make.exe"
    return "make"

#######################################################################################################################

@command_no_arguments
def command_tools():
    tools = 'tools'
    tools_bin = 'tools/bin/%s' % TURBULENZOS

    mkdir(tools_bin)
    if TURBULENZOS == 'win32':
        devenv = find_devenv()

        cgfx2json_proj = os.path.normpath(os.path.join(TURBULENZROOT, tools, 'cgfx2json', 'cgfx2json.vcproj'))
        sh([devenv, cgfx2json_proj, '/build', 'Release'], console=True)
        cp('tools/cgfx2json/bin/release/cgfx2json.exe', tools_bin)
        cp('external/Cg/bin/cg.dll', tools_bin)
        cp('external/Cg/bin/cgGL.dll', tools_bin)

        nvtristrip_sln = os.path.normpath(os.path.join(TURBULENZROOT, tools, 'NvTriStrip', 'NvTriStrip.sln'))
        sh([devenv, nvtristrip_sln, '/build', 'Release'], console=True)
        cp('tools/NvTriStrip/NvTriStripper/bin/release/NvTriStripper.exe', tools_bin)

    else:
        sh('make', tools, console=True)
        cp('tools/cgfx2json/bin/release/cgfx2json', tools_bin)
        cp('tools/NvTriStrip/NvTriStripper/bin/release/NvTriStripper', tools_bin)


@command_no_arguments
def command_tools_clean():
    tools = 'tools'
{'fraction_non_alphanumeric': 0.18506541231809495, 'fraction_numerical': 0.01220049977950904, 'mean_word_length': 3.3836984536082473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4275694', 'n_tokens_mistral': 4672, 'n_tokens_neox': 4479, 'n_words': 1002}