brailcom / brailcom/speechd

Error when creating user config for the first time

Open
#747 3 comments 0 reactions 0 assignees View on GitHub
bug needinfo
Dominant language
C
Stars
331
Forks
92
Avg merge
2d 10h
Merged PRs (30d)
9

Description

### Steps to reproduce

1. Have a fresh installation of speech dispatcher or a fresh user account or delete your `~/.config/speech-dispatcher` folder
2. Run `spd-conf` as user with any configuration (default values are fine)

### Obtained behavior

Instead of saving the file at the end, speech-dispatcher errors out:
```
$ spd-config
[…]
>
Default speech pitch range (on the scale of -100..100, 0 is default, 50 is higher, -50 is lower) [0] :
>
Traceback (most recent call last):
File "/usr/bin/spd-conf", line 26, in
sys.exit(speechd_config.main())
File "/usr/lib64/python3.10/site-packages/speechd_config/config.py", line 841, in main
configure.complete_config()
File "/usr/lib64/python3.10/site-packages/speechd_config/config.py", line 754, in complete_config
self.configure_basic_settings(type='user')
File "/usr/lib64/python3.10/site-packages/speechd_config/config.py", line 673, in configure_basic_settings
self.options_substitute(configfile,
File "/usr/lib64/python3.10/site-packages/speechd_config/config.py", line 549, in options_substitute
for line in fileinput.input(configfile, inplace=True, backup=".bak"):
File "/usr/lib64/python3.10/fileinput.py", line 256, in __next__
line = self._readline()
File "/usr/lib64/python3.10/fileinput.py", line 357, in _readline
os.rename(self._filename, self._backupfilename)
FileNotFoundError: [Errno 2] Datei oder Verzeichnis nicht gefunden: '/home/[username]/.config/speech-dispatcher/speechd.conf' -> '/home/[username]/.config/speech-dispatcher/speechd.conf.bak'
```

### Expected behavior

Save file at end of following configuration wizard `spd-conf`.

### Behavior information

(does not apply as this is not a bug in the speech-dispatcher daemon)

### Distribution

Fedora 36

### Version of Speech-dispatcher

```
speech-dispatcher-0.11.1-2.fc36.x86_64
speech-dispatcher-espeak-ng-0.11.1-2.fc36.x86_64
speech-dispatcher-utils-0.11.1-2.fc36.x86_64
speech-dispatcher-flite-0.11.1-2.fc36.x86_64
```

### Additional notes

I think (but I am not 100% sure) that this issue is the same as #649 which hasn't been fixed completely. That fix has landed in the 0.11.1 release (which I'm running) as far as I understand [from the git history of 0.11 branch](https://github.com/brailcom/speechd/commits/speech-dispatcher-0-11).

I think, the actual cause of the traceback is different: The file `~/.config/speech-dispatcher/speechd.conf` does not exist on a fresh installation or after deleting `~/.config/speech-dispatcher`. When `fileinput.input()` is called on that code, the `fileinput` module relies on the existence of that file and tries to rename it using `os.rename()` ([source code](https://github.com/python/cpython/blob/9369942054fe3fe389f4f4ff808d33c5d7945052/Lib/fileinput.py#L171)).

If I understand the issue correctly, there should be some code creating¹ that file if it does not exist yet. That code should probably be placed at the beginning of [`options_substitute`](https://github.com/brailcom/speechd/blob/master/src/api/python/speechd_config/config.py#L534) before calling `fileinput.input()`.

_____
¹ or copying from the default config file. I don't know the code well enough to tell.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/api/python/speechd_config/config.py at options_substitute, then follow how spd-conf handles a fresh user configuration. Reproduce with a fresh installation or without ~/.config/speech-dispatcher/speechd.conf. Done means the wizard completes and saves the user configuration without the fileinput traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.