2010-12-17 17:32:38 +01:00
|
|
|
#
|
|
|
|
# patch.py - Internal helper class for sponsor-patch
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010, Benjamin Drung <bdrung@ubuntu.com>
|
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
import os
|
2011-05-24 20:22:37 +02:00
|
|
|
|
|
|
|
from ubuntutools import subprocess
|
2010-12-17 17:32:38 +01:00
|
|
|
|
|
|
|
class Patch(object):
|
|
|
|
def __init__(self, patch_file):
|
|
|
|
self.patch_file = patch_file
|
|
|
|
self.full_path = os.path.realpath(self.patch_file)
|
|
|
|
assert os.path.isfile(self.full_path), "%s does not exist." % \
|
|
|
|
(self.full_path)
|
|
|
|
cmd = ["diffstat", "-l", "-p0", self.full_path]
|
|
|
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
changed_files = process.communicate()[0]
|
2010-12-22 23:31:35 +01:00
|
|
|
self.changed_files = [l for l in changed_files.split("\n") if l != ""]
|
2010-12-17 17:32:38 +01:00
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.patch_file
|
|
|
|
|
|
|
|
def get_strip_level(self):
|
|
|
|
strip_level = None
|
|
|
|
if self.is_debdiff():
|
2010-12-27 15:20:49 +01:00
|
|
|
changelog = [f for f in self.changed_files
|
|
|
|
if f.endswith("debian/changelog")][0]
|
2010-12-17 17:32:38 +01:00
|
|
|
strip_level = len(changelog.split(os.sep)) - 2
|
|
|
|
return strip_level
|
|
|
|
|
|
|
|
def is_debdiff(self):
|
2010-12-27 15:20:49 +01:00
|
|
|
return len([f for f in self.changed_files
|
|
|
|
if f.endswith("debian/changelog")]) > 0
|