Package gromacs :: Module utilities :: Class FileUtils
[hide private]
[frames] | no frames]

Class FileUtils

source code

object --+
         |
        FileUtils
Known Subclasses:

Mixin class to provide additional file-related capabilities.
Instance Methods [hide private]
 
_init_filename(self, filename=None, ext=None)
Initialize the current filename :attr:`FileUtils.real_filename` of the object.
source code
 
filename(self, filename=None, ext=None, set_default=False, use_my_ext=False)
Supply a file name for the class object.
source code
 
check_file_exists(self, filename, resolve='exception', force=None)
If a file exists then continue with the action specified in ``resolve``.
source code
 
infix_filename(self, name, default, infix, ext=None)
Unless name is provided, insert infix before the extension ext of default.
source code
 
__repr__(self)
repr(x)
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  default_extension = None
Default extension for files read/written by this class.
Instance Variables [hide private]
  real_filename
Current full path of the object for reading and writing I/O.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_init_filename(self, filename=None, ext=None)

source code 
Initialize the current filename :attr:`FileUtils.real_filename` of the object.

Bit of a hack.

- The first invocation must have ``filename != None``; this will set a
  default filename with suffix :attr:`FileUtils.default_extension`
  unless another one was supplied.

- Subsequent invocations either change the filename accordingly or
  ensure that the default filename is set with the proper suffix.

filename(self, filename=None, ext=None, set_default=False, use_my_ext=False)

source code 

Supply a file name for the class object.

Typical uses:

fn = filename()             ---> <default_filename>
fn = filename('name.ext')   ---> 'name'
fn = filename(ext='pickle') ---> <default_filename>'.pickle'
fn = filename('name.inp','pdf') --> 'name.pdf'
fn = filename('foo.pdf',ext='png',use_my_ext=True) --> 'foo.pdf'

The returned filename is stripped of the extension (use_my_ext=False) and if provided, another extension is appended. Chooses a default if no filename is given.

Raises a ValueError exception if no default file name is known.

If set_default=True then the default filename is also set.

use_my_ext=True lets the suffix of a provided filename take priority over a default ext tension.

check_file_exists(self, filename, resolve='exception', force=None)

source code 
If a file exists then continue with the action specified in ``resolve``.

``resolve`` must be one of

"ignore"
      always return ``False``
"indicate"
      return ``True`` if it exists
"warn"
      indicate and issue a :exc:`UserWarning`
"exception"
      raise :exc:`IOError` if it exists

Alternatively, set *force* for the following behaviour (which
ignores *resolve*):

``True``
      same as *resolve* = "ignore" (will allow overwriting of files)
``False``
      same as *resolve* = "exception" (will prevent overwriting of files)
``None``
      ignored, do whatever *resolve* says

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)