Skip to content

Commit

Permalink
rename 'file_name' to 'name' in special files; new attr 'file_name' i…
Browse files Browse the repository at this point in the history
…n general case
  • Loading branch information
MuellerSeb committed Aug 22, 2019
1 parent dd7d809 commit 632c2e7
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 581 deletions.
82 changes: 41 additions & 41 deletions ogs5py/fileclasses/asc/core.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# -*- coding: utf-8 -*-
"""
Class for the ogs ASC file.
"""

from __future__ import absolute_import, division, print_function
from ogs5py.fileclasses.base import LineFile


class ASC(LineFile):
"""
Class for the ogs ASC file.
Parameters
----------
lines : list of str, optional
content of the file as a list of lines
Default: None
file_name : str, optional
name of the file without extension
Default: "textfile"
task_root : str, optional
Path to the destiny folder.
Default: cwd+"ogs5model"
task_id : str, optional
Name for the ogs task. (a place holder)
Default: "model"
Notes
-----
This is just handled as a line-wise file. You can access the data by line
with:
ASC.lines
This file type comes either from .tim .pcs or .gem
"""

def __init__(self, **OGS_Config):
super(ASC, self).__init__(**OGS_Config)
self.file_ext = ".asc"
# -*- coding: utf-8 -*-
"""
Class for the ogs ASC file.
"""

from __future__ import absolute_import, division, print_function
from ogs5py.fileclasses.base import LineFile


class ASC(LineFile):
"""
Class for the ogs ASC file.
Parameters
----------
lines : list of str, optional
content of the file as a list of lines
Default: None
name : str, optional
name of the file without extension
Default: "textfile"
task_root : str, optional
Path to the destiny folder.
Default: cwd+"ogs5model"
task_id : str, optional
Name for the ogs task. (a place holder)
Default: "model"
Notes
-----
This is just handled as a line-wise file. You can access the data by line
with:
ASC.lines
This file type comes either from .tim .pcs or .gem
"""

def __init__(self, **OGS_Config):
super(ASC, self).__init__(**OGS_Config)
self.file_ext = ".asc"
40 changes: 25 additions & 15 deletions ogs5py/fileclasses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class File(object):
"""

def __init__(self, task_root=None, task_id="model", file_ext=".std"):
self._name = None
self.name_from_id = True
if task_root is None:
task_root = os.path.join(CWD, "ogs5model")
self.task_root = task_root
Expand All @@ -85,14 +87,30 @@ def get_file_type(self):
"""Get the OGS file class name."""
return self._get_clsname()

@property
def name(self):
""":class:`str`: name of the file without extension."""
if self.name_from_id:
return self.task_id
return self._name

@name.setter
def name(self, value=None):
if value is None:
self.name_from_id = True
self._name = None
else:
self._name = str(value)
self.name_from_id = False

@property
def file_path(self):
""":class:`str`: save path of the file."""
return os.path.join(self.task_root, self.task_id + self.file_ext)
return os.path.join(self.task_root, self.name + self.file_ext)

@property
def name(self):
""":class:`str`: base name of the file."""
def file_name(self):
""":class:`str`: base name of the file with extension."""
return os.path.basename(self.file_path)

@property
Expand Down Expand Up @@ -229,7 +247,7 @@ class LineFile(File):
lines : list of str, optional
content of the file as a list of lines
Default: None
file_name : str, optional
name : str, optional
name of the file without extension
Default: "textfile"
file_ext : str, optional
Expand All @@ -246,22 +264,14 @@ class LineFile(File):
def __init__(
self,
lines=None,
file_name="textfile",
name=None,
file_ext=".txt",
task_root=None,
task_id="model",
):
super(LineFile, self).__init__(task_root, task_id, file_ext)
if lines is not None:
self.lines = lines
else:
self.lines = []
self.file_name = file_name

@property
def file_path(self):
""":class:`str`: save path of the file."""
return os.path.join(self.task_root, self.file_name + self.file_ext)
self.lines = [] if lines is None else lines
self.name = name

@property
def is_empty(self):
Expand Down
Loading

0 comments on commit 632c2e7

Please sign in to comment.