Mailinglist Archive: yast-devel (144 mails)

< Previous Next >
[yast-devel] Converting YCP data files into YAML, continue removing YCP

Hi all,

The ruby conversion did not touch the YCP data files (the files which are
installed
into /usr/share/YaST2/data and are read using SCR::Read(.target.yast2/.ycp,
"foo.ycp") call.)

These data files usually contain additional data like hardware databases,
additional
data mapping...


There are several reasons why we did not convert them:

- "foo.ycp" in the SCR call would not exist after the conversion, there
would be "foo.rb"

- .target.yast2 agent parses YCP files, it would fail with Ruby content

- Ruby format is not the best format for storing data


But to get rid of the YCP interpreter completely (our long term goal)
we need to convert these YCP data files anyway.


For this reason I have created a simple "ycp2yml" client which reads a specified
YCP file and writes it's value into a YAML file. It is included in the latest
devtools.

It's very easy, it just evaluates the YCP file via SCR.Read, coverts to YAML
by calling to_yaml method and saves the result to a file.

That means it's not a 1:1 copy, e.g. comments are not transferred, translation
marks
are lost,... But in many cases it is enough. Of course, you can patch the YAML
file
manually after the conversion.


Example usage:

/sbin/yast2 ycp2yml consolefonts.ycp consolefonts.yml


Then replace the original YCP file in Git (don't forget to fix Makefile.am
and *.spec.in) and use it this way:

require 'yaml'

# add this if not already there
Yast.import "Directory"

...

# original code: data = ... SCR.Read(path(".target.yast2"), "foo.ycp")
data = YAML.load_file(Directory.datadir + "/foo.yml") rescue nil

# nil is the default value if an exception is raised (missing file,
# broken/inconsistent, read error...) and is backward compatible.
# You can use different default if needed.


Note: if you use translations in the original YCP file then you need
to use different solution, e.g. convert it into a Ruby file
and make it Yast include.


You can look at these pull requests:

https://github.com/yast/yast-sound/pull/2
https://github.com/yast/yast-ntp-client/pull/10

Enjoy!


--

Best Regards

Ladislav Slezák
Yast Developer
------------------------------------------------------------------------
SUSE LINUX, s.r.o. e-mail: lslezak@xxxxxxx
Lihovarská 1060/12 tel: +420 284 028 960
190 00 Prague 9 fax: +420 284 028 951
Czech Republic http://www.suse.cz/
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >