Exemplo n.º 1
0
def update(no_auto_update=False, no_min=False, force_update=False):
    """Update the systrace trace viewer html file.

  When the html file exists, do not update the file if
  1. the revision is NO_AUTO_UPDATE_;
  2. or the revision is not changed.

  Args:
    no_auto_update: If true, force updating the file with revision
                    NO_AUTO_UPDATE_. Future auto-updates will be skipped.
    no_min:         If true, skip minification when updating the file.
    force_update:   If true, update the systrace trace viewer file no matter
                    what.
  """
    if no_auto_update:
        new_rev = NO_AUTO_UPDATE_
    else:
        new_rev = get_catapult_rev_in_git_()
        if not new_rev:
            # Source tree could be missing git metadata.
            print >> sys.stderr, 'Warning: Couldn\'t determine current git revision.'
            new_rev = UNKNOWN_REVISION_

    need_update = False
    if force_update:
        need_update = True
    elif no_auto_update:
        need_update = True
    elif not os.path.exists(SYSTRACE_TRACE_VIEWER_HTML_FILE):
        need_update = True
    else:
        old_rev = get_catapult_rev_in_file_(SYSTRACE_TRACE_VIEWER_HTML_FILE)
        if not old_rev or old_rev == UNKNOWN_REVISION_:
            need_update = True
        # If old_rev was set to NO_AUTO_UPDATE_ it should be skipped, since forced
        # update cases have been already handled above.
        if old_rev != new_rev and old_rev != NO_AUTO_UPDATE_:
            need_update = True

    if not need_update:
        print 'Update skipped.'
        return

    print 'Generating viewer file %s with revision %s.' % (
        SYSTRACE_TRACE_VIEWER_HTML_FILE, new_rev)

    # Generate the vulcanized result.
    with codecs.open(SYSTRACE_TRACE_VIEWER_HTML_FILE,
                     encoding='utf-8',
                     mode='w') as f:
        vulcanize_trace_viewer.WriteTraceViewer(
            f,
            config_name='full',
            minify=(not no_min),
            output_html_head_and_body=False)
        if not force_update:
            f.write(create_catapult_rev_str_(new_rev))
 def testWriteHTMLForTracesToFile(self):
     try:
         # Note: We can't use "with" when working with tempfile.NamedTemporaryFile
         # as that does not work on Windows. We use the longer, more clunky version
         # instead. See https://bugs.python.org/issue14243 for detials.
         raw_tmpfile = tempfile.NamedTemporaryFile(mode='w',
                                                   suffix='.html',
                                                   delete=False)
         raw_tmpfile.close()
         with codecs.open(raw_tmpfile.name, 'w',
                          encoding='utf-8') as tmpfile:
             vulcanize_trace_viewer.WriteTraceViewer(tmpfile)
     finally:
         os.remove(raw_tmpfile.name)
def update(no_auto_update=False, no_min=False, force_update=False):
    """Update the systrace trace viewer html file.

  When the html file exists, do not update the file if
  1. the revision is NO_AUTO_UPDATE_;
  2. or the revision is not changed.

  Args:
    no_auto_update: If true, force updating the file with revision
                    NO_AUTO_UPDATE_. Future updates will be skipped unless this
                    argument is true again.
    no_min:         If true, skip minification when updating the file.
    force_update:   If true, update the systrace trace viewer file no matter
                    what.
  """
    new_rev = None
    if not force_update:
        if no_auto_update:
            new_rev = NO_AUTO_UPDATE_
        else:
            new_rev = get_catapult_rev_in_git_()
            if not new_rev:
                return

            if os.path.exists(SYSTRACE_TRACE_VIEWER_HTML_FILE):
                rev_in_file = get_catapult_rev_in_file_(
                    SYSTRACE_TRACE_VIEWER_HTML_FILE)
                if rev_in_file == NO_AUTO_UPDATE_ or rev_in_file == new_rev:
                    return

    if force_update and not new_rev:
        new_rev = "none"

    print 'Generating viewer file %s with revision %s.' % (
        SYSTRACE_TRACE_VIEWER_HTML_FILE, new_rev)

    # Generate the vulcanized result.
    with codecs.open(SYSTRACE_TRACE_VIEWER_HTML_FILE,
                     encoding='utf-8',
                     mode='w') as f:
        vulcanize_trace_viewer.WriteTraceViewer(
            f,
            config_name='full',
            minify=(not no_min),
            output_html_head_and_body=False)
        if not force_update:
            f.write(create_catapult_rev_str_(new_rev))