47 List of the available namelists (in the user directory and in the package)
48 :return: list of (name, location, readable) tuples, sorted by name; location is 'internal'
49 for a namelist of the package, the file name for a namelist of the user
50 directory and 'internal overridden by <file name>' for a namelist of the
51 package replaced by a namelist of the user directory; readable is False if the
52 namelist file cannot be read
54 names = sorted(set(os.path.basename(filename)[:-len(
'.namel')]
55 for namel_dir
in (
user_dir(
'namelists'), PACKAGE_NAMELIST_DIR)
56 for filename
in glob.glob(os.path.join(namel_dir,
'*.namel'))))
62 elif package_file
is None:
65 location =
'internal overridden by ' + user_file
70 except (ValueError, IndexError, KeyError, TypeError, OSError, StopIteration):
72 result.append((name, location, readable))
94 """Entry point of the phyex1d-namel_show command"""
95 parser = argparse.ArgumentParser(
96 description=textwrap.fill(
97 'Prints the content of a namelist (.namel file). The output can be used as a '
98 f
'starting point to define a new namelist in {user_dir("namelists")}.'),
99 epilog=
commands_help(), formatter_class=argparse.RawDescriptionHelpFormatter)
100 parser.add_argument(
'NAMELIST', help=
'namelist name (see phyex1d-namel_list)')
101 args = parser.parse_args()
104 sys.exit(f
'Error: namelist {args.NAMELIST} not found (see phyex1d-namel_list)')
105 with open(filename,
'r', encoding=
'UTF-8')
as f:
106 sys.stdout.write(f.read())