def testGenerateHtmlIndexTupleDupe(self):
   """Verifies GenerateHtmlIndex gives us something unique (input: tuple)"""
   index = os.path.join(self.tempdir, 'index.html')
   files = ('file1', 'file1', 'file1',)
   commands.GenerateHtmlIndex(index, files)
   html = osutils.ReadFile(index)
   self.assertEqual(html.count('>file1</a>'), 1)
Пример #2
0
def GenerateHtmlIndex(files, index, board, version):
    """Given the list of |files|, generate an index.html at |index|.

  Args:
    files: The list of files to link to.
    index: The path to the html index.
    board: Name of the board this index is for.
    version: Build version this index is for.
  """
    head = """<html>
<head>
 <title>Package Prebuilt Index: %(board)s / %(version)s</title>
</head>
<body>
<h2>Package Prebuilt Index: %(board)s / %(version)s</h2>"""
    head %= {
        'board': board,
        'version': version,
    }

    files = files + [
        '.|Google Storage Index',
        '..|',
    ]
    commands.GenerateHtmlIndex(index, files, head=head)
 def testGenerateHtmlIndexTuple(self):
   """Verifies GenerateHtmlIndex gives us something sane (input: tuple)"""
   index = os.path.join(self.tempdir, 'index.html')
   files = ('file1', 'monkey tree', 'flying phone',)
   commands.GenerateHtmlIndex(index, files)
   html = osutils.ReadFile(index)
   for f in files:
     self.assertIn('>%s</a>' % f, html)
Пример #4
0
    def _UploadArchiveIndex(self, builder_run):
        """Upload an HTML index for the artifacts at remote archive location.

    If there are no artifacts in the archive then do nothing.

    Args:
      builder_run: BuilderRun object for this run.

    Returns:
      If an index file is uploaded then a dict is returned where each value
        is the same (the URL for the uploaded HTML index) and the keys are
        the boards it applies to, including None if applicable.  If no index
        file is uploaded then this returns None.
    """
        archive = builder_run.GetArchive()
        archive_path = archive.archive_path

        config = builder_run.config
        boards = config.boards
        if boards:
            board_names = ' '.join(boards)
        else:
            boards = [None]
            board_names = '<no board>'

        # See if there are any artifacts found for this run.
        uploaded = os.path.join(archive_path, commands.UPLOADED_LIST_FILENAME)
        if not os.path.exists(uploaded):
            # UPLOADED doesn't exist.  Normal if Archive stage never ran, which
            # is possibly normal.  Regardless, no archive index is needed.
            logging.info('No archived artifacts found for %s run (%s)',
                         builder_run.config.name, board_names)
        else:
            # Prepare html head.
            head_data = {
                'board': board_names,
                'config': config.name,
                'version': builder_run.GetVersion(),
            }
            head = self._HTML_HEAD % head_data

            files = osutils.ReadFile(uploaded).splitlines() + [
                '.|Google Storage Index',
                '..|',
            ]
            index = os.path.join(archive_path, 'index.html')
            # TODO (sbasi) crbug.com/362776: Rework the way we do uploading to
            # multiple buckets. Currently this can only be done in the Archive Stage
            # therefore index.html will only end up in the normal Chrome OS bucket.
            commands.GenerateHtmlIndex(index,
                                       files,
                                       url_base=archive.download_url,
                                       head=head)
            commands.UploadArchivedFile(archive_path, [archive.upload_url],
                                        os.path.basename(index),
                                        debug=self._run.debug,
                                        acl=self.acl)
            return dict((b, archive.download_url) for b in boards)
 def testGenerateHtmlIndexFile(self):
   """Verifies GenerateHtmlIndex gives us something sane (input: file)"""
   index = os.path.join(self.tempdir, 'index.html')
   files = ('a.tgz', 'b b b.txt', 'c', 'dalsdkjfasdlkf',)
   filelist = os.path.join(self.tempdir, 'listing')
   osutils.WriteFile(filelist, '\n'.join(files))
   commands.GenerateHtmlIndex(index, filelist)
   html = osutils.ReadFile(index)
   for f in files:
     self.assertIn('>%s</a>' % f, html)
 def testGenerateHtmlIndexTuplePretty(self):
   """Verifies GenerateHtmlIndex gives us something pretty (input: tuple)"""
   index = os.path.join(self.tempdir, 'index.html')
   files = ('..|up', 'f.txt|MY FILE', 'm.log|MONKEY', 'b.bin|Yander',)
   commands.GenerateHtmlIndex(index, files)
   html = osutils.ReadFile(index)
   for f in files:
     a = f.split('|')
     self.assertIn('href="%s"' % a[0], html)
     self.assertIn('>%s</a>' % a[1], html)
 def testGenerateHtmlIndexDir(self):
   """Verifies GenerateHtmlIndex gives us something sane (input: dir)"""
   index = os.path.join(self.tempdir, 'index.html')
   files = ('a', 'b b b', 'c', 'dalsdkjfasdlkf',)
   simple_dir = os.path.join(self.tempdir, 'dir')
   for f in files:
     osutils.Touch(os.path.join(simple_dir, f), makedirs=True)
   commands.GenerateHtmlIndex(index, files)
   html = osutils.ReadFile(index)
   for f in files:
     self.assertIn('>%s</a>' % f, html)
Пример #8
0
def GenerateHtmlIndex(files, index, board, version):
    """Given the list of |files|, generate an index.html at |index|.

  Args:
    files: The list of files to link to.
    index: The path to the html index.
    board: Name of the board this index is for.
    version: Build version this index is for.
  """
    title = 'Package Prebuilt Index: %s / %s' % (board, version)

    files = files + [
        '.|Google Storage Index',
        '..|',
    ]
    commands.GenerateHtmlIndex(index, files, title=title)
Пример #9
0
def GenerateHtmlIndex(files, index, board, version, remote_location):
  """Given the list of |files|, generate an index.html at |index|.

  Args:
    files: The list of files to link to.
    index: The path to the html index.
    board: Name of the board this index is for.
    version: Build version this index is for.
    remote_location: Remote gs location prebuilts are uploaded to.
  """
  title = 'Package Prebuilt Index: %s / %s' % (board, version)

  files = files + [
      '.|Google Storage Index',
      '..|',
  ]
  commands.GenerateHtmlIndex(index, files, title=title,
                             url_base=gs.GsUrlToHttp(remote_location))
Пример #10
0
    def _LinkArtifacts(self, builder_run):
        """Upload an HTML index for the artifacts at remote archive location.

    If there are no artifacts in the archive then do nothing.

    Args:
      builder_run: BuilderRun object for this run.
    """
        archive = builder_run.GetArchive()
        archive_path = archive.archive_path

        boards = builder_run.config.boards
        if boards:
            board_names = ' '.join(boards)
        else:
            boards = [None]
            board_names = '<no board>'

        # See if there are any artifacts found for this run.
        uploaded = os.path.join(archive_path, commands.UPLOADED_LIST_FILENAME)
        if not os.path.exists(uploaded):
            # UPLOADED doesn't exist.  Normal if Archive stage never ran, which
            # is possibly normal.  Regardless, no archive index is needed.
            logging.info('No archived artifacts found for %s run (%s)',
                         builder_run.config.name, board_names)
            return

        if builder_run.config.internal:
            # Internal builds simply link to pantheon directories, which require
            # authenticated access that most Googlers should have.
            artifacts_url = archive.download_url

        else:
            # External builds must allow unauthenticated access to build artifacts.
            # GS doesn't let unauthenticated users browse selected locations without
            # being able to browse everything (which would expose secret stuff).
            # So, we upload an index.html file and link to it instead of the
            # directory.
            title = 'Artifacts Index: %(board)s / %(version)s (%(config)s config)' % {
                'board': board_names,
                'config': builder_run.config.name,
                'version': builder_run.GetVersion(),
            }

            files = osutils.ReadFile(uploaded).splitlines() + [
                '.|Google Storage Index',
                '..|',
            ]

            index = os.path.join(archive_path, 'index.html')

            # TODO (sbasi) crbug.com/362776: Rework the way we do uploading to
            # multiple buckets. Currently this can only be done in the Archive Stage
            # therefore index.html will only end up in the normal Chrome OS bucket.
            commands.GenerateHtmlIndex(index, files, title=title)
            commands.UploadArchivedFile(archive_path, [archive.upload_url],
                                        os.path.basename(index),
                                        debug=self._run.debug,
                                        acl=self.acl)

            artifacts_url = os.path.join(archive.download_url_file,
                                         'index.html')

        links_build_description = '%s/%s' % (builder_run.config.name,
                                             archive.version)
        logging.PrintBuildbotLink('Artifacts[%s]' % links_build_description,
                                  artifacts_url)