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

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

     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, split_cmd
    21
    22  from domain_base import BaseDomain
    23
    24 -class Domain(BaseDomain):
    25      """
    26      service(8) domain
    27      """
    28
    29      INITD_DIR = "/etc/init.d"
    30
    31 -    def complete(self, buf):
    32          """
    33          Take current buffer and return list-generator of all
    34                  matched entries in current domain.
    35
    36          @param buf: Current buffer
    37          @return: list-generator
    38          """
    39
    40          cmd = split_cmd(bstring(buf))
    41
    42          _len = len(cmd)
    43
    44          if len(cmd) == 1:
    45              obj = ""
    46          else:
    47              obj = cmd[-1]
    48
    49          _, _, files = os.walk(self.INITD_DIR).next()
    50
    51          return itertools.ifilter(lambda x: x.startswith(obj), files)
    52