Commit aac73ac0 authored by eric pellegrini's avatar eric pellegrini
Browse files

Modified the API for better coherence among IInputData concrete classes

parent 67a74d04
......@@ -36,18 +36,4 @@ class EmptyData(IInputData):
type = "empty_data"
extension = None
count = 0
def __init__(self, filename, *args, **kwargs):
IInputData.__init__(self, filename, *args, **kwargs)
self._data = None
if filename is None:
self._filename = self._basename = 'empty_' + str(EmptyData.count)
EmptyData.count += 1
else:
self._filename = self._basename = filename
extension = None
\ No newline at end of file
......@@ -47,37 +47,31 @@ class IInputData(object):
type = "input_data"
def __init__(self, *args, **kwargs):
def __init__(self,name, *args):
'''
Builds an ``IInputData`` object.
'''
self._name = name
self._data = None
self._filename = None
@property
def filename(self):
def name(self):
'''
Returns the filename associated with the input data.
Returns the name associated with the input data.
:return: the filename associated with the input data.
:return: the name associated with the input data.
:rtype: str
'''
return self._filename
return self._name
@property
def basename(self):
'''
Returns the basename of the file associated with the input data.
def shortname(self):
:return: the basename of the file associated with the input data.
:rtype: str
'''
return self._basename
return self._name
@property
def data(self):
'''
......
......@@ -39,17 +39,49 @@ class InputFileData(IInputData):
type = None
def __init__(self, filename, *args, **kwargs):
def __init__(self, filename, load=True):
IInputData.__init__(self,filename)
self._basename = os.path.basename(filename)
self._dirname = os.path.dirname(filename)
if load:
self.load()
@property
def filename(self):
'''
Returns the filename associated with the input data.
super(InputFileData, self).__init__()
:return: the filename associated with the input data.
:rtype: str
'''
self._filename = filename
self._dirname = os.path.dirname(self._filename)
self._basename = os.path.basename(self._filename)
self._data = None
self.load()
return self._name
@property
def shortname(self):
'''
Returns the shortname of the file associated with the input data.
:return: the shortname of the file associated with the input data.
:rtype: str
'''
return self._basename
@property
def basename(self):
'''
Returns the basename of the file associated with the input data.
:return: the basename of the file associated with the input data.
:rtype: str
'''
return self._basename
@property
def dirname(self):
return self._dirname
......
......@@ -45,10 +45,10 @@ class MMTKTrajectoryInputData(InputFileData):
def load(self):
try:
traj = MMTKTrajectory(None, self._filename, "r")
traj = MMTKTrajectory(None, self._name, "r")
except IOError:
raise InputDataError("The MMTK trajectory %r could not be loaded property." % self._filename)
raise InputDataError("The MMTK trajectory %r could not be loaded property." % self._name)
self._data = traj
......@@ -60,7 +60,7 @@ class MMTKTrajectoryInputData(InputFileData):
val = []
val.append("Path:")
val.append("%s\n" % self._filename)
val.append("%s\n" % self._name)
val.append("Number of steps:")
val.append("%s\n" % len(self._data))
val.append("Universe:")
......
......@@ -46,10 +46,10 @@ class NetCDFInputData(InputFileData):
def load(self):
try:
self._netcdf = NetCDFFile(self._filename,"r")
self._netcdf = NetCDFFile(self._name,"r")
except IOError:
raise InputDataError("The data stored in %r filename could not be loaded property." % self._filename)
raise InputDataError("The data stored in %r filename could not be loaded property." % self._name)
else:
self._data = collections.OrderedDict()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment