Exemple #1
0
def build_test(cnt, bldconfig, *options):
    options = filter(None, options)
    compat.exec_python_rc(makespec, script_name, '--tk',
                          '--out', out_pattern % cnt, bldconfig, *options)
    compat.exec_python_rc(build, os.path.join(out_pattern % cnt, 'hanoi.spec'),
                          '--noconfirm')
    if is_linux:
        # create symlinks
        if os.path.islink('hanoi%d' % cnt):
            os.remove('hanoi%d' % cnt)
        if bldconfig == '--onedir':
            os.symlink(dist_pattern_dir % cnt, 'hanoi%d' % cnt)
        else:
            os.symlink(dist_pattern_file % cnt, 'hanoi%d' % cnt)
Exemple #2
0
def __exec_python_cmd(cmd, env=None, capture_stdout=True):
    """
    Executes an externally spawned Python interpreter. If capture_stdout
    is set to True, returns anything that was emitted in the standard
    output as a single string. Otherwise, returns the exit code.
    """
    # 'PyInstaller.config' cannot be imported as other top-level modules.
    from PyInstaller.config import CONF
    if env is None:
        env = {}
    # Update environment. Defaults to 'os.environ'
    pp_env = copy.deepcopy(os.environ)
    pp_env.update(env)
    # Prepend PYTHONPATH with pathex
    # Some functions use some PyInstaller code in subprocess so add
    # PyInstaller HOMEPATH to sys.path too.
    pp = os.pathsep.join(CONF['pathex'] + [HOMEPATH])

    # PYTHONPATH might be already defined in the 'env' argument or in
    # the original 'os.environ'. Prepend it.
    if 'PYTHONPATH' in pp_env:
        pp = os.pathsep.join([pp_env.get('PYTHONPATH'), pp])
    pp_env['PYTHONPATH'] = pp

    if capture_stdout:
        txt = compat.exec_python(*cmd, env=pp_env)
        return txt.strip()
    else:
        return compat.exec_python_rc(*cmd, env=pp_env)
Exemple #3
0
    def test_building(self):
        """
        Run building of test script.

        Return True if build succeded False otherwise.
        """
        OPTS = ['--debug']

        if self.verbose:
            OPTS.extend(['--debug', '--log-level=INFO'])
        else:
            OPTS.append('--log-level=ERROR')

        self._msg("BUILDING TEST", self.test_name)

        # use pyinstaller.py for building test_name
        testfile_spec = self.test_file + '.spec'
        if not os.path.exists(self.test_file + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script
            testfile_spec = self.test_file + '.py'

        retcode = compat.exec_python_rc(os.path.join(HOMEPATH, 'pyinstaller.py'),
                  testfile_spec, *OPTS)

        return retcode == 0
Exemple #4
0
    def test_building(self):
        """
        Run building of test script.

        Return True if build succeded False otherwise.
        """
        OPTS = ['--debug']

        if self.verbose:
            OPTS.extend(['--debug', '--log-level=INFO'])
        else:
            OPTS.append('--log-level=ERROR')

        self._msg("BUILDING TEST", self.test_name)

        # use pyinstaller.py for building test_name
        testfile_spec = self.test_file + '.spec'
        if not os.path.exists(self.test_file + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script
            testfile_spec = self.test_file + '.py'

        retcode = compat.exec_python_rc(
            os.path.join(HOMEPATH, 'pyinstaller.py'), testfile_spec, *OPTS)

        return retcode == 0
Exemple #5
0
def build_test(cnt, bldconfig, *options, **kwopts):
    options = filter(None, options)
    if kwopts['clean'] and os.path.isdir(out_pattern % cnt):
        # remove/clean the working directory
        shutil.rmtree(out_pattern % cnt)
    compat.exec_python_rc(makespec, script_name,
                          '--out', out_pattern % cnt, bldconfig, *options)
    compat.exec_python_rc(build, os.path.join(out_pattern % cnt, 'hanoi.spec'),
                          '--noconfirm')
    if is_linux:
        # create symlinks
        if os.path.islink('hanoi%d' % cnt):
            os.remove('hanoi%d' % cnt)
        if bldconfig == '--onedir':
            os.symlink(dist_pattern_dir % cnt, 'hanoi%d' % cnt)
        else:
            os.symlink(dist_pattern_file % cnt, 'hanoi%d' % cnt)
Exemple #6
0
def __exec_python_script(script_filename, pathex):
    # Prepare the environment - default to 'os.environ'...
    env = os.environ.copy()
    # ... and prepend PYTHONPATH with pathex
    if 'PYTHONPATH' in env:
        pathex = os.pathsep.join([pathex, env['PYTHONPATH']])
    env['PYTHONPATH'] = pathex
    # Run the test script
    return exec_python_rc(script_filename, env=env)
Exemple #7
0
 def _check_modules(self, test_name):
     """
     Return name of missing required module, if any. None means
     no module is missing.
     """
     if test_name in self.MODULES:
         for mod_name in self.MODULES[test_name]:
             retcode = compat.exec_python_rc('-c', "import %s" % mod_name)
             if retcode != 0:
                 return mod_name
     return None
Exemple #8
0
 def _check_modules(self, test_name):
     """
     Return name of missing required module, if any. None means
     no module is missing.
     """
     if test_name in self.MODULES:
         for mod_name in self.MODULES[test_name]:
             retcode = compat.exec_python_rc('-c', "import %s" % mod_name)
             if retcode != 0:
                 return mod_name
     return None
Exemple #9
0
 def _check_modules(self, test_name):
     """
     Return name of missing required module, if any. None means
     no module is missing.
     """
     if test_name in self.MODULES:
         for mod_name in self.MODULES[test_name]:
             # STDOUT and STDERR are discarded (devnull) to hide
             # import exceptions.
             with open(os.devnull) as trash:
                 retcode = compat.exec_python_rc('-c', "import %s" % mod_name,
                                                 stdout=trash, stderr=trash)
             if retcode != 0:
                 return mod_name
     return None
Exemple #10
0
    def test_building(self):
        """
        Run building of test script.

        Return True if build succeded False otherwise.
        """
        OPTS = ['--debug']

        if self.verbose:
            OPTS.extend(['--debug', '--log-level=INFO'])
        else:
            OPTS.append('--log-level=ERROR')

        # Build executable in onefile mode.
        if self.test_file.startswith('test_onefile'):
            OPTS.append('--onefile')
        else:
            OPTS.append('--onedir')

        self._msg("BUILDING TEST " + self.test_name)

        # Use pyinstaller.py for building test_name.
        testfile_spec = self.test_file + '.spec'
        if not os.path.exists(self.test_file + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script.
            testfile_spec = self.test_file + '.py'

        pyinst_script = os.path.join(HOMEPATH, 'pyinstaller.py')

        # In report mode is stdout and sys.stderr redirected.
        if self.report:
            # Write output from subprocess to stdout/err.
            retcode, out, err = compat.exec_python_all(pyinst_script,
                                                       testfile_spec, *OPTS)
            sys.stdout.write(out)
            sys.stdout.write(err)
        else:
            retcode = compat.exec_python_rc(pyinst_script, testfile_spec,
                                            *OPTS)

        return retcode == 0
Exemple #11
0
    def test_building(self):
        """
        Run building of test script.

        Return True if build succeded False otherwise.
        """
        OPTS = ['--debug']

        if self.verbose:
            OPTS.extend(['--debug', '--log-level=INFO'])
        else:
            OPTS.append('--log-level=ERROR')

        # Build executable in onefile mode.
        if self.test_file.startswith('test_onefile'):
            OPTS.append('--onefile')
        else:
            OPTS.append('--onedir')

        self._msg("BUILDING TEST " + self.test_name)

        # Use pyinstaller.py for building test_name.
        testfile_spec = self.test_file + '.spec'
        if not os.path.exists(self.test_file + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script.
            testfile_spec = self.test_file + '.py'

        pyinst_script = os.path.join(HOMEPATH, 'pyinstaller.py')

        # In report mode is stdout and sys.stderr redirected.
        if self.report:
            # Write output from subprocess to stdout/err.
            retcode, out, err = compat.exec_python_all(pyinst_script,
                  testfile_spec, *OPTS)
            sys.stdout.write(out)
            sys.stdout.write(err)
        else:
            retcode = compat.exec_python_rc(pyinst_script,
                  testfile_spec, *OPTS)

        return retcode == 0
Exemple #12
0
#!/usr/bin/env python

import subprocess
import sys

from PyInstaller.compat import exec_python_rc
from wx.tools.pywxrc import XmlResourceCompiler

XmlResourceCompiler().MakePythonModule(["vgaming.xrc"],
                                       "vgaming_xrc.py",
                                       embedResources=True,
                                       generateGetText=True,
                                       assignVariables=False)

retcode = exec_python_rc("-OO", "-m", "PyInstaller", "vgaming.spec")
if retcode:
    raise subprocess.CalledProcessError(retcode, sys.executable)
Exemple #13
0
def runtests(alltests, filters=None, run_executable=1, verbose=False):
    # Use path separator '/' even on windows for test names.
    if is_win:
        alltests = [x.replace('\\', '/') for x in alltests]

    info = "Executing PyInstaller tests in: %s" % os.getcwd()
    print "*" * min(80, len(info))
    print info
    print "*" * min(80, len(info))

    OPTS = ['--skip-configure', '--debug']

    build_python = open('basic/python_exe.build', 'w')
    build_python.write(sys.executable + "\n")
    build_python.write('debug=%s' % __debug__ + '\n')
    build_python.close()

    if not filters:
        tests = alltests
    else:
        tests = []
        for part in filters:
            tests += [t for t in alltests if part in t and t not in tests]

    tests = [(len(x), x) for x in tests]
    tests.sort()
    counter = {"passed": [], "failed": [], "skipped": []}

    # run configure phase only once
    compat.exec_python_rc(os.path.join(HOMEPATH, 'utils', 'Configure.py'))

    # execute tests
    testbasedir = os.getcwdu()
    for _, test in tests:
        test = os.path.splitext(test)[0]
        if not os.path.exists(test + '.py'):
            _msg("Testfile not found:", test + '.py', short=1)
            counter["failed"].append(test)
            continue
        testdir, testfile = os.path.split(test)
        if not testdir:
            testdir = '.'
        elif not os.path.exists(testdir):
            os.makedirs(testdir)
        os.chdir(testdir)  # go to testdir
        if test in MIN_VERSION_OR_OS and not MIN_VERSION_OR_OS[test]:
            counter["skipped"].append(test)
            os.chdir(testbasedir)  # go back from testdir
            continue
        if test in DEPENDENCIES:
            failed = False
            for mod in DEPENDENCIES[test]:
                res = compat.exec_python_rc('-c', "import %s" % mod)
                if res != 0:
                    failed = True
                    break
            if failed:
                if verbose:
                    print "Skipping test because module %s is missing" % mod
                counter["skipped"].append(test)
                os.chdir(testbasedir)  # go back from testdir
                continue
        _msg("BUILDING TEST", test)

        # use pyinstaller.py for building tests
        testfile_spec = testfile + '.spec'
        if not os.path.exists(testfile + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script
            testfile_spec = testfile + '.py'

        res = compat.exec_python_rc(os.path.join(HOMEPATH, 'pyinstaller.py'),
                          testfile_spec, *OPTS)
        if res == 0 and run_executable:
            files = glob.glob(os.path.join('dist', testfile + '*'))
            for exe in files:
                exe = os.path.splitext(exe)[0]
                res_tmp = test_exe(exe[5:], testdir)
                res = res or res_tmp

        # compare log files (now used only by multipackage tests)
        logsfn = glob.glob(testfile + '.toc')
        # other main scritps do not start with 'test_'
        logsfn += glob.glob(testfile.split('_', 1)[1] + '_?.toc')
        for logfn in logsfn:
            _msg("EXECUTING MATCHING", logfn)
            tmpname = os.path.splitext(logfn)[0]
            prog = find_exepath(tmpname)
            if prog is None:
                prog = find_exepath(tmpname, os.path.join('dist', testfile))
            fname_list = compat.exec_python(
                os.path.join(HOMEPATH, 'utils', 'ArchiveViewer.py'),
                '-b', '-r', prog)
            fname_list = eval(fname_list)
            pattern_list = eval(open(logfn, 'rU').read())
            count = 0
            for pattern in pattern_list:
                found = False
                for fname in fname_list:
                    if re.match(pattern, fname):
                        count += 1
                        found = True
                        if verbose:
                            print "MATCH: %s --> %s" % (pattern, fname)
                        break
                if not found:
                    if verbose:
                        print "MISSING: %s" % pattern
            if count < len(pattern_list):
                res = 1
                print "Matching FAILED!"
            else:
                print "Matching SUCCESS!"

        if res == 0:
            _msg("FINISHING TEST", test, short=1)
            counter["passed"].append(test)
        else:
            _msg("TEST", test, "FAILED", short=1, sep="!!")
            counter["failed"].append(test)
        os.chdir(testbasedir)  # go back from testdir
    pprint.pprint(counter)
Exemple #14
0
def runtests(alltests, filters=None, run_executable=1, verbose=False):
    # Use path separator '/' even on windows for test names.
    if is_win:
        alltests = [x.replace('\\', '/') for x in alltests]

    info = "Executing PyInstaller tests in: %s" % os.getcwd()
    print "*" * min(80, len(info))
    print info
    print "*" * min(80, len(info))

    OPTS = ['--skip-configure', '--debug']

    build_python = open('basic/python_exe.build', 'w')
    build_python.write(sys.executable + "\n")
    build_python.write('debug=%s' % __debug__ + '\n')
    build_python.close()

    if not filters:
        tests = alltests
    else:
        tests = []
        for part in filters:
            tests += [t for t in alltests if part in t and t not in tests]

    tests = [(len(x), x) for x in tests]
    tests.sort()
    counter = {"passed": [], "failed": [], "skipped": []}

    # run configure phase only once
    compat.exec_python_rc(os.path.join(HOMEPATH, 'utils', 'Configure.py'))

    # execute tests
    testbasedir = os.getcwdu()
    for _, test in tests:
        test = os.path.splitext(test)[0]
        if not os.path.exists(test + '.py'):
            _msg("Testfile not found:", test + '.py', short=1)
            counter["failed"].append(test)
            continue
        testdir, testfile = os.path.split(test)
        if not testdir:
            testdir = '.'
        elif not os.path.exists(testdir):
            os.makedirs(testdir)
        os.chdir(testdir)  # go to testdir
        if test in MIN_VERSION_OR_OS and not MIN_VERSION_OR_OS[test]:
            counter["skipped"].append(test)
            os.chdir(testbasedir)  # go back from testdir
            continue
        if test in DEPENDENCIES:
            failed = False
            for mod in DEPENDENCIES[test]:
                res = compat.exec_python_rc('-c', "import %s" % mod)
                if res != 0:
                    failed = True
                    break
            if failed:
                if verbose:
                    print "Skipping test because module %s is missing" % mod
                counter["skipped"].append(test)
                os.chdir(testbasedir)  # go back from testdir
                continue
        _msg("BUILDING TEST", test)

        # use pyinstaller.py for building tests
        testfile_spec = testfile + '.spec'
        if not os.path.exists(testfile + '.spec'):
            # .spec file does not exist and it has to be generated
            # for main script
            testfile_spec = testfile + '.py'

        res = compat.exec_python_rc(os.path.join(HOMEPATH, 'pyinstaller.py'),
                                    testfile_spec, *OPTS)
        if res == 0 and run_executable:
            files = glob.glob(os.path.join('dist', testfile + '*'))
            for exe in files:
                exe = os.path.splitext(exe)[0]
                res_tmp = test_exe(exe[5:], testdir)
                res = res or res_tmp

        # compare log files (now used only by multipackage tests)
        logsfn = glob.glob(testfile + '.toc')
        # other main scritps do not start with 'test_'
        logsfn += glob.glob(testfile.split('_', 1)[1] + '_?.toc')
        for logfn in logsfn:
            _msg("EXECUTING MATCHING", logfn)
            tmpname = os.path.splitext(logfn)[0]
            prog = find_exepath(tmpname)
            if prog is None:
                prog = find_exepath(tmpname, os.path.join('dist', testfile))
            fname_list = compat.exec_python(
                os.path.join(HOMEPATH, 'utils', 'ArchiveViewer.py'), '-b',
                '-r', prog)
            fname_list = eval(fname_list)
            pattern_list = eval(open(logfn, 'rU').read())
            count = 0
            for pattern in pattern_list:
                found = False
                for fname in fname_list:
                    if re.match(pattern, fname):
                        count += 1
                        found = True
                        if verbose:
                            print "MATCH: %s --> %s" % (pattern, fname)
                        break
                if not found:
                    if verbose:
                        print "MISSING: %s" % pattern
            if count < len(pattern_list):
                res = 1
                print "Matching FAILED!"
            else:
                print "Matching SUCCESS!"

        if res == 0:
            _msg("FINISHING TEST", test, short=1)
            counter["passed"].append(test)
        else:
            _msg("TEST", test, "FAILED", short=1, sep="!!")
            counter["failed"].append(test)
        os.chdir(testbasedir)  # go back from testdir
    pprint.pprint(counter)