IOManager

class systemtools.IOManager

Manages Abjad IO.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_systemtools { graph [label=systemtools]; "abjad.tools.systemtools.IOManager.IOManager" [color=black, fontcolor=white, group=2, label=<<B>IOManager</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.systemtools.IOManager.IOManager"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

clear_terminal() Clears terminal.
count_function_calls(expr[, global_context, ...]) Counts function calls required to execute expr.
find_executable(name[, flags]) Finds executable name.
get_last_output_file_name([extension, ...]) Gets last output file name in output_directory.
get_next_output_file_name([file_extension, ...]) Gets next output file name with file_extension in output_directory.
make_subprocess(command) Makes Popen instance.
open_file(file_path[, application, line_number]) Opens file_path.
open_last_log() Opens LilyPond log file in operating system-specific text editor.
open_last_ly([target]) Opens last LilyPond output file produced by Abjad.
open_last_pdf([target]) Opens last PDF generated by Abjad.
profile(expr[, sort_by, line_count, ...]) Profiles expr.
run_lilypond(ly_path[, flags, lilypond_path]) Runs LilyPond on ly_path.
save_last_ly_as(file_path) Saves last LilyPond file created by Abjad as file_path.
save_last_pdf_as(file_path) Saves last PDF created by Abjad as file_path.
spawn_subprocess(command) Spawns subprocess and runs command.
__eq__(argument) Is true when ID of argument equals ID of Abjad object.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad object.
__ne__(argument) Is true when Abjad object does not equal argument.
__repr__() Gets interpreter representation of Abjad object.

Class & static methods

static IOManager.clear_terminal()

Clears terminal.

Runs clear if OS is POSIX-compliant (UNIX / Linux / MacOS).

Runs cls if OS is not POSIX-compliant (Windows).

Returns none.

static IOManager.count_function_calls(expr, global_context=None, local_context=None, fixed_point=True)

Counts function calls required to execute expr.

Wraps IOManager.profile(expr).

Returns nonnegative integer.

static IOManager.find_executable(name, flags=1)

Finds executable name.

Similar to Unix which command.

>>> systemtools.IOManager.find_executable('python2.7') 
['/usr/bin/python2.7']

Returns list of zero or more full paths to name.

static IOManager.get_last_output_file_name(extension=None, output_directory=None)

Gets last output file name in output_directory.

>>> systemtools.IOManager.get_last_output_file_name() 
'6222.ly'

Gets last output file name in Abjad output directory when output_directory is none.

Returns none when output directory contains no output files.

Returns string or none.

static IOManager.get_next_output_file_name(file_extension='ly', output_directory=None)

Gets next output file name with file_extension in output_directory.

>>> systemtools.IOManager.get_next_output_file_name() 
'6223.ly'

Gets next output file name with file_extension in Abjad output directory when output_directory is none.

Returns string.

static IOManager.make_subprocess(command)

Makes Popen instance.

>>> command = 'echo "hellow world"'
>>> systemtools.IOManager.make_subprocess(command)
<subprocess.Popen object at 0x...>

Defined equal to

process = subprocess.Popen(
    command,
    shell=True,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
    )

Redirects stderr to stdout.

static IOManager.open_file(file_path, application=None, line_number=None)

Opens file_path.

Uses application when application is not none.

Uses Abjad configuration file text_editor when application is none.

Takes best guess at operating system-specific file opener when both application and Abjad configuration file text_editor are none.

Respects line_number when file_path can be opened with text editor.

Returns none.

static IOManager.open_last_log()

Opens LilyPond log file in operating system-specific text editor.

Returns none.

static IOManager.open_last_ly(target=-1)

Opens last LilyPond output file produced by Abjad.

Uses operating-specific text editor.

Set target=-2 to open the next-to-last LilyPond output file produced by Abjad, and so on.

Returns none.

static IOManager.open_last_pdf(target=-1)

Opens last PDF generated by Abjad.

Abjad writes PDFs to the ~/.abjad/output directory by default.

You may change this by setting the abjad_output_directory variable in the config.py file.

Set target=-2 to open the next-to-last PDF generated by Abjad.

Returns none.

static IOManager.profile(expr, sort_by='cumulative', line_count=12, strip_dirs=True, print_callers=False, print_callees=False, global_context=None, local_context=None, print_to_terminal=True)

Profiles expr.

>>> expr = 'Staff("c8 c8 c8 c8 c8 c8 c8 c8")'
>>> systemtools.IOManager.profile(
...     expr,
...     global_context=globals(),
...     ) 
Tue Apr  5 20:32:40 2011    _tmp_abj_profile

        2852 function calls (2829 primitive calls) in 0.006 CPU seconds

Ordered by: cumulative time
List reduced from 118 to 12 due to restriction <12>

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.006    0.006 <string>:1(<module>)
        1    0.001    0.001    0.003    0.003 make_notes.py:12(make_not
        1    0.000    0.000    0.003    0.003 Staff.py:21(__init__)
        1    0.000    0.000    0.003    0.003 Context.py:11(__init__)
        1    0.000    0.000    0.003    0.003 Container.py:23(__init__)
        1    0.000    0.000    0.003    0.003 Container.py:271(_initial
        2    0.000    0.000    0.002    0.001 all_are_logical_voice_con
    52    0.001    0.000    0.002    0.000 component_to_logical_voic
        1    0.000    0.000    0.002    0.002 _construct_unprolated_not
        8    0.000    0.000    0.002    0.000 make_tied_note.py:5(make_
        8    0.000    0.000    0.002    0.000 make_tied_leaf.py:5(make_

Wraps the built-in Python cProfile module.

Set expr to any string of Abjad input.

Set sort_by to ‘cumulative’, ‘time’ or ‘calls’.

Set line_count to any nonnegative integer.

Set strip_dirs to true to strip directory names from output lines.

See the Python docs for more information on the Python profilers.

Returns none when print_to_terminal is false.

Returns string when print_to_terminal is true.

static IOManager.run_lilypond(ly_path, flags=None, lilypond_path=None)

Runs LilyPond on ly_path.

Writes redirected output of Unix date to top line of LilyPond log file.

Then appends redirected output of LilyPond output to the LilyPond log file.

Returns none.

static IOManager.save_last_ly_as(file_path)

Saves last LilyPond file created by Abjad as file_path.

Returns none.

static IOManager.save_last_pdf_as(file_path)

Saves last PDF created by Abjad as file_path.

Returns none.

static IOManager.spawn_subprocess(command)

Spawns subprocess and runs command.

The function is basically a reimplementation of the deprecated os.system() using Python’s subprocess module.

Redirects stderr to stdout.

Returns integer exit code.

Special methods

(AbjadObject).__eq__(argument)

Is true when ID of argument equals ID of Abjad object. Otherwise false.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(AbjadObject).__hash__()

Hashes Abjad object.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(argument)

Is true when Abjad object does not equal argument. Otherwise false.

Returns true or false.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.