Source code for epygram.containers
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
containers:
Contains the containers for a Resource.
"""
from footprints import FootprintBase
from epygram.util import RecursiveObject
[docs]class File(RecursiveObject, FootprintBase):
"""
Generic class implementing a File.
"""
_collector = ('container', 'file')
_footprint = dict(
attr=dict(
filename=dict(
type=str,
alias=('f',),
info='Relative or absolute pathname.')
)
)
def __init__(self, *args, **kwargs):
"""
Constructor. See its footprint for arguments.
"""
import os
# super to footprints constructor
super(File, self).__init__(*args, **kwargs)
# initialise absolute pathname
self._abspath = os.path.abspath(self.filename)
@property
[docs] def basename(self):
"""
Returns the basename of the file.
"""
import os
return os.path.basename(self._abspath)
@property
[docs] def abspath(self):
"""
Returns the absolute path of the file.
"""
return self._abspath
@property
[docs] def absdir(self):
"""
Returns the absolute path of the directory of the file.
"""
return self._abspath[:-len(self.basename)]