Conary has a
public API, through which you can have access to the packages on your system. Here is some quick examples.
1. Query packages installed locally, (equivalent of 'conary query')
1 # test1.py
2 import pprint
3
4 from conary.conaryclient import ConaryClient
5 from conary.conarycfg import ConaryConfiguration
6
7 c = ConaryClient(ConaryConfiguration())
8 troves = c.db.findTroves(None, [('dbus', None, None)])
9 pprint.pprint(troves)
$ python test1.py
{('dbus', None, None): [('dbus',
VFS('/foresight.rpath.org@fl:devel//2-qa/1.4.0-0.3-1'),
Flavor('is: x86')),
('dbus',
VFS('/foresight.rpath.org@fl:devel//2-qa/1.4.0-0.3-1'),
Flavor('is: x86_64'))]}
$ conary q dbus
dbus=foresight.rpath.org@fl:2-qa/1.4.0-0.3-1[is: x86]
dbus=foresight.rpath.org@fl:2-qa/1.4.0-0.3-1[is: x86_64]
2. Query packages in the repository, (equivalent of 'conary repoquery')
1 # test2.py
2 import pprint
3
4 from conary.conaryclient import ConaryClient
5 from conary.conarycfg import ConaryConfiguration
6
7 cfg = ConaryConfiguration(readConfigFiles=True)
8 c = ConaryClient(cfg)
9 troves = c.repos.findTroves(cfg.installLabelPath, [('dbus', None, None)])
10 pprint.pprint(troves)
$ python test2.py
{('dbus', None, None): [('dbus',
VFS('/foresight.rpath.org@fl:devel//2-qa/1.4.0-0.3-1'),
Flavor('is: x86')),
('dbus',
VFS('/foresight.rpath.org@fl:devel//2-qa/1.4.0-0.3-1'),
Flavor('is: x86_64'))]}
3. List files of a package, (equivalent of 'conary q --ls')
1 # test3.py
2
3 from conary.conaryclient import ConaryClient
4 from conary.conarycfg import ConaryConfiguration
5
6 c = ConaryClient(ConaryConfiguration())
7 n, v, f = c.db.findTrove(None, ('m4:doc', None, None))[0]
8 trove = c.db.getTrove(n, v, f, withFiles=True)
9 for (pathId, path, fileId, version) in trove.iterFileList():
10 print path
$ python test3.py
/usr/share/info/m4.info.gz
/usr/share/man/man1/m4.1.gz
Note that the trove you use for iterFileList() "will have to be a trove that has files -- a component or fileset, but not a package or a group". ('Trove' is a general name for package/component/group).
And there is also a second approach,
1 from conary.conaryclient import ConaryClient
2 from conary.conarycfg import ConaryConfiguration
3
4 c = ConaryClient(ConaryConfiguration())
5 n, v, f = c.db.findTrove(None, ('m4:doc', None, None))[0]
6 iter = c.db.iterFilesInTrove(n, v, f, withFiles=True, capsules=False)
7 for (pathId, path, fileId, version, filename) in iter:
8 print path
4. List components of a package, (equivalent of 'conary q --troves' or 'conary q --all-troves'):
1 # test4.py
2
3 from conary.conaryclient import ConaryClient
4 from conary.conarycfg import ConaryConfiguration
5
6 c = ConaryClient(ConaryConfiguration())
7 n, v, f = c.db.findTrove(None, ('kernel', None, None))[0]
8 trove = c.db.getTrove(n, v, f)
9 components = trove.iterTroveList(strongRefs=True)
10 for (n, v, f) in components:
11 print "%s %s %s - %s" % (n, v, f,
12 "Installed" if c.db.hasTrove(n, v, f) else "Not Installed")
$ python test4.py
kernel:runtime /foresight.rpath.org@fl:2-qa-kernel/2.6.35.10-5-1 ~kernel.debugdata,~!xen is: x86_64 - Installed
kernel:vmware /foresight.rpath.org@fl:2-qa-kernel/2.6.35.10-5-1 ~kernel.debugdata,~!xen is: x86_64 - Installed
kernel:debuginfo /foresight.rpath.org@fl:2-qa-kernel/2.6.35.10-5-1 ~kernel.debugdata,~!xen is: x86_64 - Not Installed
kernel:build-tree /foresight.rpath.org@fl:2-qa-kernel/2.6.35.10-5-1 ~kernel.debugdata,~!xen is: x86_64 - Not Installed
kernel:configs /foresight.rpath.org@fl:2-qa-kernel/2.6.35.10-5-1 ~kernel.debugdata,~!xen is: x86_64 - Installed
That's it, some dirty examples and I don't know if it's the recommended way of doing things. And not all functions used above are official public APIs (now I'm using conary-2.2.9 and python-2.6.6). So take care, and better to install
pycscope and poke around
the source code yourself:)