#NEWLINE# def validate( self , warnings = None ) : #NEWLINE# #INDENT# '\n        makes sure all standards for packages are met\n        :param package: Package to check\n        :param warnings: Print warnings if None or return them in the given list\n        :raises InvalidPackage: in case validation fails\n        ' #NEWLINE# errors = [ ] #NEWLINE# new_warnings = [ ] #NEWLINE# if self . package_format : #NEWLINE# #INDENT# if ( not re . match ( '^[1-9][0-9]*$' , str ( self . package_format ) ) ) : #NEWLINE# #INDENT# errors . append ( 'The "format" attribute of the package must contain a positive integer if present' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . name ) : #NEWLINE# #INDENT# errors . append ( 'Package name must not be empty' ) #NEWLINE# #UNINDENT# if ( not re . match ( '^[a-zA-Z0-9][a-zA-Z0-9_-]*$' , self . name ) ) : #NEWLINE# #INDENT# errors . append ( ( 'Package name "%s" does not follow naming conventions' % self . name ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not re . match ( '^[a-z][a-z0-9_]*$' , self . name ) ) : #NEWLINE# #INDENT# new_warnings . append ( ( 'Package name "%s" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits and underscores.' % self . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . version ) : #NEWLINE# #INDENT# errors . append ( 'Package version must not be empty' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not re . match ( '^[0-9]+\\.[0-9]+\\.[0-9]+$' , self . version ) ) : #NEWLINE# #INDENT# errors . append ( ( 'Package version "%s" does not follow version conventions' % self . version ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not re . match ( '^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$' , self . version ) ) : #NEWLINE# #INDENT# new_warnings . append ( ( 'Package "%s" does not follow the version conventions. It should not contain leading zeros (unless the number is 0).' % self . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not self . description ) : #NEWLINE# #INDENT# errors . append ( 'Package description must not be empty' ) #NEWLINE# #UNINDENT# if ( not self . maintainers ) : #NEWLINE# #INDENT# errors . append ( 'Package must declare at least one maintainer' ) #NEWLINE# #UNINDENT# for maintainer in self . maintainers : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# maintainer . validate ( ) #NEWLINE# #UNINDENT# except InvalidPackage as e : #NEWLINE# #INDENT# errors . append ( str ( e ) ) #NEWLINE# #UNINDENT# if ( not maintainer . email ) : #NEWLINE# #INDENT# errors . append ( 'Maintainers must have an email address' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . licenses ) : #NEWLINE# #INDENT# errors . append ( 'The package node must contain at least one "license" tag' ) #NEWLINE# #UNINDENT# if [ l for l in self . licenses if ( not l . strip ( ) ) ] : #NEWLINE# #INDENT# errors . append ( 'The license tag must neither be empty nor only contain whitespaces' ) #NEWLINE# #UNINDENT# if ( self . authors is not None ) : #NEWLINE# #INDENT# for author in self . authors : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# author . validate ( ) #NEWLINE# #UNINDENT# except InvalidPackage as e : #NEWLINE# #INDENT# errors . append ( str ( e ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# dep_types = { #NEWLINE# #INDENT# 'build' : self . build_depends , #NEWLINE# 'buildtool' : self . buildtool_depends , #NEWLINE# 'build_export' : self . build_export_depends , #NEWLINE# 'buildtool_export' : self . buildtool_export_depends , #NEWLINE# 'exec' : self . exec_depends , #NEWLINE# 'test' : self . test_depends , #NEWLINE# 'doc' : self . doc_depends , #NEWLINE# #UNINDENT# } #NEWLINE# for ( dep_type , depends ) in dep_types . items ( ) : #NEWLINE# #INDENT# for depend in depends : #NEWLINE# #INDENT# if ( depend . name == self . name ) : #NEWLINE# #INDENT# errors . append ( ( 'The package must not "%s_depend" on a package with the same name as this package' % dep_type ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if self . is_metapackage ( ) : #NEWLINE# #INDENT# if ( not self . has_buildtool_depend_on_catkin ( ) ) : #NEWLINE# #INDENT# new_warnings . append ( ( 'Metapackage "%s" must buildtool_depend on catkin.' % self . name ) ) #NEWLINE# #UNINDENT# if self . has_invalid_metapackage_dependencies ( ) : #NEWLINE# #INDENT# new_warnings . append ( ( 'Metapackage "%s" should not have other dependencies besides a buildtool_depend on catkin and run_depends.' % self . name ) ) #NEWLINE# #UNINDENT# #UNINDENT# for warning in new_warnings : #NEWLINE# #INDENT# if ( author is None ) : #NEWLINE# #INDENT# print ( ( 'WARNING: ' + warning ) , file = sys . stderr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( warning not in warnings ) : #NEWLINE# #INDENT# warnings . append ( warning ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if errors : #NEWLINE# #INDENT# raise InvalidPackage ( '\n' . join ( errors ) )