2009-05-05 00:18:39 -04:00
|
|
|
import fnmatch
|
2008-10-29 10:58:06 -04:00
|
|
|
import dirutil, os
|
|
|
|
from buffer import Buffer
|
|
|
|
|
2009-05-05 00:18:39 -04:00
|
|
|
ignore = ['*.o', '*.lo', '*.la', '#*#', '*.rej', '*~', '.#*', '.DS_Store',
|
|
|
|
'*.pyc', '*.pyo', '.sconsign.dblite']
|
|
|
|
|
2008-10-29 10:58:06 -04:00
|
|
|
class DirBuffer(Buffer):
|
|
|
|
btype = 'dir'
|
|
|
|
def __init__(self, path, name=None):
|
|
|
|
Buffer.__init__(self)
|
|
|
|
self.path = os.path.realpath(path)
|
2009-05-05 00:18:39 -04:00
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
self.settings['hide-dot'] = True
|
|
|
|
self.settings['type-sort'] = False
|
2009-05-05 00:18:39 -04:00
|
|
|
self.settings['hide-glob'] = True
|
|
|
|
self.settings['ignores'] = list(ignore)
|
|
|
|
|
2008-10-29 10:58:06 -04:00
|
|
|
def changed(self):
|
|
|
|
return False
|
|
|
|
def readonly(self):
|
|
|
|
return True
|
|
|
|
def name(self):
|
|
|
|
return self.path
|
|
|
|
def path_exists(self):
|
|
|
|
return os.path.exists(self.path)
|
|
|
|
|
|
|
|
def _get_names(self):
|
|
|
|
if not self.path_exists():
|
|
|
|
raise Exception, "directory %r does not exists" % self.path
|
|
|
|
names = os.listdir(self.path)
|
|
|
|
if self.path != '/':
|
|
|
|
names.insert(0, '..')
|
|
|
|
names.insert(0, '.')
|
|
|
|
return names
|
|
|
|
def _make_path(self, name):
|
|
|
|
return os.path.join(self.path, name)
|
|
|
|
def _get_lines(self):
|
|
|
|
names = self._get_names()
|
|
|
|
|
|
|
|
fieldlines = []
|
|
|
|
maxlens = [0] * 5
|
|
|
|
for name in names:
|
2009-03-29 20:50:27 -04:00
|
|
|
if self.settings.get('hide-dot'):
|
|
|
|
if name.startswith('.') and name not in ('.', '..'):
|
|
|
|
continue
|
2009-05-05 00:18:39 -04:00
|
|
|
if self.settings.get('hide-glob'):
|
|
|
|
skip = False
|
|
|
|
for glob in self.settings.get('ignores', []):
|
|
|
|
if fnmatch.fnmatch(name, glob):
|
|
|
|
skip = True
|
|
|
|
break
|
|
|
|
if skip:
|
|
|
|
continue
|
2008-10-29 10:58:06 -04:00
|
|
|
path = self._make_path(name)
|
|
|
|
fields = dirutil.path_fields(path, name)
|
|
|
|
for i in range(0, 5):
|
|
|
|
try:
|
|
|
|
maxlens[i] = max(maxlens[i], len(fields[i]))
|
|
|
|
except:
|
|
|
|
raise Exception, '%d %r' % (i, fields[i])
|
|
|
|
fieldlines.append(fields)
|
2009-03-29 20:50:27 -04:00
|
|
|
|
|
|
|
if self.settings.get('type-sort'):
|
|
|
|
fieldlines.sort(cmp=dirutil.path_sort)
|
|
|
|
else:
|
|
|
|
fieldlines.sort(cmp=dirutil.path_sort2)
|
2008-10-29 10:58:06 -04:00
|
|
|
fmt = '%%%ds %%-%ds %%-%ds %%%ds %%%ds %%s' % tuple(maxlens)
|
|
|
|
|
|
|
|
lines = []
|
|
|
|
for fields in fieldlines:
|
|
|
|
s = fmt % fields
|
|
|
|
lines.append(s)
|
|
|
|
return lines
|
|
|
|
def open(self):
|
|
|
|
self.lines = self._get_lines()
|
|
|
|
def reload(self):
|
|
|
|
lines = self._get_lines()
|
|
|
|
self.set_lines(lines, force=True)
|
|
|
|
def save(self, force=False):
|
|
|
|
raise Exception, "can't save a directory buffer"
|
|
|
|
def save_as(self, path):
|
|
|
|
raise Exception, "can't save a directory buffer"
|
|
|
|
|
|
|
|
class PathListBuffer(DirBuffer):
|
|
|
|
btype = 'pathlist'
|
|
|
|
def __init__(self, name, paths):
|
|
|
|
Buffer.__init__(self)
|
|
|
|
self.paths = list(paths)
|
|
|
|
self.path = os.getcwd()
|
|
|
|
self._name = name
|
2009-05-03 23:51:52 -04:00
|
|
|
self.settings['hide-dot'] = False
|
|
|
|
self.settings['type-sort'] = False
|
2008-10-29 10:58:06 -04:00
|
|
|
def path_exists(self):
|
|
|
|
raise Exception
|
|
|
|
def _get_names(self):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
return [x.replace(cwd, '.', 1) for x in self.paths]
|
|
|
|
def _make_path(self, name):
|
|
|
|
if name.startswith('.'):
|
|
|
|
return name.replace('.', os.getcwd(), 1)
|
|
|
|
else:
|
|
|
|
return name
|
|
|
|
def name(self):
|
|
|
|
return self._name
|