dotdrop icon indicating copy to clipboard operation
dotdrop copied to clipboard

[bug] Unknown format code ValueError when do dotdrop compare

Open roachsinai opened this issue 5 months ago • 2 comments

Dotdrop version (and git commit if run from source): v1.14.0 https://github.com/deadc0de6/dotdrop/tree/fix-428

Describe the bug

Get below error when run dotdrop compare:

Traceback (most recent call last):
  File "/usr/bin/dotdrop", line 33, in <module>
    sys.exit(load_entry_point('dotdrop==1.14.0', 'console_scripts', 'dotdrop')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/__init__.py", line 13, in main
    if dotdrop.dotdrop.main():
       ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/dotdrop.py", line 952, in main
    ret, command = _exec_command(opts)
                   ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/dotdrop.py", line 874, in _exec_command
    ret = cmd_compare(opts, tmp)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/dotdrop.py", line 459, in cmd_compare
    if not _dotfile_compare(opts, dotfile, tmp):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/dotdrop.py", line 166, in _dotfile_compare
    diff = comp.compare(src, dotfile.dst, ignore=ignores, mode=dotfile.chmod)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/comparator.py", line 66, in compare
    ret = self._comp_mode(local_path, deployed_path, mode=mode)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/dotdrop/comparator.py", line 82, in _comp_mode
    msg = f'mode differ {local_path} ({local_mode:o}) '
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Unknown format code 'o' for object of type 'str'

Value of local_path: /home/xq/code/Git/dotfiles/dotfiles/vim/snip.

Value of local_mode: preserve.

Steps to Reproduce

Steps to reproduce the behavior:

Create a dotfile with content:

config:
  backup: true
  banner: false
  create: true
  dotpath: dotfiles
  ignoreempty: false
  keepdot: false
  workdir: ~/.config/dotdrop
dotfiles:
  d__snip:
    src: vim/snip
    dst: /mnt/c/Users/xq/vimfiles/snip
    chmod: preserve
profiles:
  wsl-win:
    dotfiles:
    - d__snip

run dotdrop compare -p wsl-win

The error may is local_mode is a python string.

roachsinai avatar Jan 27 '24 12:01 roachsinai

Thanks for reporting this however you're saying you're running dotdrop from branch fix-428? Can you please try with the master branch and let me know if that bug is also there?

deadc0de6 avatar Jan 28 '24 09:01 deadc0de6

Hi @deadc0de6 , get same error when using master branch.

roachsinai avatar Jan 29 '24 06:01 roachsinai

Ok, I'll look into it, thanks for testing

deadc0de6 avatar Jan 31 '24 21:01 deadc0de6

@roachsinai I did some refactoring on dotdrop. Can you retest it with the master branch and let me know if the bug is still here?

deadc0de6 avatar Feb 18 '24 21:02 deadc0de6

Hi @deadc0de6 on my test master branch fixed this issue. Thanks a lot!!!

Futher more, get below verbose if has unimported file under a directory which managed by dotdrop:

image

roachsinai avatar Feb 19 '24 17:02 roachsinai

Cool! You can ignore unimported files with the ignore pattern. Do you need help?

deadc0de6 avatar Feb 19 '24 17:02 deadc0de6

Yeahhh, thanks a lot. Is there a doc link? And how about the modes differ the reason is dst is windows filesystem (everything is 777).

roachsinai avatar Feb 20 '24 05:02 roachsinai

Yes, you can either ignore completely anything that is not present in dotdrop with the global option ignore_missing_in_dotdrop (doc is here). This option can also be set per dotfile (see here).

Or you can use patterns to match the different directory with cmpignore (doc is here). For example to ignore everything under snip and watch_later for some dotfile:

dotfiles:
  d_some
    dst: ~/.some
    src: some
    cmpignore:
    - '*/snip/*'
    - '*/watch_later/*'

Regarding the permission, there's currently no option to ignore those during a compare. Have you tried simply removing the chmod entry on the dotfile? Since if on windows it's 777 anyway, there's no reason to have it in the config.

deadc0de6 avatar Feb 21 '24 20:02 deadc0de6

Thanks. Very helpful!

Regarding the permission, preserve remove the confirm when run dotdrop install.

roachsinai avatar Feb 22 '24 15:02 roachsinai