forked from rsmith-nl/lamprop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.py
More file actions
97 lines (89 loc) · 2.89 KB
/
console.py
File metadata and controls
97 lines (89 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# file: console.py
# vim:fileencoding=utf-8:ft=python
# lamprop - main program.
#
# Copyright © 2011-2021 R.F. Smith <rsmith@xs4all.nl>. All rights reserved.
# Created: 2011-03-26 14:54:24 +0100
# Last modified: 2021-01-02T23:42:39+0100
#
# SPDX-License-Identifier: BSD-2-Clause
import argparse
import logging
import sys
import lp
class LicenseAction(argparse.Action):
"""Action class to print the license."""
def __call__(self, parser, namespace, values, option_string=None):
print(lp.__license__)
sys.exit()
def main():
"""Entry point for lamprop console application."""
# Process the command-line arguments
doc = (
"Calculate the elastic properties of a fibrous composite laminate. "
"See the manual (lamprop-manual.pdf) for more in-depth information."
)
opts = argparse.ArgumentParser(prog="lamprop", description=doc)
group = opts.add_mutually_exclusive_group()
group.add_argument(
"-l",
"--latex",
action="store_true",
help="generate LaTeX output (the default is plain text)",
)
group.add_argument("-H", "--html", action="store_true", help="generate HTML output")
opts.add_argument(
"-e",
"--eng",
action="store_true",
help="output only the engineering properties",
)
opts.add_argument(
"-m",
"--mat",
action="store_true",
help="output only the ABD matrix and stiffness tensor",
)
opts.add_argument(
"-f", "--fea", action="store_true", help="output only material data for FEA"
)
group = opts.add_mutually_exclusive_group()
group.add_argument(
"-L", "--license", action=LicenseAction, nargs=0, help="print the license"
)
group.add_argument("-v", "--version", action="version", version=lp.__version__)
opts.add_argument(
"--log",
default="warning",
choices=["debug", "info", "warning", "error"],
help="logging level (defaults to 'warning')",
)
opts.add_argument(
"files", metavar="file", nargs="*", help="one or more files to process"
)
args = opts.parse_args(sys.argv[1:])
logging.basicConfig(
level=getattr(logging, args.log.upper(), None),
format="%(levelname)s: %(message)s",
)
del opts, group
if args.mat is False and args.eng is False and args.fea is False:
args.eng = True
args.mat = True
args.fea = True
# No files given to process.
if len(args.files) == 0:
sys.exit(1)
# Set the output method.
out = lp.text_output
if args.latex:
out = lp.latex_output
elif args.html:
out = lp.html_output
for f in args.files:
logging.info("processing file '{}'".format(f))
laminates = lp.parse(f)
for curlam in laminates:
print(*out(curlam, args.eng, args.mat, args.fea), sep="\n")
if __name__ == "__main__":
main()