dataprocessor package

Submodules

dataprocessor.argparsers module

dataprocessor.argparsers.dataprocessor()[source]
dataprocessor.argparsers.dpgenzshcomp()[source]
dataprocessor.argparsers.dpmanip()[source]
dataprocessor.argparsers.register_figure()[source]

dataprocessor.dataframe module

dataprocessor.dataframe.get_project(node_list, project_path, properties=['comment', 'tags'], index='path')[source]

Get project in dataframe format.

If there are two or more project of specified name, the latter one is selected.

Parameters:

project_path : str

the path of project

properties : list of str (optional)

properties successed from node_list into project dataframe “name” and “path” are successed always (Default=[“comment”, “tags”])

index : str or list of str (optional)

index of project dataframe if it is None, the index of DataFrame(node_list) will be successed (Default=”path”)

Returns:

project : pandas.DataFrame

dataprocessor.dataframe.get_projects(node_list)[source]

Get projects in dataframe format.

Returns:projects_dataframe : pandas.DataFrame

dataprocessor.exception module

exception dataprocessor.exception.DataProcessorError(msg)[source]

Bases: exceptions.Exception

A runtime error occurred in DataProcessor

This exception is raised when invalid manipulation is done. This exception will be caught in dataprocessor.execute, and converted into InvalidJSONError.

Attributes

msg (str) A message for the error
exception dataprocessor.exception.InvalidJSONError(name, msg)[source]

Bases: exceptions.Exception

A runtime error occurred in processing manipulation

Attributes

name (str) The name of pipe in which error occurred.
msg (str) A message for the error
dataprocessor.exception.pipe_execute(*args, **kwds)[source]

dataprocessor.execute module

dataprocessor.execute.check_manip(manip)[source]

check whether maniplation is valid

Parameters:

manip : list

A list defining manipulation

Raises:

InvalidJSONError

It is raised if manipulation is invalid.

Examples

>>> def do_check_manip(manip):
...     try:
...         check_manip(manip)
...     except InvalidJSONError as e:
...         print("[%s] %s" % (e.name, e.msg))
>>> do_check_manip([{"nae": "save_json", # typo: "nae"
...                  "args": ["out.json"],
...                  "kwds": {"silent" : "True"}}])
[] pipe name is not defined
>>> do_check_manip([{"name": "save_json",
...                  "arg": ["out.json"], # typo: "arg"
...                  "kwds": {"silent" : "True"}}])
[save_json] attributes of pipes must be in 'name', 'args', 'kwds'
>>> do_check_manip([{"name": "save_json",
...                  "args": ["out.json"],
...                  "kwd": {"silent" : "True"}}]) # typo: "kwd"
[save_json] attributes of pipes must be in 'name', 'args', 'kwds'
>>> do_check_manip([{"name": "sav_json", # typo: "sav_json"
...                  "args": ["out.json"],
...                  "kwds": {"silent" : "True"}}])
[sav_json] invalid pipe name
>>> do_check_manip([{"name": "save_json",
...                  "args": [], # argument mismatch
...                  "kwds": {"silent" : "True"}}])
[save_json] the number of arguments mismatches
>>> do_check_manip([{"name": "load_json",
...                  "args": ["in.json"],
...                  "kwds": {"silent": "True"}}])
...                  # `load_json` does not have "kwds"
[load_json] pipe does not have 'kwds'
>>> do_check_manip([{"name": "save_json",
...                  "args": ["out.json"],
...                  "kwds": {"silnt" : "True"}}])
...                  # typo in keywords: "silnt"
[save_json] keyword argument 'silnt' does not exist
dataprocessor.execute.execute(manip, node_list=[])[source]

execute pipeline defined in manip

This function does not check whether manip is valid. Please check by .check_manip

Parameters:

manip : list

A list defining manipulation

node_list : list, optional

initial node_list (default=[])

Returns:

node_list : list

dataprocessor.execute.execute_from_json_str(manip_json_str, node_list=[])[source]

execute pipeline from JSON string

This do check_manip and execute.

Returns:

node_list : list

Raises:

InvalidJSONError

It is raised if manipulation is invalid. See also .check_manip

dataprocessor.execute.pipe(name, args, kwds={}, node_list=[])[source]

Execute a pipe

Parameters:

name : str

Name of pipe

args : list

arguments of pipe

kwds : dict, optional

keyword arguments of pipe (default={})

node_list : list, optional

initial node_list (default=[])

dataprocessor.figure module

Handling node for figures.

exception dataprocessor.figure.DataProcessorFigureError(msg)[source]

Bases: dataprocessor.exception.DataProcessorError

Exception about figure.

dataprocessor.figure.calc_hash(figure_path)[source]

Return a SHA-1 hash of the figure.

dataprocessor.figure.destination_path(figure_path, figure_directory)[source]

Return the path of a directory where the figure will be copied.

This is also an ID of the figure in DataProcessor.

Parameters:

figure_path : str

The present path of figure

figure_directory : str

The path to figure_directory

dataprocessor.figure.new_node(figure_path, generators, figure_directory, parents, children=[])[source]

Copy figure and incidentals and return corresponding node.

Parameters:

figure_path : str

the present path of the figure

generators : list

the paths of files which should be managed with the figure s.t. gunplot file, python script, etc...

figure_directory : str

the base directory where figures are saved

parents : list

will be copied into node[“parents”]

children : list, optional

will be copied into node[“children”]

Raises:

DataProcessorFigureError

raised when the figure is empty

dataprocessor.figure.register(node_list, figures, figure_directory, runs=[], generators=[])[source]

Register figure into node_list.

Parameters:

node_list : list

node_list

figures : list

the present paths of figures

figure_directory : str

the base directory where figures are saved

runs : list

The paths of runs related to these figures. They will be saved into node[“parents”]

generators : list

the paths of files which should be managed with the figure; s.t. gunplot file, python script, etc...

dataprocessor.figure.zero_hash()[source]

Return a SHA-1 hash of empty figure.

dataprocessor.filter module

dataprocessor.filter.node_type(node_list, ntype)[source]

Filter by node_type.

Parameters:

ntype : str

nodes whose type is ntype are left in node_list.

Returns:

node_list

Raises:

DataProcessorError

If specified ntype is not supported.

dataprocessor.filter.prefix_path(node_list, pre_path)[source]

Filter by prefix path.

In the case when pre_path is “/foo/bar”, following paths remain (not filtered):

  • /foo/bar
  • /foo/bar/foo

, and following do not remain (filtered out):

  • /foo/barfoo/hoge
  • /bar/foo/bar/FOO
Parameters:

pre_path : str

prefix path for filtering.

Returns:

node_list

dataprocessor.filter.project(node_list, path)[source]

Filter by project path.

Parameters:

path : str or [str]

the path of project (or projects), whose children are left.

Returns:

node_list

Raises:

DataProcessorError

If path is not specified by str or [str].

dataprocessor.gencompletion module

class dataprocessor.gencompletion.CompletionGenerator(commandname, parser)[source]

Bases: object

Generator of Zsh Completion Function.

Since this class uses some inner function of argparse, this does not work well in some version of argparse. This is tested only on argparse of python 2.7.5.

Attributes

command_name (str) command name of completion
parser (argparse.ArgumentParser) parser of command

Methods

get() returns string of Zsh completion function
get()[source]

Get zsh completion function string.

dataprocessor.io module

class dataprocessor.io.DataHandler(filename, silent=False)[source]

Bases: object

A data handler.

A utility class for save/load data into/from JSON file. See the following example. This class use JSON format for serializing.

Examples

>>> with DataHandler(filename, silent=True) as dh:  
...     dh.add({"path" : "/path/to/data1", "name" : "data1",
...             "parents": [], "children": []})

Attributes

node_list (list) the managed node_list

Methods

get() returns managed node_list
add(node, skip_validate_link) add node into managed node_list
replace(node_list, skip_validate_link) swap managed node_list and node_list in the argument
serialize() serialize node_list into file. If you use with statement, you need not to call this.
add(node, strategy='update', skip_validate_link=False)[source]

Add node into managed node_list.

Parameters:

skip_validate_link : bool, optional

skip link check (default=False)

get()[source]
load()[source]
replace(node_list, skip_validate_link=True)[source]

Swap node_list.

Parameters:

skip_validate_link : bool, optional

skip link validation about all nodes in new node_list

serialize()[source]
update(node_list, skip_validate_link=False)[source]

Update node_list (use nodes.modest_update).

Parameters:

skip_validate_link : bool, optional

skip link validation about all nodes in new node_list

class dataprocessor.io.SyncDataHandler(filename, silent=False, lock_dir='/tmp', prefix='SyncDH', duration=0.1)[source]

Bases: dataprocessor.io.DataHandler

A synced data handler.

This lock reading/writing JSON file.

Methods

add(node[, strategy, skip_validate_link]) Add node into managed node_list.
get()
load()
replace(node_list[, skip_validate_link]) Swap node_list.
serialize()
update(node_list[, skip_validate_link]) Update node_list (use nodes.modest_update).
dataprocessor.io.load(node_list, json_path)[source]

Load node_list from a JSON file.

Parameters:

json_path : str

the path to JSON

Returns:

list

node_list(arg1) + [new node list]

Raises:

DataProcessorError

occurs when JSON file does not exist.

dataprocessor.io.save(node_list, json_path, silent=False)[source]

Save node_list into a JSON file.

Parameters:

json_path : str

the path to JSON

slient : bool, str, optional

Ask whether replace JSON file (default=False)

Returns:

list : node_list

dataprocessor.ipynb module

dataprocessor.ipynb.gather_notebooks()[source]

Gather processes of IPython Notebook

Raises:

DataProcessorError

  • No IPython Notebook found
dataprocessor.ipynb.resolve_name(ipynb_path)[source]
dataprocessor.ipynb.resolve_url(ipynb_path, notebooks=None)[source]

Return valid URL for .ipynb

Parameters:

ipynb_path : str

path of existing .ipynb file

Raises:

DataProcessorError

  • Existing notebook servers do not start on the parent directory of .ipynb file.

dataprocessor.nodes module

Tools for manipulation of node_list.

exception dataprocessor.nodes.DataProcessorNodesError(msg)[source]

Bases: dataprocessor.exception.DataProcessorError

Exception about Nodes processings.

dataprocessor.nodes.add(node_list, node, skip_validate_link=False, strategy='raise')[source]

Add a node into node_list.

This adds a node into node_list, and validate links in node[“children”] and node[“parents”]. In detail of validate link, see validate_link.

Parameters:

node_list : list

the list of nodes

node : dict

The node will be added into node_list

skip_validate_link : bool, optional

skip link validation (default False)

strategy : str, optional {“raise”, “update”, “modest_update”, “replace”}

The strategy for the case where there exists a node whose “path” is same as new one

  • “raise” : raise DataProcessorNodesError (default)
  • “update” : use dict.update to update existing node
  • “modest_update” : use nodes.modest_update to update existing node
  • “replace” : replace existing node with new node
Raises:

DataProcessorNodesError:

there is already exist node whose path is node[“path”]

DataProcessorError:

strategy is invalid string

Examples

>>> node_list = [{"path": "/some/path", "children": [], "parents": []}]
>>> added_node = {"path": "/added/path", "children": ["/some/path"],
...               "parents": []}
>>> add(node_list, added_node)

If skip_validate_link=True, snode_list[0][“parents”] is not filled.

dataprocessor.nodes.change_path(node_list, from_path, to_path, silent=False)[source]

Change node path.

Parameters:

from_path : str

The path of node.

to_path : str

The destination path of node.

silent : bool or { ‘False’, ‘True’ }, optional

Does not ask whether delete nonexist-path in parents or children. (default=’False’)

Returns:

node_list

Raises:

DataProcessorError

If node ‘to_path’ is already registered or node with ‘from_path’ is not registered.

dataprocessor.nodes.check_duplicate(node_list)[source]

Check if duplicated nodes exist.

only check their paths

Parameters:

node_list : list

the list of nodes (not modified)

Returns:

list of str

return the list of duplicated nodes’ paths

Examples

>>> node_list = [
...     {"path": "/path/0", "parents": ["/path/1"],
...      "children": ["/path/2", "/path/3"]},
...     {"path": "/path/1", "parents": [],
...      "children": ["/path/0"]},
...     {"path": "/path/2", "parents": ["/path/0"],
...      "children": []},
...     {"path": "/path/2", "parents": ["/path/0"],
...      "children": []},  # duplicated
...     {"path": "/path/3", "parents": ["/path/0"],
...      "children": [], "attr1": "value1"},
...     {"path": "/path/3", "parents": ["/path/0"],
...      "children": [], "attr1": "value2"}  # duplicated
... ]
>>> check_duplicate(node_list)
['/path/2', '/path/3']
dataprocessor.nodes.get(node_list, path)[source]

Search node from node_list by its path.

Returns:

node or None

the node is returned if exists, and None is returned if not.

Examples

>>> node_list = [{"path": "/path/1"}, {"path": "/path/2"},
...              {"path": "/path/3"}, {"path": "/path/4"}]
>>> get(node_list, "/path/3")
{'path': '/path/3'}
>>> node = get(node_list, "/path/5") # no node exists
>>> print(node)
None
dataprocessor.nodes.merge_duplicate(node_list)[source]

Merge duplicate node.

If duplicated nodes are found, they will be merged. The latter node has priority in merging (see Examples)

Parameters:

node_list : list

the list of nodes

Returns:

node_list : list

Examples

>>> node_list = [
...     {"path": "/path/1", "attr1": "value1"},
...     {"path": "/path/1", "attr1": "value2"},
... ]
>>> merge_duplicate(node_list)
[{'path': '/path/1', 'attr1': 'value2'}]
dataprocessor.nodes.modest_update(node_list, node, skip_validate_link=False)[source]

Update node properties modestly

This keeps values as possible, besides the “update” strategy of add(...) simply uses dict.update(). If node in the arguments has empty value e.g. node = {“path”: “/path/0”, “comment” : “”}, this function does not overwrite existing comment of the node in node_list.

Parameters:

node_list : list

the list of nodes

node : dict

The node will be added into node_list

skip_validate_link : bool, optional

skip link validation (default False)

Raises:

DataProcessorNodesError

there is no node whose “path” is node[“path”]

Examples

>>> node_list = [{
...   "path": "/path/0",
...   "comment": "some comment",
...   "children": [],
...   "parents": [],
... }]
>>> node = {
...   "path":"/path/0",
...   "configure": {"A": 1.0},
...   "comment": "",
... }
>>> modest_update(node_list, node)
>>> node_list == [{
...   'comment': 'some comment',
...   'path': '/path/0',
...   'parents': [],
...   'children': [],
...   'configure': {'A': 1.0}
... }]
True
dataprocessor.nodes.normalize(node)[source]

Normalize node (i.e. fill necessary field).

Parameters:

node: dict

node that you want to normalize

Returns:

dict

normalized node

Examples

>>> node = {
...     "path": "/path/0",
...     "type": "run",
...     "unknown": ["homhom"]
... }
>>> node = normalize(node)
>>> node == {
...     "path": "/path/0",
...     "type": "run",
...     "name": "",
...     "configure": {},
...     "comment": "",
...     "parents": [],
...     "children": [],
...     "unknown": ["homhom"]
... }
True
dataprocessor.nodes.remove(node_list, path, skip_validate_link=False)[source]

Remove node from node_list.

In detail of validate link, see validate_link.

Parameters:

node_list : list

the list of nodes

path : str

The path of the node to be removed

skip_validate_link : bool, optional

skip link validation (default False)

Raises:

DataProcessorError

occurs when specified path does not exist in node_list

Examples

>>> node_list = [{"path": "/remove/path", "children": [],
...               "parents": ["/some/path"]},
...              {"path": "/some/path", "children": ["/remove/path"],
...               "parents": []}]
>>> remove(node_list, "/remove/path")

If skip_validate_link=True, node_list[1][“chilrdren”] is not removed.

Validate the link of the node.

Check node[“children”] and node[“parents”] is correct. If a link is incomplete, it will fixed (see the following example).

Parameters:

node_list : list

the list of nodes

node : dict

a node will be checked. This must belong to the node_list

Examples

Fill node_list[0]’s parents and node_list[1]’s children

>>> node_list = [
...     {"path": "/path/0", "parents": [], "children": []},
...     {"path": "/path/1", "parents": [], "children": []},
...     {"path": "/path/2", "parents": ["/path/1"],
...      "children": ["/path/0"]}]
>>> validate_link(node_list, node_list[2])
>>> node_list == [
...     {"path": "/path/0", "parents": ["/path/2"], "children": []},
...     {"path": "/path/1", "parents": [], "children": ["/path/2"]},
...     {"path": "/path/2", "parents": ["/path/1"],
...      "children": ["/path/0"]}]
True

Remove node_list[1]’s children.

>>> node_list = [
...     {"path": "/path/0", "parents": [], "children": ["/path/1"]},
...     {"path": "/path/1", "parents": ["/path/0"],
...      "children": ["/not/exist"]}]
>>> validate_link(node_list, node_list[1], silent=True)
>>> node_list == [
...     {"path": "/path/0", "parents": [], "children": ["/path/1"]},
...     {"path": "/path/1", "parents": ["/path/0"], "children": []}]
True

dataprocessor.pipe module

This module provides wrapper functions which make easy to define a SIMD-like pipe, i.e. operates independently on each nodes.

The following two codes are equal without error handling:

>>> @wrap
... def pipe1(node, arg1, kwd1=""):
...     print(node)
...     node["attr1"] = "val"
...     return node
>>> def pipe1(node_list, arg1, kwd1=""):
...     for node in node_list:
...         print(node)
...         node["attr1"] = "val"
...     return node_list

Error handling policy is following:

  • If DataProcessorError or its inherited is raised in the decorated function while processing a node, this process is quited and continue with other nodes.
  • If another exception is raised, whole processes are quited.

Simply, corresponds to the following conceptual code:

>>> for node in node_list:  
...     try:
...         decorated(node)
...     except DataProcessorError:
...         continue
exception dataprocessor.pipe.PipeImplementationError(name, msg)[source]

Bases: exceptions.Exception

Raised when the implementation of pipe is invalid

Attributes

name (str) The name of pipe in which error occurred.
msg (str) A message for the error
dataprocessor.pipe.directory(func)

Create a pipe which operates on directory nodes

dataprocessor.pipe.file(func)

Create a pipe which operates on file nodes

dataprocessor.pipe.type(typename)[source]

Create a pipe which operates on nodes of specific type.

Examples

>>> nl = [{
...     "path": "/path/1",
...     "type": "project",
...     "children": ["/path/2"],
...     "parents": [],
... }, {
...     "path": "/path/2",
...     "type": "run",
...     "children": [],
...     "parents": ["/path/1"],
... }]
>>> @type("run")
... def run_pipe(node):
...     node["comment"] = "RUN"
...     return node
>>> @type("project")
... def project_pipe(node):
...     node["comment"] = "PROJECT"
...     return node
>>> nl = run_pipe(nl)
>>> nl = project_pipe(nl)
>>> nl == [{
...     "path": "/path/1",
...     "type": "project",
...     "children": ["/path/2"],
...     "parents": [],
...     "comment": "PROJECT",
... }, {
...     "path": "/path/2",
...     "type": "run",
...     "children": [],
...     "parents": ["/path/1"],
...     "comment": "RUN",
... }]
True

works on project nodes only.

dataprocessor.pipe.wrap(func)

Create a pipe from a function operates on a node.

This decorator makes easy to define a SIMD-like pipe, i.e. operates independently on each nodes.

Examples

The following two codes are equal without error handling:

>>> @wrap
... def pipe1(node, arg1, kwd1=""):
...     print(node)
...     node["attr1"] = "val"
...     return node
>>> def pipe1(node_list, arg1, kwd1=""):
...     for node in node_list:
...         print(node)
...         node["attr1"] = "val"
...     return node_list

dataprocessor.rc module

Configure manager of dataprocessor

dataprocessor.rc.ArgumentParser(rcpath='~/.dataprocessor.ini', options={})[source]

Argument parser for executables in this project.

Parameters:

rcpath : str, optional

path of configure file (default=~/.dataprocessor.ini)

options : [{str: dict}], optional

options which you want to read from [data] section of the configure file. [{“opt1”: argparse_opt}] will converted into parser.add_argument(“–” + “opt1”, **argparse_opt).

Returns:

argparse.ArgumentParser

Raises:

DataProcessorRcError

raised when

  • configure file does not exist.
  • configure file does not contain specified values
exception dataprocessor.rc.DataProcessorRcError(msg)[source]

Bases: dataprocessor.exception.DataProcessorError

Exception about configure file.

dataprocessor.rc.get_configparser(rcpath='~/.dataprocessor.ini')[source]

Get configure parser

Parameters:

rcpath : str, optional

path of configure file (default=~/.dataprocessor.ini)

Returns:

ConfigParser.SafeConfigParser

configure file has been loaded.

Raises:

DataProcessorRcError

raised when configure file does not exist.

dataprocessor.rc.get_configure(section, key, rcpath='~/.dataprocessor.ini')[source]

Get configure value

Parameters:

section : str

section name of configure file

key : str

key of configure

Returns:

str

configure value

Raises:

DataProcessorRcError

raised when

  • configure file does not exist.
  • configure file does not contain specified values
dataprocessor.rc.get_configure_safe(section, key, default, rcpath='~/.dataprocessor.ini')[source]

Get configure value safely.

Parameters:

section : str

section name of configure file

key : str

key of configure

default : any

This is returned in the case where configure cannot be obtained.

Returns:

str

configure value

dataprocessor.rc.load(rcpath='~/.dataprocessor.ini')[source]

Load node_list from default data.json.

Parameters:

rcpath : str, optional

path of configure file (default=~/.dataprocessor.ini)

Returns:

node_list

Raises:

DataProcessorRcError

raised when

  • configure file does not exist.
  • configure file does not contain JSON path
dataprocessor.rc.load_into_argparse(parser, section_name, options, allow_empty=False, rcpath='~/.dataprocessor.ini')[source]

Load configure into argparse.

Parameters:

parser : argparse.ArgumentParser

main parser or subparser

section_name : str

name of section

options : {str: {str: str}}

Options which you want to read from section whose name is section_name. [{“opt1”: argparse_opt}] will converted into parser.add_argument(“–” + “opt1”, **argparse_opt).

dataprocessor.rc.resolve_project_path(name_or_path, create_dir, root=None, basket_name='Projects', rcpath='~/.dataprocessor.ini')[source]

Resolve project path from its path or name.

Parameters:

name_or_path : str

Project identifier. If name (i.e. basename(name_or_path) == name_or_path), abspath of root/basket_name/name is returned. If path (otherwise case), returns its abspath.

create_dir : boolean

This flag determine the behavior occured when there is no directory at the resolved path as follows: - if create_dir is True: create new directory - if create_dir is False: raise DataProcessorError

root : str, optional

The root path of baskets. (default=None) If None, the path is read from the configure file.

basket_name : str, optional

The name of the project basket. If “project_basket” is specified in the configure file, default value is it. Otherwise, default is “Projects”.

rcpath : str, optional

path of the setting file

Returns:

path : str

existing project path

Raises:

DataProcessorRcError

occurs when root is not specified and it cannot be loaded from the setting file.

DataProcessorError

occurs when create_dir is False and a path is not resolved.

dataprocessor.rc.update(node_list, rcpath='~/.dataprocessor.ini')[source]

Save node_list into default data.json with update strategy.

Parameters:

rcpath : str, optional

path of configure file (default=~/.dataprocessor.ini)

Raises:

DataProcessorRcError

raised when

  • configure file does not exist.
  • configure file does not contain JSON path

dataprocessor.table module

Create a part of HTML of table.

class dataprocessor.table.Table(path, node_list, table_type='children', groups=[{'items': None, 'dict_path': ['configure'], 'name': None}])[source]

Bases: object

Create table widget.

Create table from dictionary in node. If node has dictionary in its values, also search dictionary recursively. (e.g. node[key1][key2]...[keyn])

Parameters:

table_type : {‘children’, ‘parents’}, optional

Table is composed of nodes in node[table_type].

groups : list of dic, optional

Specify elements in table for each group. Default is one group which get all of ‘configure’ key. One group has three keys below at most.

  • dict_path : list of str, optional

    List of key. Default is node itself. Search dictionary recursively by dict_path.

  • items : list of str, optional

    List of key in dictionary specified by dict_path. Table has only items in items.

  • name : str, optional

    Group name. Default is “/”.join(dict_path).

Raises:

DataProcessorError

Occurs in three cases:

  • No path exist.
  • Node to the path has no table_type key.
  • fail to search dictionary recursively: dict_path is invalid.

Examples

If you have following list and you call as follows,

>>> nodelist = [{'path': '/tmp', 'children': ['/tmp/run1', '/tmp/run0']},
...             {'path': '/tmp/run0', 'name': 'run0', 'comment': u'testあ',
...              'configure': {'nx':1, 'ny':2}},
...             {'path': '/tmp/run1', 'name': 'run1',
...              'configure': {'nx': 10, 'ny': 20}}]
>>> tble = Table('/tmp', nodelist,
...              groups=[{'dict_path': ['configure']},
...                      {'items': ['comment', 'path'], 'name': 'node'}])
>>> html_str = tble.render()

you can get html string of following formatted table.

  configure node
nx ny comment path
run0 1 2 testあ /tmp/run0
run1 10 20   /tmp/run1

Another example.

>>> node_list = [{"path": "/path/to",
...               "children": ["/path/to/1", "/path/to/2"]},
...              {"path": "/path/to/1", "name": "n1", "val1": 1,
...               "hoge1": {"hoge2": {"hoge3": {"val4": 4}}}},
...              {"path": "/path/to/2", "name": "h1", "val2": 2,
...               "hoge1": {"hoge2": {"hoge3": {"val3": 4}}}}]
>>> tbl = Table("/path/to", node_list,
...             groups=[{"items": ["val1", "val2"], "name": "some name"},
...                     {"dict_path": ["hoge1", "hoge2", "hoge3"]}])
>>> html_str = tbl.render()
  some name hoge1/hoge2/hoge3
val1 val2 val3 val4
h1 n 2 4  
n1 1     4

Methods

render() Get a piece of html for table.
render()[source]

Get a piece of html for table.

Returns:

str

A piece of html composed of the parameters in constructor.

dataprocessor.utility module

Utility of dataprocessor.

Some useful tools for dataprocessor are included.

dataprocessor.utility.boolenize(arg)[source]

Make arg boolen value.

Parameters:arg : bool, str, int, float
Returns:bool

Examples

>>> boolenize(True)
True
>>> boolenize(False)
False
>>> boolenize(1)
True
>>> boolenize(0)
False
>>> boolenize(0.0)
False
>>> boolenize("True")
True
>>> boolenize("other words")
True
>>> boolenize("False")
False
>>> boolenize("falSE")
False
>>> boolenize("false")
False
>>> boolenize("F")
False
>>> boolenize("f")
False
>>> boolenize("No")
False
>>> boolenize("NO")
False
>>> boolenize("no")
False
>>> boolenize("N")
False
>>> boolenize("n")
False
dataprocessor.utility.check_directory(path)[source]

Check whether directory exists.

Returns:

str

Absolute path of the argument

Raises:

DataProcessorError

occurs when the file does not exist or the file is not directory.

dataprocessor.utility.check_file(path)[source]

Check whether file exists.

Returns:

str

Absolute path of the argument

Raises:

DataProcessorError

occurs in two cases:

  • when the file does not exist
  • file exist but it is a directory
dataprocessor.utility.copy_file(from_path, to_path, strategy='interactive')[source]

Copy a file.

If to_path already exist, check whether it is same file. When there are same file, skip. When there are different, replace the file or change file name.

Moreover, when destination directory does not exist, create the direcotry.

Parameters:

from_path : str

to_path : str

strategy : str, optional, {“interactive”, “replace”, “skip”, “error”}

This specify the action when to_path already exists.
  • “interactive” : ask on the prompt.
  • “replace” : to_path file will be replaced.
  • “skip” : do nothing.
  • “error” : raise DataProcessorError.
Raises:

DataProcessorError

Occur in two cases
  • Invalid strategy keyword is specified.
  • to_path already exists and the strategy is “error”.
dataprocessor.utility.get_directory(path, silent=True)[source]

Get absolute path of the directory.

If it does not exist, it will be created.

Parameters:

silent : bool, optional

does not ask whether create directory (default=True)

Returns:

str

Absolute path of the directory

Raises:

DataProcessorError

occurs in two cases

  • another file (does not directory) exist
  • refused by user to create directory
dataprocessor.utility.path_expand(path)[source]

Get absolute path.

Returns:

str

Absolute path of the argument

Raises:

DataProcessorError

path is not readable

dataprocessor.utility.read_configure(filename, split_char='=', comment_char=['#'])[source]

Read configure file without sections.

Parameters:

filename : str

The file name of the configure file

split_char : str, optional

The lines in configure file are splited by this char (default “=”). If your configure has line s.t. a : 1.2, then you should set split_char=”:”.

comment_char : list of str, optional

The line starting with chars in this list will be skipped. (default=[“#”])

Returns:

dict

{parameter-name: value} dictionary.

Module contents

dataprocessor