-
-
Notifications
You must be signed in to change notification settings - Fork 261
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: allow several paths, new format #1369
Changes from 12 commits
3054842
1909b9e
bced76b
eec5c31
1b4c212
d1e5567
e7fd61e
5933dde
4484da1
d76b49d
ef9825e
08b7481
24a5160
c96a435
8fa66b0
e15eedc
fb4c723
67e26e6
b84fda9
fb82b53
0bfe17a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Display if a file or directory exists. | ||
Display if a files or directories exists. | ||
|
||
Configuration parameters: | ||
cache_timeout: how often to run the check (default 10) | ||
format: format of the output. (default '{icon}') | ||
icon_available: icon to display when available (default '●') | ||
icon_unavailable: icon to display when unavailable (default '■') | ||
path: the path to a file or dir to check if it exists (default None) | ||
format: format of the output. (default '\?color=paths [\?if=paths ●|■]') | ||
format_path: format of the path output. (default '{basename}') | ||
format_path_separator: show separator if more than one (default ' ') | ||
path: the path(s) to a file or dir to check if it exists, take a list (default None) | ||
thresholds: specify color thresholds to use (default [(0, 'bad'), (1, 'good')]) | ||
|
||
Color options: | ||
color_bad: Error or file/directory does not exist | ||
color_good: File or directory exists | ||
|
||
Format placeholders: | ||
{icon} icon for the current availability | ||
|
||
@author obb, Moritz Lüdecke | ||
{format_path} paths of matching files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a
|
||
{paths} number of paths, eg 1, 2, 3 | ||
|
||
format_path path placeholders: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format_path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick :) |
||
{basename} basename of matching files | ||
{fullpath} fullpath of matching files | ||
|
||
Examples: | ||
``` | ||
# check files with wildcard, or contain user path, full paths | ||
file_status { | ||
path = ['/tmp/test*', '~user/test1'] | ||
format = u'\?if=paths ● {format_path}|■ no files found' | ||
format_path = '{fullpath}' | ||
} | ||
|
||
# change color on files match | ||
file_status { | ||
path = ['/tmp/test*', '~user/test1'] | ||
format = u'\?color=paths ●' | ||
thresholds = [(0, 'bad'), (1, 'good')] | ||
} | ||
``` | ||
|
||
@author obb, Moritz Lüdecke, Cyril Levis (@cyrinux), @lasers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Thank you, but you can keep me out of this. I'm just helping you, bro. Thank you, bro. 👊 |
||
|
||
SAMPLE OUTPUT | ||
{'color': '#00FF00', 'full_text': u'\u25cf'} | ||
|
@@ -25,20 +48,23 @@ | |
{'color': '#FF0000', 'full_text': u'\u25a0'} | ||
""" | ||
|
||
from os.path import expanduser, exists | ||
from glob import glob | ||
from os.path import basename, expanduser | ||
|
||
ERR_NO_PATH = 'no path given' | ||
DEFAULT_FORMAT = u'\?color=paths [\?if=paths ●|■]' | ||
|
||
|
||
class Py3status: | ||
""" | ||
""" | ||
# available configuration parameters | ||
cache_timeout = 10 | ||
format = '{icon}' | ||
icon_available = u'●' | ||
icon_unavailable = u'■' | ||
format = DEFAULT_FORMAT | ||
format_path = u'{basename}' | ||
format_path_separator = u' ' | ||
path = None | ||
thresholds = [(0, 'bad'), (1, 'good')] | ||
|
||
class Meta: | ||
deprecated = { | ||
|
@@ -57,8 +83,25 @@ class Meta: | |
} | ||
|
||
def post_config_hook(self): | ||
# deprecation | ||
on = getattr(self, 'icon_available', None) | ||
off = getattr(self, 'icon_unavailable', None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not same from diff I gave you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oups. 😜 |
||
if self.format == DEFAULT_FORMAT and (on or off): | ||
self.format = u'\?if=paths {}|{}'.format(on or u'●', off or u'■') | ||
msg = 'DEPRECATION: you are using old style configuration ' | ||
msg += 'parameters you should update to use the new format.' | ||
self.py3.log(msg) | ||
|
||
if self.path: | ||
self.path = expanduser(self.path) | ||
# backward compatibility, str to list | ||
if not isinstance(self.path, list): | ||
self.path = [self.path] | ||
# expand user paths | ||
self.path = list(map(expanduser, self.path)) | ||
|
||
self.init = { | ||
'format_path': self.py3.get_placeholders_list(self.format_path) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep this so we can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a doubt about this, refresh is for example when I There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not understand this sorry, could you rephrase? "I'd clear this with the fam first." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have a discussion with tobes and/or ultrabug. They our fam. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, fam = familly >_> |
||
def file_status(self): | ||
if self.path is None: | ||
|
@@ -68,17 +111,40 @@ def file_status(self): | |
'cached_until': self.py3.CACHE_FOREVER, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Master Splinter! Or see STRING_NO_PATH = 'missing path' def post_config_hook(self):
if not self.path:
raise Exception(STRING_NO_PATH) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha ok I was far away |
||
} | ||
|
||
if exists(self.path): | ||
icon = self.icon_available | ||
color = self.py3.COLOR_GOOD | ||
else: | ||
icon = self.icon_unavailable | ||
color = self.py3.COLOR_BAD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There sure are lot of changes. We might as well see this all the way to finish... by removing colors, make and default This module is useful now because I can use this to print names of custom modules... and globbing. Thank you for working on this. :-) |
||
# init datas | ||
paths = sorted([files for path in self.path for files in glob(path)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this, we don't need |
||
paths_number = len(paths) | ||
|
||
# get thresholds | ||
if self.thresholds: | ||
self.py3.threshold_get_color(paths_number, 'paths') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Request) Move this down right before the return (traditionally left at bottom for looping or such). |
||
|
||
# format paths | ||
if self.init['format_path']: | ||
format_path = {} | ||
format_path_separator = self.py3.safe_format( | ||
self.format_path_separator) | ||
|
||
for key in self.init['format_path']: | ||
if key == 'basename': | ||
temps_paths = map(basename, paths) | ||
elif key == 'fullpath': | ||
temps_paths = paths | ||
else: | ||
continue | ||
format_path[key] = self.py3.composite_join( | ||
format_path_separator, temps_paths) | ||
|
||
format_path = self.py3.safe_format(self.format_path, format_path) | ||
|
||
response = { | ||
'cached_until': self.py3.time_in(self.cache_timeout), | ||
'full_text': self.py3.safe_format(self.format, {'icon': icon}), | ||
'color': color | ||
'cached_until': | ||
self.py3.time_in(self.cache_timeout), | ||
'full_text': | ||
self.py3.safe_format(self.format, { | ||
'paths': paths_number, | ||
'format_path': format_path | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Request) An attempt on creating consistency in all modules and could be a project's coding style if we were to document it... to make it more readability or such. return {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.py3.safe_format(
self.format, {
'paths': count_paths,
'format_path': format_path
}
)
} |
||
} | ||
|
||
return response | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long imo.
path: specify a string or a list of paths to check (default None)