sluyspy.system module

System functions for the sluyspy package.

sluyspy.system.homedir()[source]

Return my home directory as a string without trailing slash.

Returns:

My home directory as a string without trailing slash.

Return type:

(str)

sluyspy.system.host()[source]

Return the current host name.

Returns:

The current host name.

Return type:

(str)

sluyspy.system.on_zotac()[source]

Tell whether I am on a host called zotac.

Returns:

True when I am on a host called zotac, False otherwise.

Return type:

(bool)

sluyspy.system.string_in_file(infile, string)[source]

Use the grep command in a shell to quickly check whether a file contains a string.

Parameters:
  • infile (str) – Name of the file.

  • string (str) – Match string.

Note: fast small files (<~1Mb) and/or few calls (<~100kb).

sluyspy.system.string_in_file_grep(infile, string)[source]

Use the grep command in a shell to quickly check whether a file contains a string.

Parameters:
  • infile (str) – Name of the file.

  • string (str) – Match string.

Note: fast for large files (>~1Mb) and/or multiple calls (>~100kb).

sluyspy.system.tail_file(in_file, out_file, num_lines)[source]

Use the tail command in a shell to quickly save the last N lines of a file in a new file.

Parameters:
  • in_file (str) – Name of the input file.

  • out_file (str) – Name of the output file.

  • num_lines (int) – Number of lines to save.

sluyspy.system.temp_file_name(dir_name=None, base_name='.tmpfile', ext='tmp')[source]

Return a temporary file name, using the system clock, like “dir/file_YYYYMMDD-HHMMSS.mmmmmm.ext”.

Parameters:
  • dir_name (str) – Name of the directory for the file to be in. Use homedir if None.

  • base_name (str) – Base name of the file.

  • ext (str) – File extension.

Returns:

A temporary file name.

Return type:

(str)

Note

  • microsecond accuracy should suffice; two subsequent calls on my laptop take ~15-20us.