From 00c2b8e57e3b1482af30cd85e14645724c1af706 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guido=20G=C3=BCnther?= Date: Fri, 29 Jul 2011 19:12:16 +0200 Subject: [PATCH] Move GbpPatchQueue and GbpPatch into gbp.pq --- gbp-pq | 119 +---------------------------------------------------- gbp/pq.py | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 117 deletions(-) create mode 100644 gbp/pq.py diff --git a/gbp-pq b/gbp-pq index 138abfc..5ec7373 100755 --- a/gbp-pq +++ b/gbp-pq @@ -30,128 +30,13 @@ from gbp.command_wrappers import (Command, GitCommand, RunAtCommand, GitBranch, CommandExecFailed) from gbp.errors import GbpError import gbp.log +from gbp.pq import PatchQueue PQ_BRANCH_PREFIX = "patch-queue/" PATCH_DIR = "debian/patches/" SERIES_FILE = os.path.join(PATCH_DIR,"series") -class GbpPatch(object): - """ - A patch in a patchqueue - - @ivar path: path to the patch - @type path: string - @ivar topic: the topic of the patch - @type topic: string - @ivar strip: path components to strip (think patch -p) - @type strip: integer - """ - def __init__(self, path, topic=None, strip=None): - self.path = path - self.topic = topic - self.strip = strip - - def __repr__(self): - repr = ">> GbpPatchQueue._read_series(['a/b', \ - 'a -p1', \ - 'a/b -p2'], '.') # doctest:+NORMALIZE_WHITESPACE - [, - , - ] - """ - - queue = GbpPatchQueue() - for line in series: - queue.append(klass._parse_line(line, patch_dir)) - return queue - - @staticmethod - def _get_topic(line): - """ - Get the topic from the path's path - >>> GbpPatchQueue._get_topic("a/b c") - 'a' - >>> GbpPatchQueue._get_topic("asdf") - >>> GbpPatchQueue._get_topic("/asdf") - """ - topic = os.path.dirname(line) - if topic in [ '', '/' ]: - topic = None - return topic - - @staticmethod - def _split_strip(line): - """ - Separate the -p option from the patch name - - >>> GbpPatchQueue._split_strip("asdf -p1") - ('asdf', 1) - >>> GbpPatchQueue._split_strip("a/nice/patch") - ('a/nice/patch', None) - >>> GbpPatchQueue._split_strip("asdf foo") - ('asdf foo', None) - """ - patch = line - strip = None - - split = line.rsplit(None, 1) - if len(split) > 1: - m = re.match('-p(?P[0-9]+)', split[1]) - if m: - patch = split[0] - strip = int(m.group('level')) - - return (patch, strip) - - @classmethod - def _parse_line(klass, line, patch_dir): - """ - Parse a single line from a patch file - - >>> GbpPatchQueue._parse_line("a/b -p1", '/tmp/patches') - - >>> GbpPatchQueue._parse_line("a/b", '.') - - """ - line = line.rstrip() - topic = klass._get_topic(line) - (patch, split) = klass._split_strip(line) - return GbpPatch(os.path.join(patch_dir, patch), topic, split) - - def is_pq_branch(branch): """ is branch a patch-queue branch? @@ -298,7 +183,7 @@ def import_quilt_patches(repo, branch, series): % pq_branch) repo.set_branch(pq_branch) - queue = GbpPatchQueue.read_series_file(series) + queue = PatchQueue.read_series_file(series) for patch in queue: gbp.log.debug("Applying %s" % patch.path) apply_and_commit_patch(repo, patch.path, patch.topic) diff --git a/gbp/pq.py b/gbp/pq.py new file mode 100644 index 0000000..39eb6a0 --- /dev/null +++ b/gbp/pq.py @@ -0,0 +1,137 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2011 Guido Guenther +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +import re +from errors import GbpError + +class Patch(object): + """ + A patch in a patchqueue + + @ivar path: path to the patch + @type path: string + @ivar topic: the topic of the patch + @type topic: string + @ivar strip: path components to strip (think patch -p) + @type strip: integer + """ + def __init__(self, path, topic=None, strip=None): + self.path = path + self.topic = topic + self.strip = strip + + def __repr__(self): + repr = ">> PatchQueue._read_series(['a/b', \ + 'a -p1', \ + 'a/b -p2'], '.') # doctest:+NORMALIZE_WHITESPACE + [, + , + ] + """ + + queue = PatchQueue() + for line in series: + queue.append(klass._parse_line(line, patch_dir)) + return queue + + @staticmethod + def _get_topic(line): + """ + Get the topic from the path's path + >>> PatchQueue._get_topic("a/b c") + 'a' + >>> PatchQueue._get_topic("asdf") + >>> PatchQueue._get_topic("/asdf") + """ + topic = os.path.dirname(line) + if topic in [ '', '/' ]: + topic = None + return topic + + @staticmethod + def _split_strip(line): + """ + Separate the -p option from the patch name + + >>> PatchQueue._split_strip("asdf -p1") + ('asdf', 1) + >>> PatchQueue._split_strip("a/nice/patch") + ('a/nice/patch', None) + >>> PatchQueue._split_strip("asdf foo") + ('asdf foo', None) + """ + patch = line + strip = None + + split = line.rsplit(None, 1) + if len(split) > 1: + m = re.match('-p(?P[0-9]+)', split[1]) + if m: + patch = split[0] + strip = int(m.group('level')) + + return (patch, strip) + + @classmethod + def _parse_line(klass, line, patch_dir): + """ + Parse a single line from a patch file + + >>> PatchQueue._parse_line("a/b -p1", '/tmp/patches') + + >>> PatchQueue._parse_line("a/b", '.') + + """ + line = line.rstrip() + topic = klass._get_topic(line) + (patch, split) = klass._split_strip(line) + return Patch(os.path.join(patch_dir, patch), topic, split) + + -- 2.7.4