-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorganise to have common stuff in a single place * add iterator to further remove code duplication * Add support for reading "."
- Loading branch information
1 parent
0bbfce6
commit 90ef07b
Showing
4 changed files
with
88 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
from argparse import ArgumentParser | ||
|
||
|
||
def parser(desc, ext="nc") -> ArgumentParser: | ||
parser = ArgumentParser(description=desc) | ||
parser.add_argument( | ||
"path", | ||
nargs="+", | ||
help=f"""Path of the directory to load. The netcdf file will be | ||
called dir.{ext} if the folder was called dir.""", | ||
) | ||
parser.add_argument("-q", "--quiet", action="store_true", help="Be less verbose") | ||
parser.add_argument( | ||
"-o", | ||
"--name", | ||
help=f"Specify the name for the output file. Defaults to `dir.{ext}` " | ||
f"when not given. Otherwise `name.{ext}` is used.", | ||
) | ||
return parser | ||
|
||
|
||
def iter_dir(args): | ||
if len(args.path) > 1 and args.name: | ||
raise RuntimeError( | ||
"""Providing an explicit output name and more than one folder to be read is | ||
currently not supported. Either use the default output name or read one file | ||
after another. Further you can use the python interface that gives more | ||
control.""" | ||
) | ||
for d in args.path: | ||
while d[-1] == "/": | ||
d = d[:-1] | ||
if args.name: | ||
yield d, args.name | ||
else: | ||
if os.path.isdir(d): | ||
if d == ".": | ||
yield d, os.getcwd() | ||
else: | ||
yield d, d | ||
else: | ||
yield d, d.rsplit(".", 1)[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters