2003-07-23 03:32:52 +08:00
#---------------------------------------------------------------
2005-04-16 04:01:46 +08:00
# Project : Mandriva Linux
2003-07-23 03:32:52 +08:00
# Module : rpmlint
# File : NamingPolicyCheck.py
# Version : $Id$
# Author : Michael Scherer
# Created On : Mon May 19 11:25:37 2003
# Purpose : Check package names according to their content.
#---------------------------------------------------------------
from Filter import *
import AbstractCheck
import re
import Config
# could be added.
#
2005-11-28 05:49:15 +08:00
# zope
2003-07-23 03:32:52 +08:00
# abiword2
# alsaplayer-plugin-input
# emacs
# gstreamer
# nautilus
# vlc-plugin
# XFree
2005-11-28 05:49:15 +08:00
# xine
2003-07-23 03:32:52 +08:00
2004-12-05 08:09:59 +08:00
executable_re = re . compile ( ' ^(/usr)?/(s?bin|games)/ \ S+ ' )
2003-08-05 17:58:15 +08:00
simple_naming_policy_re = re . compile ( ' \ ^[a-zA-Z1-9-_]*$ ' ) ;
2003-07-23 03:32:52 +08:00
class NamingPolicyCheck ( AbstractCheck . AbstractCheck ) :
checks_ = [ ]
2005-11-28 05:49:15 +08:00
2003-07-23 03:32:52 +08:00
def __init__ ( self ) :
AbstractCheck . AbstractCheck . __init__ ( self , " NamingPolicyCheck " )
2005-11-28 05:49:15 +08:00
2004-12-05 08:09:59 +08:00
def add_check ( self , pkg_name , name_re , file_re , exception ) :
2003-07-23 03:32:52 +08:00
c = { }
c [ ' pkg_name ' ] = pkg_name
c [ ' name_re ' ] = re . compile ( name_re )
c [ ' file_re ' ] = re . compile ( file_re )
2005-11-28 05:49:15 +08:00
c [ ' exception ' ] = exception
2003-07-23 03:32:52 +08:00
self . checks_ . append ( c )
if Config . info :
2003-08-05 17:58:15 +08:00
if simple_naming_policy_re . search ( name_re ) :
details = " The name sould begin with " + name_re [ 1 : ]
2003-07-23 03:32:52 +08:00
else :
2003-08-05 17:58:15 +08:00
details = " The name should match this regular expression " + name_re
2005-11-28 05:49:15 +08:00
2003-07-23 03:32:52 +08:00
addDetails ( pkg_name + ' -naming-policy-not-applied ' ,
2005-11-28 05:49:15 +08:00
" This package doesn ' t respect the naming policy. \n "
2004-02-09 15:43:26 +08:00
+ details + " . \n It should only be used for separate packages modules. " )
2005-11-28 05:49:15 +08:00
2003-07-23 03:32:52 +08:00
def check ( self , pkg ) :
if pkg . isSource ( ) :
return
2006-06-16 04:21:19 +08:00
list = pkg . files ( ) . keys ( )
2004-02-09 15:43:26 +08:00
if not list :
return
2003-07-23 03:32:52 +08:00
try :
2005-11-28 05:49:15 +08:00
# check for binaries first
executables = 0
for f in list :
if executable_re . search ( f ) :
executables = 1
break
2004-12-05 08:09:59 +08:00
# check for files then
2003-07-23 03:32:52 +08:00
for c in self . checks_ :
2005-11-28 05:49:15 +08:00
exception = 0
if c [ ' exception ' ] and executables :
exception = 1
2004-12-05 08:09:59 +08:00
2003-07-23 03:32:52 +08:00
for f in list :
2006-06-16 04:21:19 +08:00
if c [ ' file_re ' ] . search ( f ) and not c [ ' name_re ' ] . search ( pkg . name ) and not exception :
2003-07-23 03:32:52 +08:00
raise ' naming-policy-not-applied '
2005-11-28 05:49:15 +08:00
except ' naming-policy-not-applied ' :
2003-07-23 03:32:52 +08:00
printWarning ( pkg , c [ ' pkg_name ' ] + ' -naming-policy-not-applied ' , f )
check = NamingPolicyCheck ( )
#
# these are the check currently impleted.
2005-11-28 05:49:15 +08:00
#
2003-07-23 03:32:52 +08:00
# first argument is the name of the check, printed by the warning.
# ex : xmms.
#
# secund argument is the regular expression of the naming policy.
# ex: xmms plugin should be named xmms-name_of_plugin.
#
# third is the path of the file that should contains a package to be related to the naming scheme.
# ex: xmms plugin are put under /usr/lib/xmms/
#
2004-12-05 08:09:59 +08:00
# fourth is a boolean for excepting packages with any executable in path of the naming scheme
# ex: a perl package with files both in /usr/bin and in /usr/lib/perl5 can be either a module with exemple script, of a perl programs with some personal modules
#
# the module is far from being perfect since you need to check this file for the naming file.
#
2003-07-23 03:32:52 +08:00
# the module is far from being perfect since you need to check this file for the naming file.
# if somone as a elegant solution, I will be happy to implement and test it.
2004-12-05 08:09:59 +08:00
check . add_check ( ' xmms ' , ' ^xmms- ' , ' ^/usr/lib/xmms/ ' , 0 )
check . add_check ( ' python ' , ' ^python- ' , ' ^/usr/lib/python[1-9](-[1-9])? ' , 1 )
check . add_check ( ' perl5 ' , ' ^perl- ' , ' ^/usr/lib/perl5/vendor_perl ' , 1 )
check . add_check ( ' apache2 ' , ' ^apache2-mod_ ' , ' ^/usr/lib/apache2- ' , 0 )
check . add_check ( ' fortune ' , ' ^fortune- ' , ' ^/usr/share/games/fortunes/ ' , 0 )
check . add_check ( ' php ' , ' ^php- ' , ' /usr/lib/php/extensions/ ' , 1 )
check . add_check ( ' ruby ' , ' ^ruby- ' , ' /usr/lib/ruby/[1-9](-[1-9])?/ ' , 1 )
check . add_check ( ' ocaml ' , ' ^ocaml- ' , ' /usr/lib/ocaml/ ' , 1 )
2003-07-23 03:32:52 +08:00
2005-11-28 05:49:15 +08:00
# these exception should be added
2003-07-23 03:32:52 +08:00
# apache2 => apache2-devel
# apache2-modules
# ruby => apache2-mod_ruby
# ruby
# NamingPolicyCheck.py ends here
2006-04-01 16:09:17 +08:00
# Local variables:
# indent-tabs-mode: nil
# py-indent-offset: 4
# End:
# ex: ts=4 sw=4 et