Package plugins :: Package core :: Package complete :: Module domain_binpath |
[hide private]
[frames] | no frames]

# Source Code for Module plugins.core.complete.domain_binpath

     1  #-*- coding: utf8 -*
     2  #
     3  # Max E. Kuznecov ~syhpoon <mek@mek.uz.ua> 2008-2009
     4  #
     5  # This file is part of XYZCommander.
     6  # XYZCommander is free software: you can redistribute it and/or modify
     7  # it under the terms of the GNU Lesser Public License as published by
     8  # the Free Software Foundation, either version 3 of the License, or
     9  # (at your option) any later version.
    10  # XYZCommander is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  # GNU Lesser Public License for more details.
    14  # You should have received a copy of the GNU Lesser Public License
    15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
    16
    17  import os
    18  import itertools
    19
    20  from libxyz.core.utils import bstring
    21
    22  from domain_base import BaseDomain
    23
    24 -class Domain(BaseDomain):
    25      """
    26      Bin path domain
    27      """
    28
    29 -    def prepare(self):
    30          """
    31          Preparation stuff
    32          """
    33
    34          path = os.getenv("PATH", "")
    35
    36          for d in path.split(":"):
    37              self._update(d)
    38
    39      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    40
    41 -    def complete(self, buf):
    42          """
    43          Take current buffer and return list-generator of all
    44                  matched entries in current domain.
    45
    46          @param buf: Current buffer
    47          @return: list-generator
    48          """
    49
    50          return itertools.ifilter(lambda x: x.startswith(bstring(buf)),
    51                                   self._data)
    52
    53      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    54
    55 -    def _update(self, directory):
    56          """
    57          Update binpath set with files in directory
    58          """
    59
    60          for _, _, files in os.walk(directory):
    61              self._data |= set(files)
    62