Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chang permission modes of HOMEDIR STMP PTMP as writable at setup time #3426

Conversation

mingshichen-noaa
Copy link
Contributor

Description

When setting up an experiment, in particular at setup_xml.py/setup_expt.py time, a check should be added to verify that the user running the experiment is able to write to those directories. This will save debugging time if a user forgets/doesn't know to change these directories.
Refs #3318

Type of change

  • New feature (adds functionality)

Change characteristics

  • Is this a breaking change (a change in existing functionality)? NO
  • Does this change require a documentation update? NO

How has this been tested?

  • Clone and build on RDHPCS
  • Cycled tests on Hercules
  • Forecast-only tests on Hercules

Checklist

  • Any dependent changes have been merged and published
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass with my changes
  • I have made corresponding changes to the documentation if necessary

@DavidHuber-NOAA
Copy link
Contributor

DavidHuber-NOAA commented Mar 7, 2025

@mingshichen-noaa A few things about this PR/issue #3318:

  1. setup_expt.py sets the defaults for STMP, PTMP, and HOMEDIR, but these can be overridden by the user before running setup_xml.py. So we don't want to check if they can be written to during the setup_expt.py step, but instead the setup_xml.py step.
  2. All three of these directories may or may not exist at the time setup_xml.py is called. So determining if they can be written to is a little tricky. What I would suggest is something like (I am guessing at function names here)
def check_dir_writable(dir)
    if os.path.is_dir(dir):
        if os.access(directory_path, os.W_OK):
            return True
        else:
            return False
    elif os.path.is_file(dir):
         # raise exception
    else:  # Find the nearest parent directory that already exists
        test_parent = os.path.dirname(dir)
        while test_parent:
            if os.path.exists(test_parent):
                # Call check_dir_writable on the parent
                return check_dir_writable(test_parent)
            test_parent = os.path.dirname(test_parent)
       # If we exited the loop, then something went wrong with my logic
       # raise exception 'Could not find a parent directory of {dir}'

If this returns True, then the directory is writable, otherwise, it's not and you can raise an exception notifying the user.
3. Lastly, STMP, PTMP, and HOMEDIR should be read from config.base, not the host file.

I'd suggest closing this PR and reworking the issue on the setup_xml side of things.

@mingshichen-noaa
Copy link
Contributor Author

@DavidHuber-NOAA
Thank you for your comments. I will close the PR.

@mingshichen-noaa mingshichen-noaa deleted the feature/check_some_dirs_writable branch March 7, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants