WebKitTools/Scripts/webkitpy/common/net/rietveld.py
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 # Copyright (c) 2010 Google Inc. All rights reserved.
       
     2 #
       
     3 # Redistribution and use in source and binary forms, with or without
       
     4 # modification, are permitted provided that the following conditions are
       
     5 # met:
       
     6 #
       
     7 #     * Redistributions of source code must retain the above copyright
       
     8 # notice, this list of conditions and the following disclaimer.
       
     9 #     * Redistributions in binary form must reproduce the above
       
    10 # copyright notice, this list of conditions and the following disclaimer
       
    11 # in the documentation and/or other materials provided with the
       
    12 # distribution.
       
    13 #     * Neither the name of Google Inc. nor the names of its
       
    14 # contributors may be used to endorse or promote products derived from
       
    15 # this software without specific prior written permission.
       
    16 #
       
    17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    28 
       
    29 import logging
       
    30 import os
       
    31 import re
       
    32 import stat
       
    33 
       
    34 import webkitpy.common.config as config
       
    35 from webkitpy.common.system.deprecated_logging import log
       
    36 from webkitpy.common.system.executive import ScriptError
       
    37 import webkitpy.thirdparty.autoinstalled.rietveld.upload as upload
       
    38 
       
    39 
       
    40 class Rietveld(object):
       
    41     def __init__(self, executive, dryrun=False):
       
    42         self.dryrun = dryrun
       
    43         self._executive = executive
       
    44 
       
    45     def url_for_issue(self, codereview_issue):
       
    46         if not codereview_issue:
       
    47             return None
       
    48         return "%s%s" % (config.codereview_server_url, codereview_issue)
       
    49 
       
    50     def post(self, diff, message=None, codereview_issue=None, cc=None):
       
    51         if not message:
       
    52             raise ScriptError("Rietveld requires a message.")
       
    53 
       
    54         # Rietveld has a 100 character limit on message length.
       
    55         if len(message) > 100:
       
    56             message = message[:100]
       
    57 
       
    58         args = [
       
    59             # First argument is empty string to mimic sys.argv.
       
    60             "",
       
    61             "--assume_yes",
       
    62             "--server=%s" % config.codereview_server_host,
       
    63             "--message=%s" % message,
       
    64         ]
       
    65         if codereview_issue:
       
    66             args.append("--issue=%s" % codereview_issue)
       
    67         if cc:
       
    68             args.append("--cc=%s" % cc)
       
    69 
       
    70         if self.dryrun:
       
    71             log("Would have run %s" % args)
       
    72             return
       
    73 
       
    74         # Use RealMain instead of calling upload from the commandline so that
       
    75         # we can pass in the diff ourselves. Otherwise, upload will just use
       
    76         # git diff for git checkouts, which doesn't respect --git-commit.
       
    77         issue, patchset = upload.RealMain(args, data=diff)
       
    78         return issue