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: allow several paths, new format #1369

Merged
merged 21 commits into from
Jul 5, 2018
Merged
Changes from 2 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
25 changes: 14 additions & 11 deletions py3status/modules/file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
{'color': '#FF0000', 'full_text': u'\u25a0'}
"""

from os.path import expanduser, exists
from glob import glob
from os.path import exists, expanduser

ERR_NO_PATH = 'no path given'

Expand Down Expand Up @@ -56,10 +57,6 @@ class Meta:
],
}

def post_config_hook(self):
if self.path:
self.path = expanduser(self.path)

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep this so we can do expanduser(path) once instead of every refresh interval.

Copy link
Contributor Author

@cyrinux cyrinux Jun 12, 2018

Choose a reason for hiding this comment

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

I had a doubt about this, refresh is for example when I py3-cmd resfresh file_status? I thought this part was only excecuted at the py3status start/restart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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."

Copy link
Contributor

Choose a reason for hiding this comment

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

Have a discussion with tobes and/or ultrabug. They our fam.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:
return {
Expand All @@ -68,12 +65,18 @@ def file_status(self):
'cached_until': self.py3.CACHE_FOREVER,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this to post_config_hook too. See hamster for an example.

Copy link
Contributor Author

@cyrinux cyrinux Jun 19, 2018

Choose a reason for hiding this comment

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

hamster from which branch? :)

Copy link
Contributor

@lasers lasers Jun 19, 2018

Choose a reason for hiding this comment

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

Master Splinter! Or see weather_yahoo.. or to be more specific, do like this...

STRING_NO_PATH = 'missing path'
    def post_config_hook(self):
        if not self.path:
            raise Exception(STRING_NO_PATH)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 thresholds with 0, 1. With glob and several paths implemented, we might want thresholds anyway as it would enhance this module... allowing us to print colors based on number of paths somewhere.

This module is useful now because I can use this to print names of custom modules... and globbing. Thank you for working on this. :-)

paths = glob(expanduser(self.path))
if isinstance(paths, str):
paths = [paths]
Copy link
Contributor

Choose a reason for hiding this comment

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

When we glob stuffs, is paths not always a list? Also, to get rid of expanduser here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is not always a list, if there is nothing to glob the return stay a str

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what to make of this. Consult with the fam.

Copy link
Contributor Author

@cyrinux cyrinux Jun 12, 2018

Choose a reason for hiding this comment

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

weird, will retry

glob.glob(pathname, , recursive=False)
Return a possibly-empty list of path names that match pathname, which must be a string containing a path specification. pathname can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (like ../../Tools/
/*.gif), and can contain shell-style wildcards. Broken symlinks are included in the results (as in the shell).


icon = self.icon_unavailable
color = self.py3.COLOR_BAD

for path in paths:
if exists(path):
Copy link
Contributor

Choose a reason for hiding this comment

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

If we use glob, then we might not need exists anymore -- Try if paths: instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok for this :)

icon = self.icon_available
color = self.py3.COLOR_GOOD
break

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
Copy link
Contributor

Choose a reason for hiding this comment

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

cache_timeout = -1 in your example means once. You may want cache_timeout = 0 instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my example I use py3-cmd refresh file_status for try ;)

Expand Down