Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
usage_of_batocera-settings [2020/01/28 20:52] – created genetik57 | usage_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 |
- | **batocera-settings** | + | <WRAP center round info> |
+ | This command | ||
+ | </ | ||
- | | + | **batocera-settings** is a command-line tool that can work with regular config files to read/write its content, useful |
- | * It's recommended | + | |
- | * It' | + | |
- | * It's recommended to add content in sections | + | |
- | * It' | + | |
- | Down here is a small excerpt of a config | + | When manually editing the '' |
- | <code> | + | * Use **## This is a text comment** for text comments. |
+ | * Use **# | ||
+ | * 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 27: | Line 31: | ||
## Escape your special chars (# ; $) with a backslash : $ => \$ | ## Escape your special chars (# ; $) with a backslash : $ => \$ | ||
# | # | ||
+ | </ | ||
+ | |||
+ | ===== Recommended commands and expressions ===== | ||
+ | |||
+ | The commands are called with '' | ||
+ | |||
+ | Syntax for reading setting values: | ||
+ | < | ||
+ | batocera-settings-get -f [CONFIG_FILE] [KEY] | ||
+ | batocera-settings-get [KEY] | ||
</ | </ | ||
- | ==== Commands | + | This will read the KEY setting from the specified config file and output its current file. If no '' |
- | 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 | + | Syntax for setting those values: |
+ | < | ||
+ | batocera-settings-set -f [CONFIG_FILE] [KEY] [VALUE] | ||
+ | batocera-settings-set [KEY] [VALUE] | ||
+ | </ | ||
+ | |||
+ | 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. | ||
+ | |||
+ | In Batocera **v36** and above, syntax for reading the current board's default setting: | ||
+ | |||
+ | < | ||
+ | batocera-settings-get-master [key] | ||
+ | </ | ||
- | As batocera-settings is more modern and supports | + | This will read the key from '' |
- | * BATOCERA Long format (Unix Style), recommended | + | |
- | * '' | + | |
- | * BATOCERA Short format, recommended | + | |
- | * '' | + | |
- | + | ||
- | ^%%--%%command ^%%--%%key ^%%--%%value ^alias commands ^ | + | |
- | |load |your.key | |get, | + | |
- | |write |your.key |keyvalue |set, | + | |
- | |status |your.key | |stat | | + | |
- | |comment |your.key | |disable, | + | |
- | |uncomment |your.key | |enable, | + | |
- | ==== Error code handling ===== | + | ===== Error code handling |
- | Whenever '' | + | Whenever '' |
^File and Key/Values error ||| | ^File and Key/Values error ||| | ||
Line 54: | 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 | ||
- | |EC 11 | ||
- | |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 | + | 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 |
- bash: Obtain value | - bash: Obtain value | ||
Line 67: | 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 75: | 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 / | #to read a value out from / | ||
- | value=" | + | value=" |
ret=$? | ret=$? | ||
if [[ $ret -eq 0 ]]; then | if [[ $ret -eq 0 ]]; then | ||
Line 91: | 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 / | #to activate UART in / | ||
- | batocera-settings | + | # Check status of file and make it writeable |
+ | [[ -w / | ||
+ | |||
+ | batocera-settings-set -f / | ||
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 -f /boot/config.txt enable_uart 1 |
- | echo "File is write protected!" | + | |
- | echo "I make boot-partition writeable" | + | |
- | mount -o remount, rw /boot | + | |
- | echo " | + | |
else | else | ||
echo "Key: enable_uart not found" | echo "Key: enable_uart not found" | ||
Line 111: | 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 / | #to set a new key in / | ||
- | value=$(batocera-settings --command write --key core.PS4.emulator | + | value=$(batocera-settings-set core.PS5.emulator |
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 " | + | |
- | + | ||
- | echo " | + | |
else | else | ||
- | echo "Annother | + | echo "Another |
fi | fi | ||
</ | </ | ||
=== 4. python: Obtain a key === | === 4. python: Obtain a key === | ||
- | |||
- | FIXME | ||
<code python| obtain_value.py> | <code python| obtain_value.py> | ||
+ | |||
# | # | ||
- | # -*- 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 / | #to read a value out from / | ||
import subprocess | import subprocess | ||
- | + | command=(["batocera-settings-get", " | |
- | value = (subprocess.check_output(['batocera-settings', 'get', 'power.switch.device' | + | rc = subprocess.call(command, |
- | if value: | + | if rc == 0: |
- | print "Power Switch Detected: ", value | + | value = subprocess.check_output(command).decode(" |
+ | print ("Power Switch Detected: ", value) | ||
else: | else: | ||
- | print "No power switch detected!" | + | print ("No power switch detected!" |
</ | </ | ||
+ | |||
+ | |||
+ |
- usage_of_batocera-settings.1580241120.txt.gz
- Last modified: 4 years ago
- by genetik57