bpozdena / OneDriveGUI

A simple GUI for OneDrive Linux client with multi-account support.
GNU General Public License v3.0
750 stars 34 forks source link

Import profile: support multiple skip_dir/skip_file entries #65

Closed mjbogusz closed 1 year ago

mjbogusz commented 2 years ago

As per the onedrive usage docs, the skip_dir and skip_file entries can be specified multiple times.

Right now OneDriveGUI fails to parse such a config with no GUI-visible error, only with a traceback on the console:

Traceback (most recent call last):
  File "/tmp/.mount_OneDriuGuN24//usr/src/OneDriveGUI.py", line 783, in import_profile
    _new_od_config = read_config(config_path)
  File "/tmp/.mount_OneDriuGuN24//usr/src/OneDriveGUI.py", line 2774, in read_config
    config.read_string(config_string)
  File "/tmp/.mount_OneDriuGuN24/usr/lib/python3.8/configparser.py", line 723, in read_string
    self.read_file(sfile, source)
  File "/tmp/.mount_OneDriuGuN24/usr/lib/python3.8/configparser.py", line 718, in read_file
    self._read(f, source)
  File "/tmp/.mount_OneDriuGuN24/usr/lib/python3.8/configparser.py", line 1093, in _read
    raise DuplicateOptionError(sectname, optname,
configparser.DuplicateOptionError: While reading from '<string>' [line 12]: option 'skip_dir' in section 'onedrive' already exists

A simple workaround is to merge the multiple lines with a pipe (|) as per the docs linked above - this allows the profile to be imported successfully.

bpozdena commented 1 year ago

Unfortunately, I will not be able to support this. It would need a significant rewrite.

Please define all your skip_dir and skip_file entries within a single line for now. The pipe separator is of course supported in the GUI as well.

I will try to improve the error handling. I will also look into auto-converting the entries into a single line.

mjbogusz commented 1 year ago

From configparser docs:

When strict is True (the default), the parser won’t allow for any section or option duplicates while reading from a single source (file, string or dictionary), raising DuplicateSectionError or DuplicateOptionError. [...] Otherwise, internal empty lines of a multiline option are kept as part of the value.

I'm not sure how it concatenates the options though, and it's mostly relevant for the one-time import; Therefore I'd consider a clear error message with the single-line workaround mentioned a very valid solution.

bpozdena commented 1 year ago

Multi-line options 'skip_file' and 'skip_dir' will now be automatically consolidated into a single line.