Mandrake Linux Archives: smart@mandrivalinux.org
Mandrake Linux: smart@mandrivalinux.org
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
- From: Gustavo Niemeyer
- Subject: Re: [smart] urpmi to smart config converter
- Date: 19 Jul 2005 21:35:36 -0000
Hello Michael,
> I decided to give smart a try on my computer today, but I didn't found
> the syntax ( ok, I lie, in fact, I didn't read any documentation
> except --help on purpose, it was just a excuse to code python ).
That's great news! Welcome on board! :-)
> So, I wrote a quick script to add the hdlist sources from
> /etc/urpmi/urpmi.cfg to /var/lib/smart/config.
Nice! Thanks! I really have in mind doing something like this
(there's even an open ticket, IIRC).
> It could be greatly improved ( it only convert hdlist sources, with a
> minimal option support, I only tested it on my computer, it doesn't
> check for duplicate sources, etc, etc ), I am posting it as a starting
> point for those who want to try smart.
>
> Do not forget to backup /var/lib/smart/config before trying it ( one more
> thing to add to the script ).
I think the best approach is to use the smart library to do that,
rather than fiddling directly with the configuration file. As a
starting point, here is a very simple way to initialize the
smart library and getting the sysconf object:
>>> from smart import *
>>> import smart
>>> ctrl = smart.init()
With that you have very simple access to the configuration via
the sysconf object, including many helpful methods.
That sysconf instance has a nice "key" access to a nested structure
of mappings. Here is another example to help you while understanding
how it works:
>>> sysconf.get("one")
>>> sysconf.get("one.two.three")
>>> sysconf.set("one.two.three", "hi")
>>> sysconf.get("one")
{'two': {'three': 'hi'}}
>>> sysconf.get("one.two")
{'three': 'hi'}
>>> sysconf.get(("one", "two"))
{'three': 'hi'}
>>> sysconf.get(("one", "two", "three"))
'hi'
>>> sysconf.remove("one")
True
>>> sysconf.get(("one", "two"))
>>>
When you understand that, you understand what the following code
(an excerpt of Mandriva's distro.py) does:
sysconf.set(("channels", "rpm-sys"),
{"type": "rpm-sys",
"name": "RPM Database"})
Before leaving the program, just run ctrl.saveSysConf() to make
your changes permanent.
--
Gustavo Niemeyer
http://niemeyer.net
- References:
- [smart] urpmi to smart config converter
- From: Michael Scherer
- [smart] urpmi to smart config converter
- Prev by Date: [smart] Re: [Smart Package Manager] #124: smart channel --enable on explicitly disabled channel does not enable it.
- Next by Date: [smart] [Smart Package Manager] #125: A couple of typos in commands/mirror.py
- Previous by thread: [smart] urpmi to smart config converter
- Next by thread: [smart] [Smart Package Manager] #124: smart wants to confirm enabling channel, as if config file had changed.
- Index(es):
Search the archive:
To (un)subscribe from/to the lists:
Fund the Mandriva Linux project
