#NEWLINE# def bin_pkg_info( path , saltenv = 'base' ) : #NEWLINE# #INDENT# "\n    .. versionadded:: 2015.8.0\n\n    Parses RPM metadata and returns a dictionary of information about the\n    package (name, version, etc.).\n\n    path\n        Path to the file. Can either be an absolute path to a file on the\n        minion, or a salt fileserver URL (e.g. ``salt://path/to/file.rpm``).\n        If a salt fileserver URL is passed, the file will be cached to the\n        minion so that it can be examined.\n\n    saltenv : base\n        Salt fileserver envrionment from which to retrieve the package. Ignored\n        if ``path`` is a local file path on the minion.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' lowpkg.bin_pkg_info /root/foo-1.2.3-1ubuntu1_all.deb\n        salt '*' lowpkg.bin_pkg_info salt://foo-1.2.3-1ubuntu1_all.deb\n    " #NEWLINE# if __salt__ [ 'config.valid_fileproto' ] ( path ) : #NEWLINE# #INDENT# newpath = __salt__ [ 'cp.cache_file' ] ( path , saltenv ) #NEWLINE# if ( not newpath ) : #NEWLINE# #INDENT# raise CommandExecutionError ( "Unable to retrieve {0} from saltenv '{1}'" . format ( path , saltenv ) ) #NEWLINE# #UNINDENT# path = newpath #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not os . path . exists ( path ) ) : #NEWLINE# #INDENT# raise CommandExecutionError ( '{0} does not exist on minion' . format ( path ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not os . path . isabs ( path ) ) : #NEWLINE# #INDENT# raise SaltInvocationError ( '{0} does not exist on minion' . format ( path ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# cmd = [ 'dpkg' , '-I' , path ] #NEWLINE# result = __salt__ [ 'cmd.run_all' ] ( cmd , output_loglevel = 'trace' ) #NEWLINE# if ( result [ 'retcode' ] != 0 ) : #NEWLINE# #INDENT# msg = ( 'Unable to get info for ' + path ) #NEWLINE# if result [ 'stderr' ] : #NEWLINE# #INDENT# msg += ( ': ' + x [ 'stderr' ] ) #NEWLINE# #UNINDENT# raise CommandExecutionError ( msg ) #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for line in result [ 'stdout' ] . splitlines ( ) : #NEWLINE# #INDENT# line = line . strip ( ) #NEWLINE# if line . startswith ( 'Package:' ) : #NEWLINE# #INDENT# ret [ 'name' ] = line . split ( ) [ ( - 1 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if line . startswith ( 'Version:' ) : #NEWLINE# #INDENT# ret [ 'version' ] = line . split ( ) [ ( - 1 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if line . startswith ( 'Architecture:' ) : #NEWLINE# #INDENT# ret [ 'arch' ] = line . split ( ) [ ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# missing = [ x for x in ( 'name' , 'version' , 'arch' ) if ( x not in ret ) ] #NEWLINE# if missing : #NEWLINE# #INDENT# raise CommandExecutionError ( 'Unable to get {0} for {1}' . format ( ', ' . join ( missing ) , path ) ) #NEWLINE# #UNINDENT# if ( __grains__ . get ( 'cpuarch' , '' ) == 'x86_64' ) : #NEWLINE# #INDENT# osarch = __grains__ . get ( 'osarch' , '' ) #NEWLINE# arch = ret [ 'arch' ] #NEWLINE# if ( ( arch != 'all' ) and ( osarch == 'amd64' ) and ( osarch != arch ) ) : #NEWLINE# #INDENT# ret [ 'name' ] += ':{0}' . format ( arch ) #NEWLINE# #UNINDENT# #UNINDENT# return ret