schema_util

Utilities for writing content to files and for other file manipulation.

Functions

get_api_key()

Tries to get the GitHub access token from the environment. Defaults to above value if not found.

make_url_request(resource_url[, ...])

Make a request and adds the above GitHub access credentials.

move_file(input_path, target_path)

If target_path is not empty, move input file to target file

url_to_file(resource_url)

Write data from a URL resource into a file.

url_to_string(resource_url)

Get the data from the specified url as a string.

write_strings_to_file(output_strings[, ...])

Write output strings to a temporary file.

write_xml_tree_2_xml_file(xml_tree[, extension])

Write an XML element tree object into an XML file.

get_api_key()[source]

Tries to get the GitHub access token from the environment. Defaults to above value if not found.

Returns:

A GitHub access key or an empty string.

make_url_request(resource_url, try_authenticate=True)[source]

Make a request and adds the above GitHub access credentials.

Parameters:
  • resource_url (str) – The url to retrieve.

  • try_authenticate (bool) – If true add the above credentials.

Returns:

url_request

move_file(input_path, target_path)[source]

If target_path is not empty, move input file to target file

Parameters:
  • input_path (str) – Path to an existing file

  • target_path (str or None) – Path to move this file to If None, the function does nothing and returns input_path

Returns:

the original or moved filepath

Return type:

filepath(str)

url_to_file(resource_url)[source]

Write data from a URL resource into a file. Data is decoded as unicode.

Parameters:

resource_url (str) – The URL to the resource.

Returns:

The local temporary filename for the downloaded file,

Return type:

str

url_to_string(resource_url)[source]

Get the data from the specified url as a string.

Parameters:

resource_url (str) – The URL to the resource.

Returns:

The data at the target url.

Return type:

str

write_strings_to_file(output_strings, extension=None)[source]

Write output strings to a temporary file.

Parameters:
  • output_strings ([str], str) – Strings to output one per line.

  • extension (str) – File extension of the temporary file.

Returns:

Opened temporary file.

Return type:

file

write_xml_tree_2_xml_file(xml_tree, extension='.xml')[source]

Write an XML element tree object into an XML file.

Parameters:
  • xml_tree (Element) – An element representing an XML file.

  • extension (string) – The file extension to use for the temporary file.

Returns:

Name of the temporary file.

Return type:

str