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

Skipping directories that fail to be read when walking #68

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ To start unittests, use
```bash
sudo python3 setup.py install
python3 tests/test.py
python3 tests/test.py discoverer.DiscovererTest.test_read_tags
```

## Copyright and Acknowledgements
Expand Down
5 changes: 5 additions & 0 deletions bin/soundconverter
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ except (ImportError, ValueError) as error:
# For args compatible to gstreamer, see `gst-launch-1.0 --help-gst`
args = Gst.init(sys.argv)

if type(args) != list:
# in tests it just suddenly returns a boolean instead. when writing tests,
# beware that `--gst-...` arguments are not filtered here
args = sys.argv

from soundconverter.util.settings import settings
from soundconverter.interface.batch import batch_main, \
CLICheck, use_memory_gsettings, validate_args
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
# USA

import sys

try:
import DistUtilsExtra.auto
except ImportError:
except ImportError as e:
sys.stderr.write('You need python-distutils-extra\n')
sys.stderr.write(e)
sys.exit(1)

import os
Expand Down
32 changes: 22 additions & 10 deletions soundconverter/util/fileoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,29 @@ def vfs_walk(uri):
return a list of uri.
"""
filelist = []
dirlist = Gio.file_parse_name(uri).enumerate_children(
'*', Gio.FileMonitorFlags.NONE, None
)
for file_info in dirlist:
info = dirlist.get_child(file_info).query_file_type(
Gio.FileMonitorFlags.NONE, None

try:
dirlist = Gio.file_parse_name(uri).enumerate_children(
'*', Gio.FileMonitorFlags.NONE, None
)
if info == Gio.FileType.DIRECTORY:
filelist.extend(vfs_walk(dirlist.get_child(file_info).get_uri()))
if info == Gio.FileType.REGULAR:
filelist.append(str(dirlist.get_child(file_info).get_uri()))

for file_info in dirlist:
info = dirlist.get_child(file_info).query_file_type(
Gio.FileMonitorFlags.NONE, None
)

uri = dirlist.get_child(file_info).get_uri();

if info == Gio.FileType.DIRECTORY:
filelist.extend(vfs_walk(uri))

if info == Gio.FileType.REGULAR:
filelist.append(str(uri))
except Exception as e:
# this is impossible to write unittests for, because this only happens
# when the owner of this directory is e.g. root
logger.error('Failed to walk "%s": "%s"', uri, e)

return filelist


Expand Down
4 changes: 2 additions & 2 deletions soundconverter/util/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def format(self, record):
if settings['debug']:
self._style._fmt = ( # noqa
'\033[{}m%(levelname)s\033[0m: '
'%(filename)s, line %(lineno)d, %(msg)s'
'%(filename)s, line %(lineno)d, %(message)s'
).format(color)
else:
self._style._fmt = ( # noqa
'\033[{}m%(levelname)s\033[0m: %(msg)s'
'\033[{}m%(levelname)s\033[0m: %(message)s'
).format(color)
return super().format(record)

Expand Down
2 changes: 1 addition & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# in all of the available tests like unittest.main() does...,
# so provide both options.
if len(modules) > 0:
# for example `tests/test.py integration.GUI`
# for example `python3 tests/test.py discoverer.DiscovererTest.test_read_tags`
testsuite = unittest.defaultTestLoader.loadTestsFromNames(
['testcases.{}'.format(module) for module in modules]
)
Expand Down
Loading