Packages()

Archive of the older Feature Request Forum Posts
Locked
innominabile
Adept Poster
Posts: 85
Joined: Wed Aug 30, 2006 5:24 pm

Packages()

Post by innominabile »

Now packages report name sopports_http and npcdesc
Have on report all info loaded in pkg.cfg ?
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

None of that is really stored, with the exception of the package name, and its version.

The solution to use it would be make an include that uses file.em and read it in that way.

Code: Select all

use os;
use file;

/*
 * GetPackageCfgInfo(pkg_name)
 *
 * Purpose
 * Reads a pkg.cfg for a package and returns its information.
 *
 * Parameters
 * pkg_name:	Name of the package to retrieve the information for.
 *
 * Return Value
 * Returns a dictionary on success.
 * Returns an error on failure.
 *
 */

function GetPackageCfgInfo(pkg_name)
	var info := dictionary;
	var pkgfile := ReadFile(":"+pkg_name+":pkg.cfg");
	if ( pkgfile.errortext )
		return pkgfile; // Contains an error.
	endif

	foreach line in ( pkgfile )
		var parsed := SplitWords(line);
		var key := parsed[1];

		var pos := Find(line, parsed[2], Len(parsed[1])+1);
		var value := line[pos, Len(line)];

		info[key] := value;
		SleepMs(2);
	endforeach

	return info;
endfunction
innominabile
Adept Poster
Posts: 85
Joined: Wed Aug 30, 2006 5:24 pm

Post by innominabile »

Thanks :-))) Very nice.
Locked