def testCreate(self):
        ps = path_set.PathSet()
        self.assertEqual(len(ps), 0)  # Check __len__.
        self.assertFalse(__file__ in ps)
        for _ in ps:  # Check __iter__.
            self.fail('New set is not empty.')

        ps = path_set.PathSet([__file__])
        self.assertEqual(len(ps), 1)
        self.assertTrue(__file__ in ps)
        self.assertEqual(ps.pop(), os.path.realpath(__file__))
Ejemplo n.º 2
0
def FindDependencies(paths, options):
    # Verify arguments.
    for path in paths:
        if not os.path.exists(path):
            raise ValueError('Path does not exist: %s' % path)

    dependencies = path_set.PathSet()

    # Including __init__.py will include Telemetry and its dependencies.
    # If the user doesn't pass any arguments, we just have Telemetry.
    dependencies |= FindPythonDependencies(
        os.path.realpath(
            os.path.join(util.GetTelemetryDir(), 'telemetry', '__init__.py')))
    dependencies |= FindBootstrapDependencies(util.GetTelemetryDir())

    # Add dependencies.
    for path in paths:
        base_dir = os.path.dirname(os.path.realpath(path))

        dependencies.add(base_dir)
        dependencies |= FindBootstrapDependencies(base_dir)
        dependencies |= FindPythonDependencies(path)
        if options.include_page_set_data:
            dependencies |= FindPageSetDependencies(base_dir)

    # Remove excluded files.
    dependencies -= FindExcludedFiles(set(dependencies), options)

    return dependencies
Ejemplo n.º 3
0
def FindDependencies(target_paths, options):
  # Verify arguments.
  for target_path in target_paths:
    if not os.path.exists(target_path):
      raise ValueError('Path does not exist: %s' % target_path)

  dependencies = path_set.PathSet()

  # Including Telemetry's major entry points will (hopefully) include Telemetry
  # and all its dependencies. If the user doesn't pass any arguments, we just
  # have Telemetry.
  dependencies |= FindPythonDependencies(os.path.realpath(
    os.path.join(path.GetTelemetryDir(), 'telemetry', 'benchmark_runner.py')))
  dependencies |= FindPythonDependencies(os.path.realpath(
    os.path.join(path.GetTelemetryDir(),
                 'telemetry', 'unittest_util', 'run_tests.py')))
  dependencies |= FindBootstrapDependencies(path.GetTelemetryDir())

  # Add dependencies.
  for target_path in target_paths:
    base_dir = os.path.dirname(os.path.realpath(target_path))

    dependencies.add(base_dir)
    dependencies |= FindBootstrapDependencies(base_dir)
    dependencies |= FindPythonDependencies(target_path)
    if options.include_page_set_data:
      dependencies |= FindPageSetDependencies(base_dir)

  # Remove excluded files.
  dependencies -= FindExcludedFiles(set(dependencies), options)

  return dependencies
Ejemplo n.º 4
0
def ZipDependencies(paths, dependencies, options):
    base_dir = os.path.dirname(os.path.realpath(util.GetChromiumSrcDir()))

    with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file:
        # Add dependencies to archive.
        for path in dependencies:
            path_in_archive = os.path.join('telemetry',
                                           os.path.relpath(path, base_dir))
            zip_file.write(path, path_in_archive)

        # Add symlinks to executable paths, for ease of use.
        for path in paths:
            link_info = zipfile.ZipInfo(
                os.path.join('telemetry', os.path.basename(path)))
            link_info.create_system = 3  # Unix attributes.
            # 010 is regular file, 0111 is the permission bits rwxrwxrwx.
            link_info.external_attr = 0100777 << 16  # Octal.

            relative_path = os.path.relpath(path, base_dir)
            link_script = (
                '#!/usr/bin/env python\n\n'
                'import os\n'
                'import sys\n\n\n'
                'script = os.path.join(os.path.dirname(__file__), \'%s\')\n'
                'os.execv(sys.executable, [sys.executable, script] + sys.argv[1:])'
                % relative_path)

            zip_file.writestr(link_info, link_script)

        # Add gsutil to the archive, if it's available. The gsutil in
        # depot_tools is modified to allow authentication using prodaccess.
        # TODO: If there's a gsutil in telemetry/third_party/, bootstrap_deps
        # will include it. Then there will be two copies of gsutil at the same
        # location in the archive. This can be confusing for users.
        gsutil_path = os.path.realpath(cloud_storage.FindGsutil())
        if cloud_storage.SupportsProdaccess(gsutil_path):
            gsutil_base_dir = os.path.join(os.path.dirname(gsutil_path),
                                           os.pardir)
            gsutil_dependencies = path_set.PathSet()
            gsutil_dependencies.add(os.path.dirname(gsutil_path))
            # Also add modules from depot_tools that are needed by gsutil.
            gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'boto'))
            gsutil_dependencies.add(
                os.path.join(gsutil_base_dir, 'retry_decorator'))
            gsutil_dependencies -= FindExcludedFiles(set(gsutil_dependencies),
                                                     options)

            # Also add upload.py to the archive from depot_tools, if it is available.
            # This allows us to post patches without requiring a full depot_tools
            # install. There's no real point in including upload.py if we do not
            # also have gsutil, which is why this is inside the gsutil block.
            gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'upload.py'))

            for path in gsutil_dependencies:
                path_in_archive = os.path.join(
                    'telemetry',
                    os.path.relpath(util.GetTelemetryDir(), base_dir),
                    'third_party', os.path.relpath(path, gsutil_base_dir))
                zip_file.write(path, path_in_archive)
 def testDiscard(self):
     ps = path_set.PathSet([__file__])
     ps.discard(__file__)
     self.assertEqual(len(ps), 0)
     self.assertFalse(__file__ in ps)
 def testAdd(self):
     ps = path_set.PathSet()
     ps.add(__file__)
     self.assertEqual(len(ps), 1)
     self.assertTrue(__file__ in ps)
     self.assertEqual(ps.pop(), os.path.realpath(__file__))