# Standard modules
import logging
+import os
import re
import shutil
import sys
import termios
from collections import namedtuple
from io import UnsupportedOperation
+from pathlib import Path
# Third party modules
from fb_tools.cfg_app import FbConfigApplication
from .. import DEFAULT_CONFIG_DIR
from .. import DEFAULT_TERMINAL_HEIGHT, DEFAULT_TERMINAL_WIDTH
from .. import __version__ as GLOBAL_VERSION
+from ..errors import DpxFileError
from ..xlate import DOMAIN, LOCALE_DIR, XLATOR
from ..xlate import __base_dir__ as __xlate_base_dir__
from ..xlate import __lib_dir__ as __xlate_lib_dir__
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.9.3'
+__version__ = '0.10.0'
# =============================================================================
print('.', end='', flush=True)
self.cur_dots += 1
+ # -------------------------------------------------------------------------
+ def check_output_file(self, ofile, must_exists=False, must_absolute=False):
+ """Check all nessacary thinks about an output file, before it can be used."""
+ if ofile is None:
+ msg = _('The output file to chack must not be None.')
+ raise TypeError(msg)
+
+ ofile = Path(ofile)
+ if must_absolute:
+ msg = _('The path {!r} must be an absolute path.').format(ofile)
+ raise DpxFileError(msg)
+
+ if ofile.exists():
+
+ if not ofile.is_file():
+ msg = _('The given path {!r} exists, but is not a regular file.').format(
+ str(ofile))
+ raise DpxFileError(msg)
+
+ if not os.access(str(ofile), os.R_OK):
+ msg = _('The given file {!r} is not readable.').format(str(ofile))
+ raise DpxFileError(msg)
+
+ if not os.access(str(ofile), os.W_OK):
+ msg = _('The given file {!r} is not writeable.').format(str(ofile))
+ raise DpxFileError(msg)
+
+ return
+
+ parent_dir = ofile.parent
+ if not parent_dir.exists():
+ msg = _('Directory {!r} does not exists.').format(str(parent_dir))
+ raise DpxFileError(msg)
+
+ if not parent_dir.is_dir():
+ msg = _('Path {!r} exists, bu is not a directory.').format(str(parent_dir))
+ raise DpxFileError(msg)
+
+ if not os.access(str(parent_dir), os.W_OK):
+ msg = _('The directory {!r} is not writeable.').format(str(parent_dir))
+ raise DpxFileError(msg)
+
# =============================================================================