#NEWLINE# def ensure_package_installed( self , package_name , version = None ) : #NEWLINE# #INDENT# "\n        Makes sure the package is installed with the specified version (latest if :data:`None` specified).\n        This method does not verify and upgrade the package on subsequent provisions, though.\n\n        :param package_name: Name of the package to install.\n        :type package_name: :class:`str`\n        :param version: If specified, installs this version of the package. Installs latest version otherwise.\n        :type version: :class:`str`\n\n        Example::\n        ::\n\n            from provy.core import Role\n            from provy.more.debian import GemRole\n\n            class MySampleRole(Role):\n                def provision(self):\n                    with self.using(GemRole) as role:\n                        role.ensure_package_installed('activerecord', version='3.1.1')\n        " #NEWLINE# if ( not self . is_package_installed ( package_name ) ) : #NEWLINE# #INDENT# version_str = ( ( version and ( '(%s)' % version ) ) or '' ) #NEWLINE# self . log ( ( '%s is not installed (via gem)! Installing...' % package_name ) ) #NEWLINE# self . execute ( ( 'gem install %s%s' % ( package_name , package_name ) ) , stdout = False , sudo = self . use_sudo ) #NEWLINE# self . log ( ( '%s installed!' % package_name ) ) #NEWLINE# return True #NEWLINE# #UNINDENT# return False