def test_running_from_zip(self):
        # Test assumes that it runs from a normal checkout, not a zip.
        self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__]))
        self.assertIsNone(
            zip_package.get_module_zip_archive(sys.modules[__name__]))
        self.assertTrue(
            os.path.abspath(zip_package.get_main_script_path()).startswith(
                test_env.CLIENT_DIR))

        # Build executable zip that calls same functions.
        pkg = zip_package.ZipPackage(self.temp_dir)
        pkg.add_directory(os.path.join(test_env.CLIENT_DIR, 'utils'), 'utils')
        pkg.add_buffer(
            '__main__.py', b'\n'.join([
                b'import sys',
                b'',
                b'from utils import zip_package',
                b'',
                b'print(zip_package.is_zipped_module(sys.modules[__name__]))',
                b'print(zip_package.get_module_zip_archive(sys.modules[__name__]))',
                b'print(zip_package.get_main_script_path())',
            ]))
        zip_file = os.path.join(self.temp_dir, 'out.zip')
        pkg.zip_into_file(zip_file)

        # Run the zip, validate results.
        actual = check_output([sys.executable, zip_file]).strip().splitlines()
        self.assertEqual(['True', zip_file, zip_file], actual)
Ejemplo n.º 2
0
  def test_running_from_zip(self):
    # Test assumes that it runs from a normal checkout, not a zip.
    self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__]))
    self.assertIsNone(zip_package.get_module_zip_archive(sys.modules[__name__]))
    self.assertTrue(os.path.abspath(
        zip_package.get_main_script_path()).startswith(ROOT_DIR))

    # Build executable zip that calls same functions.
    pkg = zip_package.ZipPackage(self.temp_dir)
    pkg.add_directory(os.path.join(ROOT_DIR, 'utils'), 'utils')
    pkg.add_buffer('__main__.py', '\n'.join([
      'import sys',
      '',
      'from utils import zip_package',
      '',
      'print zip_package.is_zipped_module(sys.modules[__name__])',
      'print zip_package.get_module_zip_archive(sys.modules[__name__])',
      'print zip_package.get_main_script_path()',
    ]))
    zip_file = os.path.join(self.temp_dir, 'out.zip')
    pkg.zip_into_file(zip_file)

    # Run the zip, validate results.
    actual = check_output([sys.executable, zip_file]).strip().splitlines()
    self.assertEqual(['True', zip_file, zip_file], actual)
Ejemplo n.º 3
0
  def test_running_from_zip(self):
    # Test assumes that it runs from a normal checkout, not a zip.
    self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__]))
    self.assertIsNone(zip_package.get_module_zip_archive(sys.modules[__name__]))
    self.assertTrue(os.path.abspath(
        zip_package.get_main_script_path()).startswith(ROOT_DIR))

    # Build executable zip that calls same functions.
    pkg = zip_package.ZipPackage(self.temp_dir)
    pkg.add_directory(os.path.join(ROOT_DIR, 'utils'), 'utils')
    pkg.add_buffer('__main__.py', '\n'.join([
      'import sys',
      '',
      'from utils import zip_package',
      '',
      'print zip_package.is_zipped_module(sys.modules[__name__])',
      'print zip_package.get_module_zip_archive(sys.modules[__name__])',
      'print zip_package.get_main_script_path()',
    ]))
    zip_file = os.path.join(self.temp_dir, 'out.zip')
    pkg.zip_into_file(zip_file)

    # Run the zip, validate results.
    proc = subprocess.Popen(
        [sys.executable, zip_file],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
    out, err = proc.communicate()

    actual = out.strip().splitlines()
    expected = ['True', zip_file, zip_file,]
    self.assertEqual(err, '')
    self.assertEqual(actual, expected)
Ejemplo n.º 4
0
from utils import threading_utils
from utils import tools
from utils import zip_package

import auth
import isolateserver


# Absolute path to this file (can be None if running from zip on Mac).
THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None

# Directory that contains this file (might be inside zip package).
BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None

# Directory that contains currently running script file.
if zip_package.get_main_script_path():
  MAIN_DIR = os.path.dirname(
      os.path.abspath(zip_package.get_main_script_path()))
else:
  # This happens when 'import run_isolated' is executed at the python
  # interactive prompt, in that case __file__ is undefined.
  MAIN_DIR = None

# Types of action accepted by link_file().
HARDLINK, HARDLINK_WITH_FALLBACK, SYMLINK, COPY = range(1, 5)

# The name of the log file to use.
RUN_ISOLATED_LOG_FILE = 'run_isolated.log'

# The name of the log to use for the run_test_cases.py command
RUN_TEST_CASES_LOG = 'run_test_cases.log'
Ejemplo n.º 5
0
import os
import signal
import sys
import tempfile
import time
import zipfile

import xsrf_client
from utils import net
from utils import on_error
from utils import subprocess42
from utils import zip_package


# Path to this file or the zip containing this file.
THIS_FILE = os.path.abspath(zip_package.get_main_script_path())


# Sends a maximum of 100kb of stdout per task_update packet.
MAX_CHUNK_SIZE = 102400


# Maximum wait between task_update packet when there's no output.
MAX_PACKET_INTERVAL = 30


# Minimum wait between task_update packet when there's output.
MIN_PACKET_INTERNAL = 10


# Current task_runner_out version.
Ejemplo n.º 6
0
from api import os_utilities

from utils import file_path
from utils import net
from utils import on_error
from utils import subprocess42
from utils import zip_package

from libs import luci_context

import bot_auth
import remote_client


# Path to this file or the zip containing this file.
THIS_FILE = os.path.abspath(zip_package.get_main_script_path())


# Current task_runner_out version.
OUT_VERSION = 3


# On Windows, SIGTERM is actually sent as SIGBREAK since there's no real
# SIGTERM.  SIGBREAK is not defined on posix since it's a pure Windows concept.
SIG_BREAK_OR_TERM = (
    signal.SIGBREAK if sys.platform == 'win32' else signal.SIGTERM)


# Used to implement monotonic_time for a clock that never goes backward.
_last_now = 0
Ejemplo n.º 7
0
import auth
import cipd
import isolateserver
import named_cache

# Absolute path to this file (can be None if running from zip on Mac).
THIS_FILE_PATH = os.path.abspath(__file__.decode(
    sys.getfilesystemencoding())) if __file__ else None

# Directory that contains this file (might be inside zip package).
BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__.decode(
    sys.getfilesystemencoding()) else None

# Directory that contains currently running script file.
if zip_package.get_main_script_path():
    MAIN_DIR = os.path.dirname(
        os.path.abspath(zip_package.get_main_script_path()))
else:
    # This happens when 'import run_isolated' is executed at the python
    # interactive prompt, in that case __file__ is undefined.
    MAIN_DIR = None

# Magic variables that can be found in the isolate task command line.
ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}'
EXECUTABLE_SUFFIX_PARAMETER = '${EXECUTABLE_SUFFIX}'
SWARMING_BOT_FILE_PARAMETER = '${SWARMING_BOT_FILE}'

# The name of the log file to use.
RUN_ISOLATED_LOG_FILE = 'run_isolated.log'
Ejemplo n.º 8
0
from utils import tools
from utils import zip_package

import auth
import isolated_format
import isolateserver


# Absolute path to this file (can be None if running from zip on Mac).
THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None

# Directory that contains this file (might be inside zip package).
BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None

# Directory that contains currently running script file.
if zip_package.get_main_script_path():
    MAIN_DIR = os.path.dirname(os.path.abspath(zip_package.get_main_script_path()))
else:
    # This happens when 'import run_isolated' is executed at the python
    # interactive prompt, in that case __file__ is undefined.
    MAIN_DIR = None

# The name of the log file to use.
RUN_ISOLATED_LOG_FILE = "run_isolated.log"

# The name of the log to use for the run_test_cases.py command
RUN_TEST_CASES_LOG = "run_test_cases.log"


def get_as_zip_package(executable=True):
    """Returns ZipPackage with this module and all its dependencies.