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 [2021/08/22 11:09] – repaired scripts (maybe?) atariusage_of_batocera-settings [2023/10/09 20:41] (current) – python example works now crcerror
Line 1: Line 1:
-~~NOTOC~~ 
 ====== Usage of batocera-settings ====== ====== Usage of batocera-settings ======
  
 ===== Introduction ===== ===== Introduction =====
  
-<WRAP center round info 60%+<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 file. Certain commands may no longer be functional. The following is still useful for scripting however.+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 file. Certain 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> </WRAP>
  
-**batocera-settings** is a command-line tool that can work with regular config files to read/write its content instead of manually editing it yourself. The ''/userdata/system/batocera.conf'' contains most of the machine's settings and uses the **key[game-if-applicable].setting=value** syntax.+**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's settings and follows ''batocera.conf'''s [[:batocera_conf_syntax|regular syntax]].
  
 When manually editing the ''batocera.conf'' file: When manually editing the ''batocera.conf'' file:
Line 18: Line 17:
  
 Down here is a small excerpt of an example config file Down here is a small excerpt of an example config file
 +
 <file> <file>
 # ------------ B - Network ------------ # # ------------ B - Network ------------ #
Line 35: Line 35:
 ===== Recommended commands and expressions ===== ===== Recommended commands and expressions =====
  
-batocera-setting is utilized by parameters parsedThese parameters can be used in the long and in the short format. It's a relic of RecalBox times thus its syntax should seem familiar.+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 reading/writing values. For these examples, replace the contents in the square brackets with your intended setting (and don't include the square brackets themselves).+Syntax for reading setting values: 
 +<code> 
 +batocera-settings-get -f [CONFIG_FILE] [KEY] 
 +batocera-settings-get [KEY] 
 +</code>
  
-  * BATOCERA Basic usage +This will read the KEY setting from the specified config file and output its current fileIf no ''-f'' flag specified, it will search through ''userdata/system/batocera.conf'' by default.
-    * **''batocera-settings-get [key]''** read ''key'' from ''batocera.conf'' +
-    * **''batocera-settings-set [key] -v [value]''** write value ''key=value'' to ''batocera.conf'' +
-    * **''batocera-settings-get -f [file] [key]''** read value key from ''file'' +
-  * BATCOERA Extended usage FIXME This flag no longer existswas it moved or outright deleted? +
-    * **''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%+Syntax for setting those values: 
-**Basic usage:** //batocera-settings-set -f [CONFIG_FILE] [KEY] [VALUE]\\ +<code
-**Extended usage:** //batocera-settings-set -e -g [game-s [system-r [key] FIXME This flag no longer exists, was it moved or outright deleted?\\ +batocera-settings-set -f [CONFIG_FILE] [KEY] [VALUE] 
-**-f** -- Specifies the config file to read from. Defaults to ''/userdata/system/batocera.conf''.\\ +batocera-settings-set [KEY] [VALUE
-**-v** -- Set value to selected 'key', any alphanumeric value\\ +</code>
-**-e** -- Activate extended mode, needed for parsing game/system specific keys FIXME This flag no longer exists, was it moved or outright deleted?\\ +
-**-g** -- Filename of the specified game, enclose in double-quotes ("") to avoid globbing FIXME This flag no longer exists, was it moved or outright deleted?\\ +
-**-s** -- Shortname of specified system FIXME This flag no longer exists, was it moved or outright deleted?\\ +
-</WRAP>+
  
-<WRAP center round alert 60%> +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. 
-FIXME This flag no longer exists, was it moved or outright deleted?\\ + 
-If ''-e'' is not set the parameters ''-g'' and ''-s'' are ignored!\\ +In Batocera **v36** and above, syntax for reading the current board'default setting: 
-Use the errorlevels for scripts!\\ + 
-Always use quotes if you use arguments containing blanks!\\ +<code> 
-</WRAP>+batocera-settings-get-master [key] 
 +</code> 
 + 
 +This will read the key from ''/usr/share/batocera/sysconfigs/batocera.conf.${BOARD_MODEL}''.
  
 ===== Error code handling ====== ===== Error code handling ======
Line 72: 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 =====
Line 110: Line 103:
 #This is an example file how batocera-settings-set 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
 +
 +# Check status of file and make it writeable
 +[[ -w /boot/config.txt ]] && batocera-es-swissknife --remount
  
 batocera-settings-set -f /boot/config.txt enable_uart 1 batocera-settings-set -f /boot/config.txt enable_uart 1
Line 115: Line 111:
 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 
-    echo "File is write protected!" 
-    echo "Remounting boot-partition with write permissions..." 
-    mount -o remount, rw /boot 
     batocera-settings-set -f /boot/config.txt enable_uart 1     batocera-settings-set -f /boot/config.txt enable_uart 1
-    if [[ $ret -eq 0 ]]; then 
-        echo "UART activated, uncommented enable_uart" 
-    fi 
 else else
     echo "Key: enable_uart not found"     echo "Key: enable_uart not found"
Line 136: Line 125:
 #to set a new key in /userdata/system/batocera.conf #to set a new key in /userdata/system/batocera.conf
  
-value=$(batocera-settings-set core.PS4.emulator 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!"
 else else
     echo "Another error occurred!"     echo "Another error occurred!"
Line 146: Line 135:
  
 === 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-get 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.1629623341.txt.gz
  • Last modified: 3 years ago
  • by atari