From d54f962f7b781b4169bf0bf40f622abc50de9e19 Mon Sep 17 00:00:00 2001 From: mehtank <mehtank> Date: Wed, 28 Apr 2021 22:20:56 -0700 Subject: [PATCH] Command line interface for creating / testing components in rocolib using python -m rocolib --- rocolib/__init__.py | 2 +- rocolib/__main__.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 rocolib/__main__.py diff --git a/rocolib/__init__.py b/rocolib/__init__.py index f0d5c0a..a54d298 100644 --- a/rocolib/__init__.py +++ b/rocolib/__init__.py @@ -9,7 +9,7 @@ from os.path import realpath from os.path import relpath -__version__ = "0.2.0" +__version__ = "0.2.1" __author__ = 'UCLA LEMUR' __credits__ = 'The Laboratory for Embedded Machines and Ubiquitous Robots' diff --git a/rocolib/__main__.py b/rocolib/__main__.py new file mode 100644 index 0000000..16d782d --- /dev/null +++ b/rocolib/__main__.py @@ -0,0 +1,48 @@ +#!/bin/env python + +import logging +import argparse +from rocolib.library import getComponent +from rocolib.api.composables.graph.Joint import FingerJoint + + +def test(component, params, thickness, display=False, display3D=False): + f = getComponent(component) + if params is not None: + for p in params: + f.setParameter(p[0], eval(p[1])) + if thickness is None: + t = 0 + j = None + else: + t = thickness + j = FingerJoint(thickness=t) + + f.makeOutput("output/" + component, display=display, display3D=display3D, thickness=t, joint=j) + + +if __name__ == '__main__': + LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] + DEFAULT_LOG_LEVEL = "WARNING" + + parser = argparse.ArgumentParser() + parser.add_argument("component", help="Name of the component you'd like to test") + parser.add_argument("--verbose", "-v", dest="log_level", action="append_const", const=-1) + parser.add_argument("--quiet", "-q", dest="log_level", action="append_const", const=1) + parser.add_argument("-t", type=float, help="Thickness if you are making with wood") + parser.add_argument("-d", action='store_true', help="Display 2D drawing") + parser.add_argument("-D", action='store_true', help="Display 3D drawing") + parser.add_argument("-P", nargs=2, action='append', + metavar=("NAME", "VALUE"), + help="Set component parameter NAME to value VALUE") + args = parser.parse_args() + + log_level = LOG_LEVELS.index(DEFAULT_LOG_LEVEL) + # For each "-q" and "-v" flag, adjust the logging verbosity accordingly + # making sure to clamp off the value from 0 to 4, inclusive of both + for adjustment in args.log_level or (): + log_level = min(len(LOG_LEVELS) - 1, max(log_level + adjustment, 0)) + log_level_name = LOG_LEVELS[log_level] + logging.basicConfig(level=getattr(logging, log_level_name)) + + test(args.component, args.P, thickness=args.t, display=args.d, display3D=args.D) -- GitLab