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

Source Code for Module plugins.core.complete.domain_fs

 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 Filesystem domain 27 """ 28
29 - def complete(self, buf):
30 """ 31 Take current buffer and return list-generator of all 32 matched entries in current domain. 33 34 @param buf: Current buffer 35 @return: list-generator 36 """ 37 38 buf = bstring(buf) 39 40 if os.path.isdir(buf): 41 _dir = buf 42 _obj = "" 43 # Treat as current dir 44 elif os.path.sep not in buf: 45 _dir = "." 46 _obj = buf 47 else: 48 _dir = os.path.dirname(buf) 49 _obj = os.path.basename(buf) 50 51 _, dirs, files = os.walk(_dir).next() 52 53 return itertools.ifilter(lambda x: x.startswith(_obj), dirs + files)
54