update formatting
This commit is contained in:
69
materials.py
69
materials.py
@@ -1,13 +1,26 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# -*- mode: python-mode; python-indent-offset: 2; tab-width: 2 -*-
|
"""\
|
||||||
|
Material database.
|
||||||
"""
|
"""
|
||||||
Created on Mon Dec 21 19:39:44 2015
|
__author__ = "Daniel Weschke"
|
||||||
|
__copyright__ = "Copyright 2019 Daniel Weschke"
|
||||||
|
__credits__ = ["Daniel Weschke"]
|
||||||
|
__license__ = "MIT"
|
||||||
|
__version__ = "2019.02.03"
|
||||||
|
__maintainer__ = "Daniel Weschke"
|
||||||
|
__email__ = "daniel.weschke@directbox.de"
|
||||||
|
__status__ = "Production" # "Prototype", "Development", "Production"
|
||||||
|
|
||||||
@author: Daniel
|
VERSION = """\
|
||||||
|
%(prog)s version {version} {copyright}
|
||||||
|
""".format(
|
||||||
|
version=__version__, copyright=__copyright__)
|
||||||
|
|
||||||
|
EPILOG = """\
|
||||||
"""
|
"""
|
||||||
import sys, os
|
|
||||||
import argparse
|
import os
|
||||||
|
|
||||||
|
|
||||||
def list():
|
def list():
|
||||||
@@ -22,7 +35,7 @@ def list():
|
|||||||
def read(input, search_keys=None):
|
def read(input, search_keys=None):
|
||||||
import json
|
import json
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
def find_values(id, json_repr):
|
def find_values(id, json_repr):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
@@ -44,7 +57,7 @@ def read(input, search_keys=None):
|
|||||||
for value in found_values:
|
for value in found_values:
|
||||||
#print('%-5s' % value[0] + ' ' + value[1])
|
#print('%-5s' % value[0] + ' ' + value[1])
|
||||||
print(search_key + ' = ' + '%s' % value[0] + ' ' + value[1])
|
print(search_key + ' = ' + '%s' % value[0] + ' ' + value[1])
|
||||||
|
|
||||||
#def getLength(element):
|
#def getLength(element):
|
||||||
# try:
|
# try:
|
||||||
# element.__iter__
|
# element.__iter__
|
||||||
@@ -53,7 +66,7 @@ def read(input, search_keys=None):
|
|||||||
# return 1
|
# return 1
|
||||||
#print(len(data))
|
#print(len(data))
|
||||||
#print(getLength(json.loads(data)))
|
#print(getLength(json.loads(data)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
data = json.load(data_file)
|
data = json.load(data_file)
|
||||||
pprint(data)
|
pprint(data)
|
||||||
@@ -65,41 +78,55 @@ def read(input, search_keys=None):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Material database.')
|
"""\
|
||||||
|
Main function
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description=__doc__, prefix_chars='-', epilog=EPILOG,
|
||||||
|
#usage="%(prog)s [OPTION]... NAME",
|
||||||
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
|
)
|
||||||
|
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose output")
|
||||||
|
parser.add_argument('-V', '--version', action='version', version=VERSION)
|
||||||
|
parser.add_argument('-D', '--debug', dest='debug', action='store_true', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(help='commands', dest='command')
|
subparsers = parser.add_subparsers(help='commands', dest='command')
|
||||||
|
|
||||||
# list materials
|
# list materials
|
||||||
list_parser = subparsers.add_parser('list',
|
parser_list = subparsers.add_parser('list',
|
||||||
description='List materials.',
|
description='List materials.',
|
||||||
help='list all available materials')
|
help='list all available materials')
|
||||||
|
|
||||||
# material
|
# material
|
||||||
material_parser = subparsers.add_parser('material',
|
parser_material = subparsers.add_parser('material',
|
||||||
help='the material to get information from')
|
help='the material to get information from')
|
||||||
material_parser.add_argument('materialname', action='store',
|
parser_material.add_argument('materialname', action='store',
|
||||||
help='list available material information')
|
help='list available material information')
|
||||||
material_parser.add_argument('-r', '--rho', dest='const_collection',
|
parser_material.add_argument('-r', '--rho', dest='const_collection',
|
||||||
action='append_const', const="rho",
|
action='append_const', const="rho",
|
||||||
help='get density from material')
|
help='get density from material')
|
||||||
material_parser.add_argument('-T', '--Tm', dest='const_collection',
|
parser_material.add_argument('-T', '--Tm', dest='const_collection',
|
||||||
action='append_const', const="Tm",
|
action='append_const', const="Tm",
|
||||||
help='get melting point temperature')
|
help='get melting point temperature')
|
||||||
|
|
||||||
parser.add_argument('-v', '--version', action='version',
|
|
||||||
version='%(prog)s 1.0')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args)
|
|
||||||
|
if args.debug:
|
||||||
|
print(args)
|
||||||
|
|
||||||
if args.command == 'list':
|
if args.command == 'list':
|
||||||
list()
|
list()
|
||||||
|
|
||||||
elif args.command == 'material':
|
elif args.command == 'material':
|
||||||
if args.const_collection:
|
if args.const_collection:
|
||||||
read(args.materialname, search_keys=args.const_collection)
|
read(args.materialname, search_keys=args.const_collection)
|
||||||
else:
|
else:
|
||||||
read(args.materialname)
|
read(args.materialname)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
import sys
|
||||||
|
sys.exit(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user