Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISK] Fixes df output parsing when FS column contains whitespaces #102

Merged
merged 3 commits into from
Oct 16, 2021

Conversation

lourinaldi
Copy link
Contributor

@lourinaldi lourinaldi commented Sep 21, 2021

use the float() method to avoid invalid literal for int() with base 10

Description

The Python ValueError: invalid literal for int() with base 10 error is raised when you try to convert a string value that is not formatted as an integer.

To solve this problem, you can use the float() method to convert a floating-point number in a string to an integer. Then, you can use int() to convert your number to an integer.

Reason and / or context

Traceback (most recent call last):
  File "/opt/homebrew/bin/archey", line 33, in <module>
    sys.exit(load_entry_point('archey4==4.13.1', 'console_scripts', 'archey')())
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/__main__.py", line 168, in main
    for entry_instance in mapper(_entry_instantiator, available_entries):
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 608, in result_iterator
    yield fs.pop().result()
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/opt/homebrew/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/__main__.py", line 144, in _entry_instantiator
    return Entries[entry.pop('type')].value(
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/entries/disk.py", line 18, in __init__
    self._disk_dict = self._get_df_output_dict()
  File "/opt/homebrew/Cellar/archey4/4.13.1/libexec/lib/python3.9/site-packages/archey/entries/disk.py", line 133, in _get_df_output_dict
    'total_blocks': int(columns[1])
ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'

How has this been tested ?

Python 3.9.7 on MacOS 11.6

Types of changes :

  • Bug fix (non-breaking change which fixes an issue)
  • Typo / style fix (non-breaking change which improves readability)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist :

  • [IF NEEDED] I have updated the README.md file accordingly ;
  • [IF NEEDED] I have updated the test cases (which pass) accordingly ;
  • [IF BREAKING] This pull request targets next Archey version branch ;
  • My changes looks good ;
  • I agree that my code may be modified in the future ;
  • My code follows the code style of this project (PEP8).

@HorlogeSkynet
Copy link
Owner

Hey, thanks for opening this up.
From your traceback, I don't think your patch would fix anything : "ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'".
There seems to be a problem related to the parsing of df output, as encountered on Windows.
Could you paste here the output of df -P -k on your system ?

Thanks, bye 👋

@lourinaldi
Copy link
Contributor Author

Hey, thanks for opening this up.
From your traceback, I don't think your patch would fix anything : "ValueError: invalid literal for int() with base 10: 'Us.app/Wrapper'".
There seems to be a problem related to the parsing of df output, as encountered on Windows.
Could you paste here the output of df -P -k on your system ?

Thanks, bye 👋

So it looks like it didn't like whitespace in the Volume name under the "Filesystem" column of df's output (/Applications/Among Us.app/Wrapper).

@HorlogeSkynet
Copy link
Owner

Indeed, the parsing is currently very naive, as based on whitespaces. It worked well on *NIX and derivatives as the filesystem column was not supposed to contain any whitespace. I'll try to fix this without aiming for proper Windows support (as originally planned), as you are already concerned on macOS.
Cheers

@HorlogeSkynet HorlogeSkynet changed the title use the float() method to avoid invalid literal for int() with base 10 [DISK] Fixes df output parsing when FS column contains whitespaces Sep 22, 2021
@HorlogeSkynet HorlogeSkynet self-assigned this Sep 22, 2021
@HorlogeSkynet HorlogeSkynet added the bug 🐛 A real glitch has been found label Sep 22, 2021
@HorlogeSkynet
Copy link
Owner

@lourinaldi please check the updated patch and tell me whether it suits you.
If you can provide a "real" example in unit tests, it would be great.
Bye 👋

@HorlogeSkynet HorlogeSkynet linked an issue Oct 12, 2021 that may be closed by this pull request
@HorlogeSkynet HorlogeSkynet merged commit 0e21951 into HorlogeSkynet:master Oct 16, 2021
@HorlogeSkynet HorlogeSkynet added the no answer 😶 The OP does not answer anymore. Frozen due to age label Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 A real glitch has been found no answer 😶 The OP does not answer anymore. Frozen due to age
Projects
Status: DONE
Development

Successfully merging this pull request may close these issues.

[BUG] archey4 can't handle filesystems with spaces
2 participants