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

file_status: patch to fix plural wording #1389

Merged
merged 5 commits into from
Aug 9, 2018
Merged
Changes from 1 commit
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
41 changes: 22 additions & 19 deletions py3status/modules/file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
Configuration parameters:
cache_timeout: refresh interval for this module (default 10)
format: display format for this module
(default '\?color=paths [\?if=paths ●|■]')
(default '\?color=path [\?if=path ●|■]')
format_path: format for paths (default '{basename}')
format_path_separator: show separator if more than one (default ' ')
path: specify a string or a list of paths to check (default None)
paths: specify a string or a list of paths to check (default None)
thresholds: specify color thresholds to use
(default [(0, 'bad'), (1, 'good')])

Format placeholders:
{format_path} format for paths
{paths} number of paths, eg 1, 2, 3
{path} number of paths, eg 1, 2, 3

format_path placeholders:
{basename} basename of pathname
Expand All @@ -26,24 +26,23 @@

Color thresholds:
format:
paths: print a color based on the number of paths
path: print a color based on the number of paths

Examples:
```
# add multiple paths with wildcard or with pathnames
```
file_status {
path = ['/tmp/test*', '~user/test1', '~/Videos/*.mp4']
paths = ['/tmp/test*', '~user/test1', '~/Videos/*.mp4']
}

# colorize basenames
file_status {
path = ['~/.config/i3/modules/*.py']
paths = ['~/.config/i3/modules/*.py']
format = '{format_path}'
format_path = '\?color=good {basename}'
format_path_separator = ', '
}
```

@author obb, Moritz Lüdecke, Cyril Levis (@cyrinux)

SAMPLE OUTPUT
Expand All @@ -64,7 +63,7 @@ class Py3status:
"""
# available configuration parameters
cache_timeout = 10
format = u'\?color=paths [\?if=paths \u25cf|\u25a0]'
format = u'\?color=path [\?if=path \u25cf|\u25a0]'
format_path = u'{basename}'
format_path_separator = u' '
path = None
Expand All @@ -83,23 +82,28 @@ class Meta:
'new': 'icon_unavailable',
'msg': 'obsolete parameter use `icon_unavailable`'
},
{
'param': 'path',
'new': 'paths',
'msg': 'obsolete parameter use `paths`'
},
],
}

def post_config_hook(self):
if not self.path:
if not self.paths:
raise Exception(STRING_NO_PATH)

# icon deprecation
on = getattr(self, 'icon_available', u'\u25cf')
off = getattr(self, 'icon_unavailable', u'\u25a0')
new_icon = u'\?color=paths [\?if=paths {}|{}]'.format(on, off)
new_icon = u'\?color=path [\?if=path {}|{}]'.format(on, off)
self.format = self.format.replace('{icon}', new_icon)

# convert str to list + expand path
if not isinstance(self.path, list):
self.path = [self.path]
self.path = list(map(expanduser, self.path))
if not isinstance(self.paths, list):
self.paths = [self.paths]
self.paths = list(map(expanduser, self.paths))

self.init = {'format_path': []}
if self.py3.format_contains(self.format, 'format_path'):
Expand All @@ -109,7 +113,7 @@ def post_config_hook(self):

def file_status(self):
# init datas
paths = sorted([files for path in self.path for files in glob(path)])
paths = sorted([files for path in self.paths for files in glob(path)])
count_path = len(paths)
format_path = None

Expand Down Expand Up @@ -137,14 +141,13 @@ def file_status(self):
)

if self.thresholds:
self.py3.threshold_get_color(count_path, 'paths')
self.py3.threshold_get_color(count_path, 'path')

return {
'cached_until':
self.py3.time_in(self.cache_timeout),
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.py3.safe_format(
self.format, {
'paths': count_path,
'path': count_path,
Copy link
Contributor

@lasers lasers Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyrinux Can you add paths: count_path # deprecation here? This trips because it's a list. Deprecation replace_placeholder works on {paths} but not \?if=paths. Ty. Sorry. Xoxo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Xoxo ^^

'format_path': format_path
}
)
Expand Down