Skip to content

Commit

Permalink
Add support for HPSS (#22)
Browse files Browse the repository at this point in the history
Adds classes to interface with the hsi and htar commands with several helper methods for easier use. Resolves #2.
  • Loading branch information
DavidHuber-NOAA authored Apr 9, 2024
1 parent 81bfec0 commit 63db259
Show file tree
Hide file tree
Showing 9 changed files with 908 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ API
timetools
jinja
logger
hsi
htar


4 changes: 4 additions & 0 deletions docs/hsi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. currentmodule:: wxflow

.. autoclass:: Hsi
:members:
4 changes: 4 additions & 0 deletions docs/htar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. currentmodule:: wxflow

.. autoclass:: Htar
:members:
4 changes: 3 additions & 1 deletion src/wxflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from .executable import CommandNotFoundError, Executable, ProcessError, which
from .factory import Factory
from .file_utils import FileHandler
from .fsutils import chdir, cp, mkdir, mkdir_p, rm_p, rmdir
from .fsutils import chdir, chgrp, cp, get_gid, mkdir, mkdir_p, rm_p, rmdir
from .hsi import Hsi
from .htar import Htar
from .jinja import Jinja
from .logger import Logger, logit
from .sqlitedb import SQLiteDB, SQLiteDBError
Expand Down
22 changes: 21 additions & 1 deletion src/wxflow/fsutils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import contextlib
import errno
import grp
import os
import shutil

__all__ = ['mkdir', 'mkdir_p', 'rmdir', 'chdir', 'rm_p', 'cp']
__all__ = ['mkdir', 'mkdir_p', 'rmdir', 'chdir', 'rm_p', 'cp',
'get_gid', 'chgrp']


def mkdir_p(path):
Expand Down Expand Up @@ -85,3 +87,21 @@ def cp(source: str, target: str) -> None:
raise OSError(f"unable to copy {source} to {target}")
except Exception as exc:
raise Exception(exc)


# Group ID number for a given group name
def get_gid(group_name: str):
try:
group_id = grp.getgrnam(group_name).gr_gid
except KeyError:
raise KeyError(f"{group_name} is not a valid group name.")

return group_id


# Change the group of a target file or directory
def chgrp(group_name, target, recursive=False):
# TODO add recursive option
gid = get_gid(group_name)
uid = os.stat(target).st_uid
os.chown(target, uid, gid)
Loading

0 comments on commit 63db259

Please sign in to comment.