12bde8e466a4451c7319e3a072d118917957d6554Steve Block# Copyright (C) 2011 Google Inc. All rights reserved.
22bde8e466a4451c7319e3a072d118917957d6554Steve Block#
32bde8e466a4451c7319e3a072d118917957d6554Steve Block# Redistribution and use in source and binary forms, with or without
42bde8e466a4451c7319e3a072d118917957d6554Steve Block# modification, are permitted provided that the following conditions are
52bde8e466a4451c7319e3a072d118917957d6554Steve Block# met:
62bde8e466a4451c7319e3a072d118917957d6554Steve Block#
72bde8e466a4451c7319e3a072d118917957d6554Steve Block#     * Redistributions of source code must retain the above copyright
82bde8e466a4451c7319e3a072d118917957d6554Steve Block# notice, this list of conditions and the following disclaimer.
92bde8e466a4451c7319e3a072d118917957d6554Steve Block#     * Redistributions in binary form must reproduce the above
102bde8e466a4451c7319e3a072d118917957d6554Steve Block# copyright notice, this list of conditions and the following disclaimer
112bde8e466a4451c7319e3a072d118917957d6554Steve Block# in the documentation and/or other materials provided with the
122bde8e466a4451c7319e3a072d118917957d6554Steve Block# distribution.
132bde8e466a4451c7319e3a072d118917957d6554Steve Block#     * Neither the name of Google Inc. nor the names of its
142bde8e466a4451c7319e3a072d118917957d6554Steve Block# contributors may be used to endorse or promote products derived from
152bde8e466a4451c7319e3a072d118917957d6554Steve Block# this software without specific prior written permission.
162bde8e466a4451c7319e3a072d118917957d6554Steve Block#
172bde8e466a4451c7319e3a072d118917957d6554Steve Block# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182bde8e466a4451c7319e3a072d118917957d6554Steve Block# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202bde8e466a4451c7319e3a072d118917957d6554Steve Block# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212bde8e466a4451c7319e3a072d118917957d6554Steve Block# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222bde8e466a4451c7319e3a072d118917957d6554Steve Block# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232bde8e466a4451c7319e3a072d118917957d6554Steve Block# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242bde8e466a4451c7319e3a072d118917957d6554Steve Block# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252bde8e466a4451c7319e3a072d118917957d6554Steve Block# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262bde8e466a4451c7319e3a072d118917957d6554Steve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272bde8e466a4451c7319e3a072d118917957d6554Steve Block# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282bde8e466a4451c7319e3a072d118917957d6554Steve Block
292bde8e466a4451c7319e3a072d118917957d6554Steve Blockimport os
302bde8e466a4451c7319e3a072d118917957d6554Steve Block
312bde8e466a4451c7319e3a072d118917957d6554Steve Blockfrom webkitpy.tool.steps.abstractstep import AbstractStep
322bde8e466a4451c7319e3a072d118917957d6554Steve Blockfrom webkitpy.tool.steps.options import Options
332bde8e466a4451c7319e3a072d118917957d6554Steve Block
342bde8e466a4451c7319e3a072d118917957d6554Steve Block
352bde8e466a4451c7319e3a072d118917957d6554Steve Blockclass AttachToBug(AbstractStep):
362bde8e466a4451c7319e3a072d118917957d6554Steve Block    @classmethod
372bde8e466a4451c7319e3a072d118917957d6554Steve Block    def options(cls):
382bde8e466a4451c7319e3a072d118917957d6554Steve Block        return AbstractStep.options() + [
392bde8e466a4451c7319e3a072d118917957d6554Steve Block            Options.comment,
402bde8e466a4451c7319e3a072d118917957d6554Steve Block            Options.description,
412bde8e466a4451c7319e3a072d118917957d6554Steve Block        ]
422bde8e466a4451c7319e3a072d118917957d6554Steve Block
432bde8e466a4451c7319e3a072d118917957d6554Steve Block    def run(self, state):
442bde8e466a4451c7319e3a072d118917957d6554Steve Block        filepath = state["filepath"]
452bde8e466a4451c7319e3a072d118917957d6554Steve Block        bug_id = state["bug_id"]
462bde8e466a4451c7319e3a072d118917957d6554Steve Block        description = self._options.description or filepath.split(os.sep)[-1]
472bde8e466a4451c7319e3a072d118917957d6554Steve Block        comment_text = self._options.comment
482bde8e466a4451c7319e3a072d118917957d6554Steve Block
492bde8e466a4451c7319e3a072d118917957d6554Steve Block        # add_attachment_to_bug fills in the filename from the file path.
502bde8e466a4451c7319e3a072d118917957d6554Steve Block        filename = None
512bde8e466a4451c7319e3a072d118917957d6554Steve Block        self._tool.bugs.add_attachment_to_bug(bug_id, filepath, description, filename, comment_text)
52