environment Module

class pipelet.environment.Environment(w)[source]

Bases: pipelet.environment.EnvironmentBase

Default segment’s facilities.

The default environment contains some basic utilities related to filenames, parameters and subprocesses. It can be extended to complete the default environment with new utilities.

clean_tmp()[source]

Delete the list of tmp file created by a segment

expose(lst_tag)[source]

Set list of parameter to expose from the web interface.

get_data_fn(x, seg=None)[source]

Complete the filename with the path to the working directory.

>>> get_data_fn ("test.png")
./test/first_test/first_S3CRKVY/data/test.png
get_input(seg=None)[source]

Return the input coming from segment seg.

If no segment specified, take the first. This utility replaces the seg_input variable which type could vary as described below.

>>> get_input(seg='third')
the_brave
get_parent()[source]

Return list of parent names

>>> get_parent()
['second', 'third'] 
get_tmp_fn()[source]

Obtain a temporary filename

Note : has to be part of the segment execution environment The temporary file is added to the intern list for future removal.

>>> get_tmp_fn()
./test/first_test/third_QA7CX5A/fourth_LGJSKVQ/735200
glob_parent(y, segs=None)[source]

Globbing limited to the fatherhood. For unlimited globbing see glob_seg.

>>> glob_parent ('test*.txt')
['./test/first_test/first_S3CRKVY/second_WDSDP3Q/data/7_Robin/test.txt']
glob_seg(x, y)[source]

Return the list of filename matching y in the working directory of segment x.

Usage of glob_seg should be limited: + potentially breaks the dependancy scheme + may hurt performances as all task directories of the segment x will be searched

>>> glob_seg ('second', 'test*.txt')
['./test/first_test/first_S3CRKVY/second_WDSDP3Q/data/8_Arthur/test.txt', './test/first_test/first_S3CRKVY/second_WDSDP3Q/data/7_Robin/test.txt']
hook(hook_name, glo)[source]

Execute hook code.

Search for an extra segment code file, and update dictionnary with the result of its execution.

load_param(seg, glo, param_name='*')[source]

Update the global dictionnary with parameters of a segment.

>>> load_param('second', globals(), ["fn"])
>>> print fn
test.txt
load_products(filename, glo, param_name='*')[source]

Update a namespace by unpickling requested object from the file.

>>> load_products(get_data_fn("test.pkl", seg="second"), globals(),['i'])
>>> print i
0
logged_subprocess(args, shell=False, except_on_failure=True, name=None)[source]

Execute a subprocess and log its output.

Create files process_name.log and process_name.err. If shell is set to True, the command is run via a shell. If except_on_failure set to True, raise an exception when command execution return non zero

>>> (o,e)=logged_subprocess (["echo", "$TMP"])
>>> open(o).readlines()
['$BASH']
save_param(lst_par)[source]

Set list of parameter to save on disk

save_products(filename, glo, param_name='*')[source]

Use pickle to save a part of a given namespace.

>>> save_products(get_data_fn("test.pkl"), globals(),['i'])
>>> open(get_data_fn("test.pkl")).readlines()
['(dp1'\n, "S'i'\n", 'I0\n', 's.']
set_output(lst_o)[source]

Set the segment output as a list.

If o is not a list, set a list of one element o.

Table Of Contents

This Page