1
# arch-tag: 75709428-970d-4bba-ac1c-7e1e7428345f
2
# Copyright (C) 2004 David Allouche <david@allouche.net>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program 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 General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""File name manipulation."""
21
__all__ = ['PathName', 'DirName', 'FileName']
28
"""String with extra methods for filename operations."""
30
def __new__(cls, path='.'):
31
return str.__new__(cls, os.path.normpath(path))
33
def __div__(self, path):
34
if isinstance(path, (DirName, FileName)):
38
return ctor(os.path.join(self, path))
41
return '%s(%s)' % (type(self).__name__, str.__repr__(self))
44
return self.__class__(os.path.abspath(self))
46
return DirName(os.path.dirname(self))
48
return self.__class__(os.path.basename(self))
51
if 'realpath' in dir(os.path):
52
return self.__class__(os.path.realpath(self))
57
dir_, base = os.path.split(self)
58
return DirName(dir_), self.__class__(base)
61
class DirName(PathName):
63
"""PathName, further characterized as a directory name."""
66
class FileName(PathName):
68
"""PathName further characterized as a file name."""