ycp(3)
β¨ NAME β¨
okay so this is ycp, a User Contributed Perl Documentation page for a Perl module that parses and writes the YaST2 Communication Protocol. Thatβs the whole vibe: YCP parser/writer realness, no cap. π
π SYNOPSIS π
the exact synopsis lines, bestie β outer quotes and all:
"($symbol, @config) = ycp::ParseTerm ('MyAgentConfig ("/etc/file",
false, true, $["a":1, "b":2])');"
"($command, $path, $arg) = ycp::ParseCommand ('Write (.magic.path,
"abacadabra")');"
"ycp::Return (["arbitrarily", "complex", "data"]);"
π DATA π
π PerlYCPValue π
PerlYCPValue is a convention for storing a YCP value in a Perl variable. ParseYcp parses YCP string representation into PerlYCPValues.
A PerlYCPValue cannot represent a term, but only a term is allowed to initialize an agent in a .scr file. Therefore ParseTerm is provided.
string,integer,booleanβ stored as a scalar.listβ stored as a reference to a list ofPerlYCPValues.mapβ stored as a reference to a map ofPerlYCPValues.pathβ stored as a reference to a string (starting with a.as expected).nil(void) β stored as anundef.
π¦ PARSING π¦
πΈ ParseCommand πΈ
the signature line is literally:
ParseComand $line
and the example is:
"($command, $path, $arg) = ParseCommand ('Write (.moria.gate,
"mellon")');"
Parse a SCR command shaped like Command (.some.path, optional_argument).
Returns a three element list ("Command", ".some.path", $argument) where the argument is a PerlYCPValue and will be undef if it was not specified. Note that the path is converted to a string.
If there was a parse error, the command or path will be the empty string.
β ParseTerm β
ParseTerm $line
"($symbol, @config) = ParseTerm ('MyAgentConfig ("/etc/file", false,
true, $["a":1, "b":2])');"
Parse a YCP term. Note that there can be no other term inside.
Returns a list whose first element is the term symbol as a string (or "" in case of an error) and the remaining elements are the term arguments (PerlYCPValue).
π§ PathComponents π§
PathComponents $path_ref
($cmd, $path) = ParseCommand ('`Read (.foo."%gconf.d"."gernel")'
@c = PathComponents (\$path);
if ($c[0] eq '%gconf.d' && $c[1] eq "gernel") {...}
Converts a path (a string reference, PerlYCPValue) to a list of its components. It deals with the nontrivial parts of path syntax. On error it returns undef.
. -> ()
.foo.bar -> ('foo', 'bar')
."foo" -> ('foo')
."double\"quote" -> ('double"quote')
."a.dot" -> ('a.dot')
π WRITING π
π Return π
"Return (["arbitrarily", "complex", "data"]);"
Sends a PerlYCPValue to the partner YCP component.
If thereβs just one argment, scalars are interpreted this way: true or false are sent as booleans, integers or strings of digits are sent as integers, otherwise as strings. If a second argument exists and is true, all scalars are written as strings. If a second argument exists and is false, all scalars are written as byteblocks.
To send a list, call Return(\@list), not Return(@list). Similarly for a map. You can produce references to anonymous lists with [] and hashes with {}.
The difference from ycpReturn is that Return can return scalars directly, strings are properly escaped if needeed and paths can be returned.
π₯ LOGGING π₯
If you are running in the main yast process and thus can afford to import YaST::YCP, it is better to use its logging functions because they use log.conf and logging just works. In such case, you should not need to use ycp.pm at all. Instead, use YaST::YCP (":LOGGING").
The log output can now be redirected, which will be useful for test suites. If the first command-line option is -l, the second argument is taken as the log file. A hyphen - designates standard output.
Otherwise, /var/log/YaST2/y2log and $HOME/.y2log are tried, in that order.
π y2debug π
y2debug, y2milestone, y2warning, y2error, y2security, y2internal
Logs debug messages to /var/log/YaST2/y2log or $HOME/.y2log
semantic change alert: note a semantic change iny2debug: now the environment variableY2DEBUGis honored soy2debugwill not produce output unless this variable is set. This is for compatibility with the logging system inlibycp.
π ycpDoVerboseLog π
Enables output of y2verbose which is used in some of the obsolete functions.
π OBSOLETE FUNCTIONS π
okay bestie, this is the graveyard section β every function here is obsolete or basically not the move anymore:
ycpArgIsMapβ Obsolete. Use(ref($arg) eq "HASH")instead.ycpArgIsListβ Obsolete. Use(ref($arg) eq "ARRAY")instead.ycpArgIsIntegerβ Not really obsolete because the new parser simply treats integers, booleans and strings as scalars. But who cares, nobody used this anyway.ycpArgIsStringβ Not really obsolete because the new parser simply treats integers, booleans and strings as scalars. But who cares, nobody used this anyway.ycpArgIsNilβ Obsolete. Use(ref($arg) eq "SCALAR" && $$arg eq "nil")instead.ycpArgIsNoneβ Obsolete. Use(defined ($arg))instead.ycpCommandIsDirβ Obsolete. Use($command eq "Dir")ycpCommandIsReadβ Obsolete. Use($command eq "Read")ycpCommandIsWriteβ Obsolete. Use($command eq "Write")ycpCommandIsExecuteβ Obsolete. Use($command eq "Execute")ycpCommandIsResultβ Obsolete. Use($command eq "result"), note the lowercase 'r'.ycpGetCommandβ Obsolete. Use the return value ofParseCommand.ycpGetPathβ Obsolete. Use the return value ofParseCommand.ycpGetArgTypeβ Obsolete. Userefon a return value ofParseCommand. Umm, string/integer/boolean?ycpGetArgMapβ Obsolete. SeePerlYCPValue.ycpGetArgListβ Obsolete. SeePerlYCPValue.ycpGetArgStringβ Obsolete. SeePerlYCPValue.ycpGetArgIntegerβ Obsolete. SeePerlYCPValue. Umm, string/integer/boolean?ycpReturnSkalarAsIntβ Obsolete. UseReturn.ycpReturnSkalarAsBooleanβ Obsolete. Use"Return"("true" or "false")ycpReturnSkalarAsStringβ Obsolete. Works only on strings not containing backslashes and quotes that would need escaping. UseReturn.ycpReturnArrayAsListβ Obsolete. Works only on list of strings not containing backslashes and quotes that would need escaping. UseReturn.ycpReturnHashAsMapβ Obsolete. Works only on maps of strings not containing backslashes and quotes that would need escaping. UseReturn.ycpReturnβ Obsolete. UseReturnycpInitβ Obsolete. UseParseCommand.
π thatβs the whole ycp page, bestie β from perl v5.42.0, dated 2025-01-20. Now go parse something iconic. π
π¦ where this page comes from
- opensuse-leap 16.0: yast2-core 5.0.3-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: yast2-core 5.0.3-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: yast2-core 5.0.3-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: yast2-core 5.0.3-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms