Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
usage_of_batocera-settings [2020/11/22 11:30] lalausage_of_batocera-settings [2023/10/09 20:41] (current) – python example works now crcerror
Line 1: Line 1:
-~~NOTOC~~ +====== Usage of batocera-settings ======
-===== Usage ofbatocera-settings =====+
  
-==== Introduction ====+===== Introduction =====
  
-**batocera-settings** is a commandline tool that can work with regular config files and read/write/change it's contentThere are keys and values stored in a file like ''/userdata/system/batocera.conf''.+<WRAP center round info> 
 +This command is a bit out of date to use now, most if not all things can be adjusted within Batocera EmulationStation itself or through manually editing the text fileCertain commands may no longer be functional. On older versions of Batocera, the list of available functions can be found by entering in ''batocera-settings'' and pressing Enter. 
 +</WRAP>
  
-  It's recommended to use **## This is a text comment** for text comments +**batocera-settings** is a command-line tool that can work with regular config files to read/write its content, useful for scripting (like say you need to change the config based on what machine you have the drive plugged into)The ''/userdata/system/batocera.conf'' contains most of the machine'settings and follows ''batocera.conf'''[[:batocera_conf_syntax|regular syntax]].
-  * It's recommended to use **#enable.godmode=hallelujah** for commenting values +
-  * It'recommended to descripe content and functions in text form +
-  * It's recommended to add content in sections +
-  * It'recommended to use the form **key.description=value**+
  
-Down here is a small excerpt of config file +When manually editing the ''batocera.conf'' file: 
-<code>+ 
 +  * Use **## This is a text comment** for text comments. 
 +  * Use **#enable.godmode=hallelujah** for commenting values. 
 +  * Describe content and functions in comments when adding them for future reference. 
 +  * It's recommended to add content in their appropriate sections, but not strictly required. 
 + 
 +Down here is a small excerpt of an example config file 
 + 
 +<file>
 # ------------ B - Network ------------ # # ------------ B - Network ------------ #
 ## Set system hostname ## Set system hostname
Line 26: Line 31:
 ## Escape your special chars (# ; $) with a backslash : $ => \$ ## Escape your special chars (# ; $) with a backslash : $ => \$
 #wifi.key=new key #wifi.key=new key
-</code>+</file>
  
-==== Recommended commands and expressions ====+===== Recommended commands and expressions =====
  
-batocera-setting is utilized by parameters parsed. These parameters can be used in the long and in the short format. It's a relict of RecalBox times thus the expression ''python batoceraSetting.py -command load -key user.key'' is used till today but arguments are now parsed to batocera-settings.+The commands are called with ''batocera-setting-get'' and ''batocera-setting-set''. For the syntax below, replace the contents in the square brackets with your intended setting (and don't include the square brackets themselves).
  
-As batocera-settings is more modern and supports read/write/change of value let's see how the command line works+Syntax for reading setting values
-  * BATOCERA Basic usage +<code> 
-    * ''batocera-settings -r [key]'' read key ''from batocera.conf'' +batocera-settings-get -f [CONFIG_FILE] [KEY
-    * ''batocera-settings -w [key] -v [value]'' write value ''key=value'' to batocera.conf +batocera-settings-get [KEY
-    * ''batocera-settings -f [file-r[key]'' read value key from ''file'' +</code>
-  * BATCOERA Extended usage +
-    * ''batocera-settings -e -r [key-s [system]'' iterate keys ''system.key'' and if not available use ''global.key'' +
-    * ''batocera-settings -e -r [key] -s [system] -g [game]'' iterate keys like above, but start with ''system["game"].key''+
  
-<WRAP center round tip 80%> +This will read the KEY setting from the specified config file and output its current fileIf no ''-f'' flag specifiedit will search through ''userdata/system/batocera.conf'' by default.
-**Basic usage:** //batocera-settings -f [file] -r [key] -w [key] -v [value]// \\ +
-**Extended usage:** //batocera-settings -e -g [game] -s [system] -r [key]// \\ +
-\\ +
-**-f** -- Loads any config file, default '/userdata/system/batocera.conf\\ +
-**-r** -- Read 'key' and returns value from config file \\ +
-**-w** -- Write 'keyto config filemandatory parameter -v \\ +
-**-v** -- Set value to selected 'key', any alphanumeric value \\ +
-**-e** -- Activate extended mode, needed for parsing game/system specific keys \\ +
-**-g** -- Any alphanumeric string for game, set quotes to avoid globbing \\ +
-**-s** -- Any alphanumeric string for system \\ +
-</WRAP> +
-<WRAP center round alert 60%> +
-If ''-e'' is not set the parameters ''-g'' and ''-s'' are ignored! \\ +
-Value ''-w'' needs an additional valid entry for ''-v''! \\ +
-Use the errorlevels for scripts! \\ +
-Always use quotes if you use arguments containing blanks! +
-</WRAP>+
  
 +Syntax for setting those values:
 +<code>
 +batocera-settings-set -f [CONFIG_FILE] [KEY] [VALUE]
 +batocera-settings-set [KEY] [VALUE]
 +</code>
  
-==== Backward compatibility commands and expressions ====+This will search for the key in the config file and then replace its value with the new specified one. If the key doesn't already exist in the config file, a new line with that key will be created.
  
-  BATOCERA Classic format (Unix Style) +In Batocera **v36** and above, syntax for reading the current board's default setting:
-    ''batocera-settings %%--%%command load %%--%%key your.key'' +
-  BATOCERA Classic short format +
-    * ''batocera-settings load your.key'' +
-  +
-^%%--%%command ^%%--%%key ^%%--%%value ^alias commands ^ +
-|load |your.key | |get, read | +
-|write |your.key |keyvalue |set, save | +
-|status |your.key | |stat | +
-|comment |your.key | |disable, deactivate | +
-|uncomment |your.key | |enable, activate |+
  
-==== Error code handling =====+<code> 
 +batocera-settings-get-master [key] 
 +</code> 
 + 
 +This will read the key from ''/usr/share/batocera/sysconfigs/batocera.conf.${BOARD_MODEL}''
 + 
 +===== Error code handling ======
  
-Whenever ''batocera-settings'' was called you will receive an exit code number. This will help to identify errors - morover for debugging you can use the **status** command to held usefull output. +Whenever ''batocera-settings-set'' or ''batocera-settings-get'' is called from a script you will receive an exit code number. This will help to identify errors (for debugging you can use the **status** command for more useful output)
  
 ^File and Key/Values error ||| ^File and Key/Values error |||
Line 83: Line 69:
 |EC 0    |No Error, value found | 8-) You made it! | |EC 0    |No Error, value found | 8-) You made it! |
 |EC 1    |General error, e.g. command line error | 8-o Check your command line for correct parameters | |EC 1    |General error, e.g. command line error | 8-o Check your command line for correct parameters |
-|EC 2    |File error, e.g. the config file is not available | m( Check file path and r/w access to it | 
-|EC 10   |Value error, key found but value is empty | 8-o Unusual setup but no error at all | 
-|EC 11   |Value error, key found but it is commented out | :-( Activate the key entry by ''uncomment'' command | 
-|EC 12   |Key not found | m( Add the key by manual or check your command line for typos | 
  
-==== Handling in scripts ====+===== Handling in scripts =====
  
-I present here some short scripts, to show you how to make batocera-settings work in your script. As I'm more confident in shell scripting I give you just some small exampels in shell script.+I present here some short scripts, to show you how to make batocera-settings work in your script. As I'm more confident in shell scripting I give you just some small examples in shell script.
  
   - bash: Obtain value   - bash: Obtain value
Line 96: Line 78:
   - bash: Set a new key   - bash: Set a new key
   - python: Obtain a value   - python: Obtain a value
- 
  
 ** USE AT YOUR OWN RISK ** 8-) ** USE AT YOUR OWN RISK ** 8-)
Line 104: Line 85:
 <code bash| obtain_value.sh> <code bash| obtain_value.sh>
 #!/bin/bash #!/bin/bash
-#This is an example file how batocera-settings can be utilized+#This is an example file how batocera-settings-get can be utilized
 #to read a value out from /userdata/system/batocera.conf #to read a value out from /userdata/system/batocera.conf
  
-value="$(batocera-settings --command load --key power.switch.device)"+value="$(batocera-settings-get power.switch.device)"
 ret=$? ret=$?
 if [[ $ret -eq 0 ]]; then if [[ $ret -eq 0 ]]; then
Line 120: Line 101:
 <code bash| activate_uart.sh> <code bash| activate_uart.sh>
 #!/bin/bash #!/bin/bash
-#This is an example file how batocera-settings can be utilized+#This is an example file how batocera-settings-set can be utilized
 #to activate UART in /boot/config.txt #to activate UART in /boot/config.txt
  
-batocera-settings /boot/config.txt --command uncomment --key enable_uart+# Check status of file and make it writeable 
 +[[ -/boot/config.txt ]] && batocera-es-swissknife --remount 
 + 
 +batocera-settings-set -f /boot/config.txt enable_uart 1
 ret=$? ret=$?
 if [[ $ret -eq 0 ]]; then if [[ $ret -eq 0 ]]; then
     echo "UART activated, uncommented enable_uart"     echo "UART activated, uncommented enable_uart"
-elif [[ $ret -eq 2 ]]; then +    batocera-settings-set -/boot/config.txt enable_uart 1
-    echo "File is write protected!" +
-    echo "I make boot-partition writeable" +
-    mount -o remount, rw /boot +
-    echo "Please restart script"+
 else else
     echo "Key: enable_uart not found"     echo "Key: enable_uart not found"
Line 140: Line 120:
 === 3. bash: Set a new key === === 3. bash: Set a new key ===
  
-<code bash| activate_uart.sh>+<code bash| set_new_key.sh>
 #!/bin/bash #!/bin/bash
-#This is an example file how batocera-settings can be utilized+#This is an example file how batocera-settings-set can be utilized
 #to set a new key in /userdata/system/batocera.conf #to set a new key in /userdata/system/batocera.conf
  
-value=$(batocera-settings --command write --key core.PS4.emulator --value SONY4EVER+value=$(batocera-settings-set core.PS5.emulator SONY5EVER)
 ret=$? ret=$?
 if [[ $ret -eq 0 ]]; then if [[ $ret -eq 0 ]]; then
-    echo "PS4 core enabled!" +    echo "PS5 core enabled!"
-elif [[ $ret -eq 12 ]]; then +
-    echo "Key not found! - I add it" +
-    echo "core.PS4.emulator=" >> /userdata/system/batocera.conf +
-     +
-    echo "Please restart script!"+
 else else
-    echo "Annother error occoured!"+    echo "Another error occurred!"
 fi fi
 </code> </code>
  
 === 4. python: Obtain a key === === 4. python: Obtain a key ===
- 
-FIXME 
  
 <code python| obtain_value.py> <code python| obtain_value.py>
 +
 #!/usr/bin/python #!/usr/bin/python
-# -*- coding: utf-8 -*- +#This is an example file how batocera-settings-get can be utilized
-#This is an example file how batocera-settings can be utilized+
 #to read a value out from /userdata/system/batocera.conf with python #to read a value out from /userdata/system/batocera.conf with python
  
 import subprocess import subprocess
- +command=(["batocera-settings-get""system.power.switch"]) 
-value (subprocess.check_output(['batocera-settings', 'get''power.switch.device'])) +rc = subprocess.call(command, stdout=subprocess.DEVNULL
-if value+if rc == 0: 
-    print "Power Switch Detected: ", value+    value = subprocess.check_output(command).decode("utf-8") 
 +    print ("Power Switch Detected: ", value)
 else: else:
-    print "No power switch detected!"+    print ("No power switch detected!")
 </code> </code>
 +
 +
 +
  • usage_of_batocera-settings.1606041047.txt.gz
  • Last modified: 3 years ago
  • by lala