B @`#@sddlZddlZddlZddlmZddlmZmZddlm Z m Z dddZ edfddZ d d Z e e d e d d ddZdddZdS)N)Options)ProblemConfigFactory guess_format) add_subparserCustomHelpFormattercCsR|dkrtjdd}|jdddddd|jddd d dd|jd dd dd |S)Nz8%(prog)s [options] [])usagez--outputstorefilenamezjOutput file name. This option is required unless the file name is specified in a configuration file.)actiondesthelpdefaultz--formatformatz Output formatz--generate-config-templatetemplate)r r r )argparseArgumentParser add_argument)parserrC/tmp/pip-unpacked-wheel-bi3529v6/pyomo/scripting/plugins/convert.py create_parsers$rcCsddlm}m}|jjdkr:|jjr:|jjdd|j_t|jj}|jjdkr\|||S|dkr|jjdkrztdqtd|jjfn ||||SdS)Nr)convertconvert_dakota.Zdakotaz%Unspecified target conversion format!z+Unrecognized target conversion format (%s)!) Zpyomo.scripting.convertrrmodel save_format save_filesplitr RuntimeError)optionsrrr_formatrrr run_convert-s     r"c Csddl}|jdk rtdd\}}t|jd}|jdrV|tj| ddn|| | t d|jt dt|d d}|dkrt|d d}|dk rd |}|dkr^y|jj|d }Wn0tk rd}Yntk rd}YnX|dk r^y|d d}Wn YnX|dkr^yd t|d d}Wn YnX|dks|d|ks|d|krd|ksd|kst dt dtd\}}tddd} || | j|dgdt dtd\}}t} || | j|d} || t|d d|j_t|d d|j_| jdr\| j|j_| j|j _!n|jj| j}|"||jjj#t$t%|ddS)Nrr Twjson)indentz Created template file '%s'r rzunknown.rrz save filez save formatz-hz--helpz*ERROR: No output file or format specified!)outputgenerate)argsz.pyr)commandrr name)&Zpyomo.scripting.utilrrZ config_blockopenendswithwriter$dumpsvalueZgenerate_yaml_templatecloseprintsysexitgetattr scriptingutilZget_config_values IndexErrorIOErrorstrcreate_temporary_parserZinitialize_argparse parse_argsZimport_argparserrrmodel_or_config_filer data_filesdatafiles set_value run_commandr"convert_parser) r*ZunparsedZpyomoconfigblocksZOUTPUTZ save_filenamervalr_parser_optionsrrr convert_exec@sl                   rKrz'Convert a Pyomo model to another formatFzbThis pyomo subcommand is used to create a new model file in a specified format from a Pyomo model.)funcr add_help descriptioncCstjtd}|}|d}t|_|r<|jdddddd|rt|jddd d dd |jd dd ddd d|_d|_|jddd d dd |jd dd ddd |jdddddd|jdddgdd|S)N)formatter_classrz--generate-config-templaterrz>Create a configuration template file in YAML or JSON and exit.)r r r r z--outputr zjOutput file name. This option is required unless the file name is specified in a configuration file.)r r r r z--formatrz Output formatz8%(prog)s [options] []a Description: The 'pyomo convert' subcommand converts a Pyomo model into a specified format. The --output option is used to specify an output file. If only the --format option is specified, then the output filename is unknown.. The standard steps executed by this subcommand are: - Apply pre-solve operations (e.g. import Python packages) - Create the model - Apply model transformations This subcommand can be executed with or without a configuration file. For example: pyomo convert --output=model.lp model.py model.dat This creates the file 'model.lp' with format 'lp'. A yaml or json configuration file can also be used to specify conversion options. For example: pyomo convert config.yaml No other command-line options are required! A template configuration file can be generated with the '--generate-config-template' option: pyomo convert --generate-config-template=template.yaml pyomo convert --generate-config-template=template.json Note that yaml template files contain comments that describe the configuration options. Also, configuration files will generally support more configuration options than are available with command-line options. r??r'zA Python module that defines a Pyomo model, or a configuration file that defines options for 'pyomo convert' (in either YAML or JSON format))r nargsr r r@*zaPyomo data files that defined data used to initialize the model (specified in the first argument)) rrradd_subparsers add_parserrOrrepilog)r(r)r _subparsersrIrrrr=sX  'r=)N)FF)r$r5rZpyomo.common.collectionsrZ pyomo.optrrZpyomo.scripting.pyomo_parserrrrr"rKrEr=rrrr s  W