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 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
52 changes: 33 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 @@ -56,18 +55,18 @@
from glob import glob
from os.path import basename, expanduser

STRING_NO_PATH = 'missing path'
STRING_NO_PATHS = 'missing paths'


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
paths = None
thresholds = [(0, 'bad'), (1, 'good')]

class Meta:
Expand All @@ -83,23 +82,35 @@ class Meta:
'new': 'icon_unavailable',
'msg': 'obsolete parameter use `icon_unavailable`'
},
{
'param': 'path',
'new': 'paths',
'msg': 'obsolete parameter use `paths`'
},
],
'rename_placeholder': [
{
'placeholder': 'paths',
'new': 'path',
'format_strings': ['format'],
},
],
}

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

# 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 +120,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,13 +148,16 @@ def file_status(self):
)

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

return {
'cached_until':
self.py3.time_in(self.cache_timeout),
'full_text': self.py3.safe_format(
'full_text':
self.py3.safe_format(
self.format, {
'path': count_path,
'paths': count_path,
'format_path': format_path
}
Expand Down