1
# Copyright (C) 2010 Canonical Limited
4
# This file is part of bzr-builddeb.
6
# bzr-builddeb is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# bzr-builddeb is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with bzr-builddeb; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
"""Tagging related functions for bzr-builddeb."""
22
__all__ = ['is_upstream_tag', 'upstream_tag_version']
24
def is_upstream_tag(tag):
25
"""Return true if tag is an upstream tag.
27
:param tag: The string name of the tag.
28
:return: True if the tag name is one generated by upstream tag operations.
30
>>> is_upstream_tag('2.1')
32
>>> is_upstream_tag('upstream-2.1')
35
return tag.startswith('upstream-') or tag.startswith('upstream/')
38
def upstream_tag_version(tag):
39
"""Return the upstream version portion of an upstream tag name.
41
:param tag: The string name of the tag.
42
:return: The version portion of the tag.
44
>>> upstream_tag_version('upstream-2.1')
47
assert is_upstream_tag(tag), "Not an upstream tag: %s" % tag
48
if tag.startswith('upstream/'):
49
tag = tag[len('upstream/'):]
50
elif tag.startswith('upstream-'):
51
tag = tag[len('upstream-'):]
52
if tag.startswith('debian-'):
53
tag = tag[len('debian-'):]
54
elif tag.startswith('ubuntu-'):
55
tag = tag[len('ubuntu-'):]