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



Date Index | Thread Index

Search the archive:



To (un)subscribe from/to the lists:

Sympa mailing lists server.





Fund the Mandriva Linux project

Looking for a job?