# vim: set fileencoding=utf-8 : # # (C) 2013 Guido Günther # 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 3 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 # # Some Pom parsing handling class Version(object): def __init__(self, text): self._version = text.strip() def is_subst(self): """ Wheter a version is subject to variable substitution >>> Version('1.0').is_subst() False >>> Version('${version}').is_subst() True >>> Version('foo-${version}-bar').is_subst() True >>> Version('${version}-bar').is_subst() True >>> Version('foo-${version}').is_subst() True """ if '${' in self._version: return True if '}' in self._version.split('${')[1] else False else: return False def is_snapshot(self): """ Wheter a version is a snapthot version >>> Version('1.0').is_snapshot() False >>> Version('1.0-SNAPSHOT').is_snapshot() True """ return self._version.endswith('-SNAPSHOT') def __str__(self): return self._version def __eq__(self, arg): # Make sure we can compare versions in string context if isinstance(arg, (str, unicode)): return self._version.__eq__(arg) else: return super(Version, self).__eq__(arg)