# -*- coding: utf-8 -*-
"""
Display if a file or dir exists.

Configuration parameters:
    cache_timeout: how often to run the check
    color_available: color of format_available
    color_unavailable: color of format_unavailable
    format_available: what to display when available
    format_unavailable: what to display when unavailable
    path: check if file or dir exists

@author obb, Moritz Lüdecke
"""

from time import time
import os


class Py3status:
    """
    """
    # available configuration parameters
    cache_timeout = 10
    color_available = None
    color_unavailable = None
    format_available = u'●'
    format_unavailable = u'■'
    path = '/dev/sdb1'

    def file_status(self, i3s_output_list, i3s_config):
        response = {
            'cached_until': time() + self.cache_timeout
        }

        if os.system("ls " + self.path + " >> /dev/null 2>&1") == 0:
            response['full_text'] = self.format_available
            response['color'] = self.color_available or i3s_config['color_good']
        else:
            response['full_text'] = self.format_unavailable
            response['color'] = self.color_unavailable or i3s_config['color_bad']

        return response

if __name__ == "__main__":
    """
    Test this module by calling it directly.
    """
    from time import sleep
    x = Py3status()
    config = {
        'color_good': '#00FF00',
        'color_bad': '#FF0000',
    }
    while True:
        print(x.file_status([], config))
        sleep(1)

@@ -439,16 +439,34 @@
 port os%0A
+import subprocess%0A
 %0A%0Aclass 
@@ -560,64 +560,8 @@
  10%0A
-    color_available = None%0A    color_unavailable = None%0A
     
@@ -794,61 +794,168 @@
     
-if os.system(%22ls %22 + self.path + %22 %3E%3E /dev/null 2%3E&1%22
+fnull = open(os.devnull, 'w')%0A        if subprocess.call(%5B%22ls%22, self.path%5D, stdout=fnull,%0A                                              stderr=subprocess.STDOUT
 ) ==
@@ -1051,32 +1051,8 @@
 '%5D =
- self.color_available or
  i3s
@@ -1182,34 +1182,8 @@
 '%5D =
- self.color_unavailable or
  i3s

Remove specific color params