Cache : cache_manager#

Hierarchy:

source code documentation#

Manage the NXDL cache directories of this project.

A key component necessary to validate both NeXus data files and NXDL class files is a current set of the NXDL definitions.

There are two cache directories:

  • the source cache

  • the user cache

Within each of these cache directories, there may be one or more subdirectories, each containing the NeXus definitions subdirectories and files (*.xml, *.xsl, & *.xsd) of a specific branch, release, tag, or commit hash from the NeXus definitions repository.

source cache:

contains default set of NeXus NXDL files

user cache:

contains additional set(s) of NeXus NXDL files, installed by user

The cache_manager is called by main, schema_manager, and nxdl_manager.

Public interface

CacheManager(*args, **kwargs)

manager both source and user caches

Internal interface

get_short_sha(full_sha)

return the first few unique characters of the git commit hash (SHA)

read_json_file(filename)

read a structured object from the JSON file file_name

write_json_file(filename, obj)

write the structured obj to the JSON file file_name

is_extractable(item, allowed_endings, ...)

decide if this item should be extracted from the ZIP download.

download_NeXus_zip_archive(url)

Download the NXDL definitions described by url.

download_file_set(file_set_name, cache_path)

Download & extract NXDL file set into a subdirectory of cache_path.

table_of_caches()

return a pyRestTable table describing all known file sets in both source and user caches

Base_Cache()

provides comon methods to get the QSettings path and file name

SourceCache()

manage the source directory cache of NXDL files

UserCache()

manage the user directory cache of NXDL files

NXDL_File_Set()

describe a single set of NXDL files

class punx.cache_manager.Base_Cache[source]#

provides comon methods to get the QSettings path and file name

all_file_sets

index all NXDL file sets in this cache

fileName()

full path of the QSettings file

path

directory containing the QSettings file

cleanup()

removes any temporary directories

property all_file_sets#

index all NXDL file sets in this cache

cleanup()[source]#

removes any temporary directories

fileName()[source]#

full path of the QSettings file

property path#

directory containing the QSettings file

class punx.cache_manager.CacheManager(*args, **kwargs)[source]#

manager both source and user caches

select_NXDL_file_set([ref])

Return the named self.default_file_set instance.

all_file_sets

return dictionary of all NXDL file sets in both source & user caches

cleanup()

removes any temporary directories

property all_file_sets#

return dictionary of all NXDL file sets in both source & user caches

cleanup()[source]#

removes any temporary directories

select_NXDL_file_set(ref=None)[source]#

Return the named self.default_file_set instance.

Raise KeyError exception if unknown.

Return obj:

table_of_caches()[source]#

return a pyRestTable table describing all known file sets in both source and user caches

Returns obj:

instance of pyRestTable.Table with all known file sets

Example:

============= ====== =================== ======= ==================================================================
NXDL file set cache  date & time         commit  path
============= ====== =================== ======= ==================================================================
a4fd52d       source 2016-11-19 01:07:45 a4fd52d /home/prjemian/Documents/projects/prjemian/punx/punx/cache/a4fd52d
v3.3          source 2017-07-12 10:41:12 9285af9 /home/prjemian/Documents/projects/prjemian/punx/punx/cache/v3.3
v2018.5       source 2018-05-15 16:34:19 a3045fd /home/prjemian/Documents/projects/prjemian/punx/punx/cache/v2018.5
Schema-3.4    user   2018-05-15 08:24:34 aa1ccd1 /home/prjemian/.config/punx/Schema-3.4
main          user   2021-12-17 13:09:18 041c2c0 /home/prjemian/.config/punx/main
============= ====== =================== ======= ==================================================================
class punx.cache_manager.NXDL_File_Set[source]#

describe a single set of NXDL files

class punx.cache_manager.SourceCache[source]#

manage the source directory cache of NXDL files

class punx.cache_manager.UserCache[source]#

manage the user directory cache of NXDL files

punx.cache_manager.download_NeXus_zip_archive(url)[source]#

Download the NXDL definitions described by url.

Return the downloaded content in memory.

punx.cache_manager.download_file_set(file_set_name, cache_path, replace=False)[source]#

Download & extract NXDL file set into a subdirectory of cache_path.

file_set_name str :

Name of the NXDL file_set to be downloaded.

cache_path obj :

Directory with NXDL file_sets (instance of pathlib.Path). (A file_set is a directory with a version of the NeXus definitions repository.)

replace bool :

If True and file set exists, replace it. (default: False)

USAGE:

download_file_set(file_set_name, cache_path, replace=False)
punx.cache_manager.get_short_sha(full_sha)[source]#

return the first few unique characters of the git commit hash (SHA)

Parameters:

full_sha (str) – hash code from Github

punx.cache_manager.is_extractable(item, allowed_endings, allowed_parents)[source]#

decide if this item should be extracted from the ZIP download.

Return bool:

punx.cache_manager.read_json_file(filename)[source]#

read a structured object from the JSON file file_name

See:

https://docs.python.org/3.5/library/json.html#json.loads

punx.cache_manager.table_of_caches()[source]#

return a pyRestTable table describing all known file sets in both source and user caches

Returns obj:

instance of pyRestTable.Table with all known file sets

Example:

============= ====== =================== ======= ==================================================================
NXDL file set cache  date & time         commit  path
============= ====== =================== ======= ==================================================================
a4fd52d       source 2016-11-19 01:07:45 a4fd52d /home/prjemian/Documents/projects/prjemian/punx/punx/cache/a4fd52d
v3.3          source 2017-07-12 10:41:12 9285af9 /home/prjemian/Documents/projects/prjemian/punx/punx/cache/v3.3
v2018.5       source 2018-05-15 16:34:19 a3045fd /home/prjemian/Documents/projects/prjemian/punx/punx/cache/v2018.5
Schema-3.4    user   2018-05-15 08:24:34 aa1ccd1 /home/prjemian/.config/punx/Schema-3.4
main          user   2021-12-17 13:09:18 041c2c0 /home/prjemian/.config/punx/main
============= ====== =================== ======= ==================================================================
punx.cache_manager.write_json_file(filename, obj)[source]#

write the structured obj to the JSON file file_name

See:

https://docs.python.org/3.5/library/json.html#json.dumps