lexor.command package — lexor 0.1.2c0 documentation

# lexor.command package

## Submodules

## lexor.command.config module

Config

This module is in charge of providing all the necessary settings to the rest of the modules in lexor.

class `lexor.command.config.` `ConfigDispAction`(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

  Bases: `argparse.Action`

  Derived argparse Action class to use when displaying the configuration file and location.

`lexor.command.config.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.config.` `get_cfg`(names, defaults=None)

  Obtain settings from the configuration file.

`lexor.command.config.` `read_config`()

  Read a configuration file.

`lexor.command.config.` `run`()

  Run command.

`lexor.command.config.` `set_style_cfg`(obj, name, defaults)

  Given an obj, this can be a Parser, Converter or Writer. It sets the attribute defaults to the specified defaults in the configuration file or by the user by overwriting values in the parameter defaults.

`lexor.command.config.` `update_single`(cfg, name, defaults=None)

  Helper function for get_cfg.

`lexor.command.config.` `value_completer`(**_)

  value completer.

`lexor.command.config.` `var_completer`(**_)

  var completer.

`lexor.command.config.` `write_config`(cfg_file)

  Write the configuration file.

## lexor.command.defaults module

Defaults

Print the default values for each command.

`lexor.command.defaults.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.defaults.` `name_completer`(**_)

  var completer.

`lexor.command.defaults.` `run`()

  Run command.

## lexor.command.develop module

Develop

Routine to append a path to the develop section in the configuration file.

`lexor.command.develop.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.develop.` `run`()

  Append the path to the develop section in the configuration file.

## lexor.command.dist module

Distribute

Package a style along with auxiliary and test files.

`lexor.command.dist.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.dist.` `run`()

  Run the command.

`lexor.command.dist.` `style_completer`(parsed_args, **_)

  Return a list of valid files to edit.

## lexor.command.document module

Document

Routine to create an xml file with the documentation of a lexor style.

`lexor.command.document.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.document.` `append_main`(doc, mod)

  Append the main module. Return a dictionary containing all the modules used in the style.

`lexor.command.document.` `check_filename`(arg)

  Check if the inputfile exists.

`lexor.command.document.` `full_class_name`(cls)

  Obtain the full class name.

`lexor.command.document.` `get_class_node`(cls)

  Return a class node. Assumes that cls is a valid class.

`lexor.command.document.` `get_defaults_node`(obj)

  Obtain defaults node.

`lexor.command.document.` `get_function_node`(func)

  Return a function node.

`lexor.command.document.` `get_info_node`(info)

  Generate the info node.

`lexor.command.document.` `get_mapping_node`(mapping)

  Generate the mapping node.

`lexor.command.document.` `get_member_node`(member)

  Return a property node.

`lexor.command.document.` `get_property_node`(prop)

  Return a property node.

`lexor.command.document.` `make_module_node`(mod, name=None)

  Create a module node documenation.

`lexor.command.document.` `run`()

  Run the command.

`lexor.command.document.` `separate_objects`(mod, remove=None)

  Given a module, it separates the objects into a dictionary.

`lexor.command.document.` `xml_style`(lang_str)

  Parses a style string.

## lexor.command.edit module

Edit

Module to open files with an editor.

`lexor.command.edit.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.edit.` `run`()

  Run the edit command.

`lexor.command.edit.` `valid_files`(parsed_args, **_)

  Return a list of valid files to edit.

## lexor.command.install module

Install

Routine to install a parser/writer/converter style.

`lexor.command.install.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.install.` `download_file`(url, base='.')

  Download a file.

`lexor.command.install.` `install_style`(style, install_dir)

  Install a given style to the install_dir path.

`lexor.command.install.` `run`()

  Run the command.

`lexor.command.install.` `unzip_file`(local_name)

  Extract the contents of a zip file.

## lexor.command.lang module

Language

This module provides functions to load the different languages parsers, writers and converters.

## Constants

LEXOR_PATH: The paths where lexor looks for the parsing, writing and converting styles.

`lexor.command.lang.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.lang.` `get_style_module`(type_, lang, style, to_lang=None)

  Return a parsing/writing/converting module.

`lexor.command.lang.` `load_aux`(info)

  Wrapper around load_mod for easy use when developing styles. The only parameter is the dictionary INFO that needs to exist with every style. INFO is returned by the init function in the lexor module.

`lexor.command.lang.` `load_mod`(modbase, dirpath)

  Return a dictionary containing the modules located in dirpath. The name modbase must be provided so that each module may have a unique identifying name. The result will be a dictionary of modules. Each of the modules will have the name “modbase_modname” where modname is a module in the directory.

`lexor.command.lang.` `load_rel`(path, module)

  Load relative to a path. If path is the name of a file the filename will be dropped.

`lexor.command.lang.` `map_explanations`(mod, exp)

  Helper function to create a map of msg codes to explanations in the lexor language modules.

`lexor.command.lang.` `run`()

  Run the command.

## lexor.command.paste module

Paste

Routine to append paste templates.

`lexor.command.paste.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.paste.` `lang_completer`(**_)

  Return the meta var.

`lexor.command.paste.` `make_auxilary`(base, type_, fmt, aux_type='')

  Creates a new node parser module.

`lexor.command.paste.` `make_style`(base, type_, fmt)

  Creates a new style file.

`lexor.command.paste.` `run`()

  Run the command.

`lexor.command.paste.` `style_completer`(**_)

  Return the meta var.

## lexor.command.test module

Lexor Test

This module contains various test for lexor.

`lexor.command.test.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.test.` `compare_with`(str_obj, expected)

  Calls nose.eq_ to compare the strings and prints a custom message.

`lexor.command.test.` `find_failed`(tests, lang, style)

  Run the tests and return a list of the tests that fail.

`lexor.command.test.` `nose_msg_explanations`(lang, type_, style, name)

  Gather the MSG_EXPLANATION list and run the tests it contains.

`lexor.command.test.` `parse_convert_write`(callerfile, in_, out_, style, tolang)

  Provide the filename as the input and the style you wish to compare it against.

`lexor.command.test.` `parse_msg`(msg)

  Obtain the tests embedded inside the messages declared in a style. The format of the messages is as follows:

  > <tab>[A-Z][0-9]*: <msg>

  or

  > <tab>([A-Z][0-9]*|Okay): <tab><tab>msg ... <tab><tab>msg continues <tab>([A-Z][0-9]*|Okay): msg

  Where <tab> consists of 4 whitespaces. This function returns the message without the tests and a list of tuples of the form (code, msg) along with the message

`lexor.command.test.` `parse_write`(callerfile, in_, out_, style, lang)

  Provide the filename as the input and the style you wish to compare it against.

`lexor.command.test.` `print_log`(node)

  Display the error obtained from parsing.

`lexor.command.test.` `run`()

  Run command.

`lexor.command.test.` `run_develop`(param, cfg, verbose)

  Run develop tests.

`lexor.command.test.` `run_installed`(param, cfg, verbose)

  Run installed tests.

## lexor.command.to module

to

Execute lexor by transforming a file “to” another language.

`lexor.command.to.` `add_parser`(subp, fclass)

  Add a parser to the main subparser.

`lexor.command.to.` `convert_and_write`(f_name, parser, in_lang, log, arg)

  Auxiliary function to reduce the number of branches in run.

`lexor.command.to.` `get_input`(input_file, cfg, default='_')

  Returns the text to be parsed along with the name assigned to that text. The last output is the extension of the file.

`lexor.command.to.` `input_language`(tolang)

  Parses the tolang argument.

`lexor.command.to.` `language_style`(lang_str)

  Parses a language string. In particular, the options –from and –log.

`lexor.command.to.` `parse_styles`(lang_str)

  Parses a language string. In particular, the options –from and –log.

`lexor.command.to.` `run`()

  Run the command.

`lexor.command.to.` `run_converter`(param)

  Auxiliary function for convert and write.

`lexor.command.to.` `run_writer`(param)

  Auxiliary function for convert and write.

`lexor.command.to.` `split_at`(delimiter, text, opens='[<(', closes=']>)', quotes='"\'')

  Custom function to split at commas. Taken from stackoverflow http://stackoverflow.com/a/20599372/788553

`lexor.command.to.` `style_parameters`(style)

  Parsers a style name along with its parameters.

`lexor.command.to.` `write_document`(writer, doc, fname, arg)

  Auxiliary function for convert_and_write.

`lexor.command.to.` `write_log`(writer, log, quiet)

  Write the log file to stderr.

## Module contents

Command

Collection of functions to create lexor’s command line utility.

`lexor.command.` `date`(short=False)

  Return the current date as a string.

`lexor.command.` `error`(msg)

  Print a message to the standard error stream and exit.

`lexor.command.` `exec_cmd`(cmd, verbose=False)

  Run a subprocess and return its output and errors.

`lexor.command.` `import_mod`(name)

  Return a module by string.

`lexor.command.` `warn`(msg)

  Print a message to the standard error