#!/usr/bin/env python # # Copyright 2008 Orcan Ogetbil # # Date: 2008/11/20 # Ver: 0.2 # # 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 translate; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import SpecCheck import reviewspec from Filter import * import re # Allowed expressions for the buildroot tag by Fedora: buildroot_tag_regex = re.compile(r"(?i)Buildroot[ \t]*:") buildroot_tag_separator = re.compile(r":") buildroot_regex = re.compile(r""" ^[ \t]*%\([ \t]*mktemp[ \t]+-ud[ \t]+%{_tmppath}/%{name}-%{version}-%{release}-XXXXXX[ \t]*\)[ \t]*$ |^[ \t]*%{_tmppath}/%{name}-%{version}-%{release}-root-%\([ \t]*%{__id_u}[ \t]+-n[ \t]*\)[ \t]*$ |^[ \t]*%{_tmppath}/%{name}-%{version}-%{release}-root[ \t]*$ """, re.VERBOSE) prep_regex = re.compile(r"^[ \t]*%{?prep}?") class BuildRootCheck(SpecCheck.SpecCheck): """Check the buildroot tag of the spec file to see if it matches the guidelines.""" def __init__(self): """Sample constructor""" SpecCheck.SpecCheck.__init__(self, "BuildRootCheck") def check(self, spec): """Buildroot Check""" # Parse the spec file and get the buildroot(s) #printInfo(spec, "buildroot-check") file=open(spec.filename, "r") result = file.readlines() file.close() number_of_specified_buildroots = 0 for i in result: if prep_regex.match(i): # No need to parse further than where we match %prep break elif buildroot_tag_regex.match(i): number_of_specified_buildroots = number_of_specified_buildroots + 1 buildroot = buildroot_tag_separator.split(i)[1] if number_of_specified_buildroots > 1: printError(spec, "multiple-buildroots") return elif number_of_specified_buildroots == 0: printError(spec, "no-buildroot") return if buildroot_regex.match(buildroot): printInfo(spec, "buildroot-check", "passed") else: printError(spec, "bad-buildroot", buildroot) # An object to autoregister the check check=BuildRootCheck() if reviewspec.info: addDetails( 'buildroot-check', '''Check the buildroot tag of the spec file to see if it matches the guidelines.\n It needs to be one of these three:\n %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)\n %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)\n %{_tmppath}/%{name}-%{version}-%{release}-root ''', "multiple-buildroots", '''More than one buildroot tags are specified.''', "no-buildroot", '''No buildroot tags are specified.''', "bad-buildroot", '''Buildroot must be set to one of these three expressions: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %{_tmppath}/%{name}-%{version}-%{release}-root''' ) # SpecCheck ends here