nodes: 0, module; 1, function_definition; 2, function_name:currentdir; 3, parameters; 4, type; 5, block; 6, identifier:self; 7, identifier:str; 8, expression_statement; 9, if_statement; 10, return_statement; 11, comment:"""Name of the current working directory containing the relevant files.
  
          To show most of the functionality of |property|
          |FileManager.currentdir| (unpacking zip files on the fly is
          explained in the documentation on function
          (|FileManager.zip_currentdir|), we first prepare a |FileManager|
          object corresponding to the |FileManager.basepath|
          `projectname/basename`:
  
          >>> from hydpy.core.filetools import FileManager
          >>> filemanager = FileManager()
          >>> filemanager.BASEDIR = 'basename'
          >>> filemanager.projectdir = 'projectname'
          >>> import os
          >>> from hydpy import repr_, TestIO
          >>> TestIO.clear()
          >>> with TestIO():
          ...     os.makedirs('projectname/basename')
          ...     repr_(filemanager.basepath)    # doctest: +ELLIPSIS
          '...hydpy/tests/iotesting/projectname/basename'
  
          At first, the base directory is empty and asking for the
          current working directory results in the following error:
  
          >>> with TestIO():
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: \
  `.../projectname/basename` does not contain any available directories.
  
          If only one directory exists, it is considered as the current
          working directory automatically:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir1')
          ...     filemanager.currentdir
          'dir1'
  
          |property| |FileManager.currentdir| memorises the name of the
          current working directory, even if another directory is later
          added to the base path:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir2')
          ...     filemanager.currentdir
          'dir1'
  
          Set the value of |FileManager.currentdir| to |None| to let it
          forget the memorised directory.  After that, asking for the
          current working directory now results in another error, as
          it is not clear which directory to select:
  
          >>> with TestIO():
          ...     filemanager.currentdir = None
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: \
  `....../projectname/basename` does contain multiple available directories \
  (dir1 and dir2).
  
          Setting |FileManager.currentdir| manually solves the problem:
  
          >>> with TestIO():
          ...     filemanager.currentdir = 'dir1'
          ...     filemanager.currentdir
          'dir1'
  
          Remove the current working directory `dir1` with the `del` statement:
  
          >>> with TestIO():
          ...     del filemanager.currentdir
          ...     os.path.exists('projectname/basename/dir1')
          False
  
          |FileManager| subclasses can define a default directory name.
          When many directories exist and none is selected manually, the
          default directory is selected automatically.  The following
          example shows an error message due to multiple directories
          without any having the default name:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir1')
          ...     filemanager.DEFAULTDIR = 'dir3'
          ...     del filemanager.currentdir
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: The \
  default directory (dir3) is not among the available directories (dir1 and dir2).
  
          We can fix this by adding the required default directory manually:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir3')
          ...     filemanager.currentdir
          'dir3'
  
          Setting the |FileManager.currentdir| to `dir4` not only overwrites
          the default name, but also creates the required folder:
  
          >>> with TestIO():
          ...     filemanager.currentdir = 'dir4'
          ...     filemanager.currentdir
          'dir4'
          >>> with TestIO():
          ...     sorted(os.listdir('projectname/basename'))
          ['dir1', 'dir2', 'dir3', 'dir4']
  
          Failed attempts in removing directories result in error messages
          like the following one:
  
          >>> import shutil
          >>> from unittest.mock import patch
          >>> with patch.object(shutil, 'rmtree', side_effect=AttributeError):
          ...     with TestIO():
          ...         del filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          AttributeError: While trying to delete the current working directory \
  `.../projectname/basename/dir4` of the FileManager object, the following \
  error occurred: ...
  
          Then, the current working directory still exists and is remembered
          by |FileManager.currentdir|:
  
          >>> with TestIO():
          ...     filemanager.currentdir
          'dir4'
          >>> with TestIO():
          ...     sorted(os.listdir('projectname/basename'))
          ['dir1', 'dir2', 'dir3', 'dir4']
          """; 12, comparison_operator:self._currentdir is None; 13, block; 14, attribute; 15, attribute; 16, None; 17, expression_statement; 18, if_statement; 19, identifier:self; 20, identifier:_currentdir; 21, identifier:self; 22, identifier:_currentdir; 23, assignment; 24, comparison_operator:len(directories) == 1; 25, block; 26, elif_clause; 27, else_clause; 28, identifier:directories; 29, attribute; 30, call; 31, integer:1; 32, expression_statement; 33, comparison_operator:self.DEFAULTDIR in directories; 34, block; 35, block; 36, attribute; 37, identifier:folders; 38, identifier:len; 39, argument_list; 40, assignment; 41, attribute; 42, identifier:directories; 43, expression_statement; 44, expression_statement; 45, if_statement; 46, if_statement; 47, raise_statement; 48, identifier:self; 49, identifier:availabledirs; 50, identifier:directories; 51, attribute; 52, subscript; 53, identifier:self; 54, identifier:DEFAULTDIR; 55, assignment; 56, assignment; 57, not_operator; 58, block; 59, comparison_operator:self.DEFAULTDIR is None; 60, block; 61, call; 62, identifier:self; 63, identifier:currentdir; 64, identifier:directories; 65, integer:0; 66, attribute; 67, attribute; 68, identifier:prefix; 69, parenthesized_expression; 70, identifier:directories; 71, raise_statement; 72, attribute; 73, None; 74, raise_statement; 75, identifier:RuntimeError; 76, argument_list; 77, identifier:self; 78, identifier:currentdir; 79, identifier:self; 80, identifier:DEFAULTDIR; 81, concatenated_string; 82, call; 83, identifier:self; 84, identifier:DEFAULTDIR; 85, call; 86, concatenated_string; 87, string; 88, string; 89, string; 90, string; 91, identifier:RuntimeError; 92, argument_list; 93, identifier:RuntimeError; 94, argument_list; 95, string; 96, string; 97, string; 98, string_content:The current working directory of the; 99, interpolation; 100, string_content:object; 101, string_content:has not been defined manually and cannot; 102, string_content:be determined automatically:; 103, concatenated_string; 104, concatenated_string; 105, interpolation; 106, string_content:The default directory (; 107, interpolation; 108, string_content:); 109, string_content:is not among the available directories; 110, string_content:(; 111, interpolation; 112, string_content:).; 113, call; 114, string; 115, string; 116, string; 117, string; 118, string; 119, identifier:prefix; 120, attribute; 121, call; 122, attribute; 123, argument_list; 124, interpolation; 125, string_content:`; 126, interpolation; 127, string_content:`; 128, string_content:does not contain any available directories.; 129, interpolation; 130, string_content:`; 131, interpolation; 132, string_content:`; 133, string_content:does contain multiple available directories; 134, string_content:(; 135, interpolation; 136, string_content:).; 137, identifier:self; 138, identifier:DEFAULTDIR; 139, attribute; 140, argument_list; 141, identifier:objecttools; 142, identifier:classname; 143, identifier:self; 144, identifier:prefix; 145, call; 146, identifier:prefix; 147, call; 148, call; 149, identifier:objecttools; 150, identifier:enumeration; 151, identifier:directories; 152, attribute; 153, argument_list; 154, attribute; 155, argument_list; 156, attribute; 157, argument_list; 158, identifier:objecttools; 159, identifier:repr_; 160, attribute; 161, identifier:objecttools; 162, identifier:repr_; 163, attribute; 164, identifier:objecttools; 165, identifier:enumeration; 166, identifier:directories; 167, identifier:self; 168, identifier:basepath; 169, identifier:self; 170, identifier:basepath
code: def currentdir(self) -> str:
          """Name of the current working directory containing the relevant files.
  
          To show most of the functionality of |property|
          |FileManager.currentdir| (unpacking zip files on the fly is
          explained in the documentation on function
          (|FileManager.zip_currentdir|), we first prepare a |FileManager|
          object corresponding to the |FileManager.basepath|
          `projectname/basename`:
  
          >>> from hydpy.core.filetools import FileManager
          >>> filemanager = FileManager()
          >>> filemanager.BASEDIR = 'basename'
          >>> filemanager.projectdir = 'projectname'
          >>> import os
          >>> from hydpy import repr_, TestIO
          >>> TestIO.clear()
          >>> with TestIO():
          ...     os.makedirs('projectname/basename')
          ...     repr_(filemanager.basepath)    # doctest: +ELLIPSIS
          '...hydpy/tests/iotesting/projectname/basename'
  
          At first, the base directory is empty and asking for the
          current working directory results in the following error:
  
          >>> with TestIO():
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: \
  `.../projectname/basename` does not contain any available directories.
  
          If only one directory exists, it is considered as the current
          working directory automatically:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir1')
          ...     filemanager.currentdir
          'dir1'
  
          |property| |FileManager.currentdir| memorises the name of the
          current working directory, even if another directory is later
          added to the base path:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir2')
          ...     filemanager.currentdir
          'dir1'
  
          Set the value of |FileManager.currentdir| to |None| to let it
          forget the memorised directory.  After that, asking for the
          current working directory now results in another error, as
          it is not clear which directory to select:
  
          >>> with TestIO():
          ...     filemanager.currentdir = None
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: \
  `....../projectname/basename` does contain multiple available directories \
  (dir1 and dir2).
  
          Setting |FileManager.currentdir| manually solves the problem:
  
          >>> with TestIO():
          ...     filemanager.currentdir = 'dir1'
          ...     filemanager.currentdir
          'dir1'
  
          Remove the current working directory `dir1` with the `del` statement:
  
          >>> with TestIO():
          ...     del filemanager.currentdir
          ...     os.path.exists('projectname/basename/dir1')
          False
  
          |FileManager| subclasses can define a default directory name.
          When many directories exist and none is selected manually, the
          default directory is selected automatically.  The following
          example shows an error message due to multiple directories
          without any having the default name:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir1')
          ...     filemanager.DEFAULTDIR = 'dir3'
          ...     del filemanager.currentdir
          ...     filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          RuntimeError: The current working directory of the FileManager object \
  has not been defined manually and cannot be determined automatically: The \
  default directory (dir3) is not among the available directories (dir1 and dir2).
  
          We can fix this by adding the required default directory manually:
  
          >>> with TestIO():
          ...     os.mkdir('projectname/basename/dir3')
          ...     filemanager.currentdir
          'dir3'
  
          Setting the |FileManager.currentdir| to `dir4` not only overwrites
          the default name, but also creates the required folder:
  
          >>> with TestIO():
          ...     filemanager.currentdir = 'dir4'
          ...     filemanager.currentdir
          'dir4'
          >>> with TestIO():
          ...     sorted(os.listdir('projectname/basename'))
          ['dir1', 'dir2', 'dir3', 'dir4']
  
          Failed attempts in removing directories result in error messages
          like the following one:
  
          >>> import shutil
          >>> from unittest.mock import patch
          >>> with patch.object(shutil, 'rmtree', side_effect=AttributeError):
          ...     with TestIO():
          ...         del filemanager.currentdir   # doctest: +ELLIPSIS
          Traceback (most recent call last):
          ...
          AttributeError: While trying to delete the current working directory \
  `.../projectname/basename/dir4` of the FileManager object, the following \
  error occurred: ...
  
          Then, the current working directory still exists and is remembered
          by |FileManager.currentdir|:
  
          >>> with TestIO():
          ...     filemanager.currentdir
          'dir4'
          >>> with TestIO():
          ...     sorted(os.listdir('projectname/basename'))
          ['dir1', 'dir2', 'dir3', 'dir4']
          """
          if self._currentdir is None:
              directories = self.availabledirs.folders
              if len(directories) == 1:
                  self.currentdir = directories[0]
              elif self.DEFAULTDIR in directories:
                  self.currentdir = self.DEFAULTDIR
              else:
                  prefix = (f'The current working directory of the '
                            f'{objecttools.classname(self)} object '
                            f'has not been defined manually and cannot '
                            f'be determined automatically:')
                  if not directories:
                      raise RuntimeError(
                          f'{prefix} `{objecttools.repr_(self.basepath)}` '
                          f'does not contain any available directories.')
                  if self.DEFAULTDIR is None:
                      raise RuntimeError(
                          f'{prefix} `{objecttools.repr_(self.basepath)}` '
                          f'does contain multiple available directories '
                          f'({objecttools.enumeration(directories)}).')
                  raise RuntimeError(
                      f'{prefix} The default directory ({self.DEFAULTDIR}) '
                      f'is not among the available directories '
                      f'({objecttools.enumeration(directories)}).')
          return self._currentdir