-
-
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 7 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 |
---|---|---|
|
@@ -4,28 +4,46 @@ | |
|
||
Configuration parameters: | ||
cache_timeout: how often to run the check (default 10) | ||
format: format of the output. (default '{icon}') | ||
format: format of the output. (default '{icon} {format_path}') | ||
format_path: format of the path output. (default '{basename}') | ||
format_path_separator: show separator if more than one (default ' ') | ||
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) | ||
path: the path(s) to a file or dir to check if it exists, take a list (default None) | ||
|
||
Color options: | ||
color_bad: Error or file/directory does not exist | ||
color_good: File or directory exists | ||
|
||
Format placeholders: | ||
{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
|
||
{icon} icon for the current availability | ||
|
||
@author obb, Moritz Lüdecke | ||
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_path = '{fullpath}' | ||
} | ||
``` | ||
|
||
@author obb, Moritz Lüdecke, Cyril Levis (@cyrinux) | ||
|
||
SAMPLE OUTPUT | ||
{'color': '#00FF00', 'full_text': u'\u25cf'} | ||
{'color': '#00FF00', 'full_text': u'\u25cf test.py'} | ||
|
||
missing | ||
{'color': '#FF0000', 'full_text': u'\u25a0'} | ||
""" | ||
|
||
from os.path import expanduser, exists | ||
from glob import glob | ||
from itertools import chain | ||
from os.path import basename, expanduser | ||
|
||
ERR_NO_PATH = 'no path given' | ||
|
||
|
@@ -35,7 +53,9 @@ class Py3status: | |
""" | ||
# available configuration parameters | ||
cache_timeout = 10 | ||
format = '{icon}' | ||
format = u'{icon} {format_path}' | ||
format_path = u'{basename}' | ||
format_path_separator = u' ' | ||
icon_available = u'●' | ||
icon_unavailable = u'■' | ||
path = None | ||
|
@@ -58,7 +78,11 @@ class Meta: | |
|
||
def post_config_hook(self): | ||
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)) | ||
|
||
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,16 +92,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 | ||
# init data | ||
file_status_data = {} | ||
# expand glob from paths | ||
paths = list(map(glob, self.path)) | ||
# merge list of paths | ||
paths = [x for x in chain.from_iterable(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. I wonder if it is more efficient 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. Idk 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. Try 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. Dont know if this is better but it works :) not used to read this :| |
||
|
||
# fill data | ||
file_status_data['icon'] = self.icon_unavailable | ||
color = self.py3.COLOR_BAD | ||
|
||
if paths: | ||
file_status_data['icon'] = self.icon_available | ||
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. Here, I really would like to deprecate I guess we stick with just Just mentioning that 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. So i remove legacy stuff? Or I just add 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. Ideally, we do no more than to It'd be good to ask the fam first about deprecating |
||
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. :-) |
||
|
||
# format paths | ||
if self.format_path: | ||
format_path = {} | ||
|
||
format_path_separator = self.py3.safe_format( | ||
self.format_path_separator) | ||
|
||
format_path['basename'] = self.py3.composite_join( | ||
format_path_separator, map(basename, paths)) | ||
|
||
format_path['full'] = self.py3.composite_join( | ||
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. Due to glob, there can be many things in the list. We could be a bit more efficient by using Look |
||
format_path_separator, paths) | ||
|
||
file_status_data['format_path'] = self.py3.safe_format( | ||
self.format_path, format_path) | ||
|
||
response = { | ||
'cached_until': self.py3.time_in(self.cache_timeout), | ||
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. In my example I use |
||
'full_text': self.py3.safe_format(self.format, {'icon': icon}), | ||
'full_text': self.py3.safe_format(self.format, file_status_data), | ||
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. (Opinion). May look cleaner if we pass |
||
'color': color | ||
} | ||
|
||
|
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)