Cache : cache_manager

Hierarchy:

source code documentation

manages 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 calls the github_handler and is called by schema_manager and nxdl_manager.

Public interface

CacheManager() 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
should_extract_this(item, …) decide if this item should be extracted from the ZIP download
should_avoid_download(grr, path) decide if the download should be avoided (True: avoid, False: download)
extract_from_download(grr, path) download & extract NXDL files from grr into a subdirectory of 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

find_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
cleanup()[source]

removes any temporary directories

fileName()[source]

full path of the QSettings file

find_all_file_sets()[source]

index all NXDL file sets in this cache

path()[source]

directory containing the QSettings file

class punx.cache_manager.CacheManager[source]

manager both source and user caches

install_NXDL_file_set(grr[, user_cache, …]) using ref as a name, get the se of NXDL files from the NeXus GitHub
select_NXDL_file_set([ref]) return the named self.default_file_set instance or raise KeyError exception if unknown
find_all_file_sets() return dictionary of all NXDL file sets in both source & user caches
cleanup() removes any temporary directories
cleanup()[source]

removes any temporary directories

find_all_file_sets()[source]

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

install_NXDL_file_set(grr, user_cache=True, ref=None, force=False)[source]

using ref as a name, get the se of NXDL files from the NeXus GitHub

Parameters:
  • grr (obj) – instance of GitHub_Repository_Reference
  • user_cache (bool) – True: use user cache, `` False``: use source cache (default)
  • ref (str) – name to use when requesting from GitHub, (master, commit hash such as abc1234, branch name, release name such as v3.2, or tag name)
  • force (bool) – update if installed is not the same SHA
select_NXDL_file_set(ref=None)[source]

return the named self.default_file_set instance or 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 type    cache  date & time         commit  path
============= ======= ====== =================== ======= ===================================
v3.2          tag     source 2017-01-18 23:12:44 e888dac /home/user/punx/src/punx/cache/v3.2
NXroot-1.0    tag     user   2016-10-24 14:58:10 e0ad63d /home/user/.config/punx/NXroot-1.0
master        branch  user   2016-12-20 18:30:29 85d056f /home/user/.config/punx/master
Schema-3.3    release user   2017-05-02 12:33:19 4aa4215 /home/user/.config/punx/Schema-3.3
a4fd52d       commit  user   2016-11-19 01:07:45 a4fd52d /home/user/.config/punx/a4fd52d
============= ======= ====== =================== ======= ===================================
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.extract_from_download(grr, path)[source]

download & extract NXDL files from grr into a subdirectory of path

USAGE:

grr = github_handler.GitHub_Repository_Reference()
grr.connect_repo()
if grr.request_info() is not None:
    extract_from_download(grr, cache_directory)
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.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.should_avoid_download(grr, path)[source]

decide if the download should be avoided (True: avoid, False: download)

Return bool:
punx.cache_manager.should_extract_this(item, NXDL_file_endings_list, allowed_parent_directories)[source]

decide if this item should be extracted from the ZIP download

Return bool:
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 type    cache  date & time         commit  path
============= ======= ====== =================== ======= ===================================
v3.2          tag     source 2017-01-18 23:12:44 e888dac /home/user/punx/src/punx/cache/v3.2
NXroot-1.0    tag     user   2016-10-24 14:58:10 e0ad63d /home/user/.config/punx/NXroot-1.0
master        branch  user   2016-12-20 18:30:29 85d056f /home/user/.config/punx/master
Schema-3.3    release user   2017-05-02 12:33:19 4aa4215 /home/user/.config/punx/Schema-3.3
a4fd52d       commit  user   2016-11-19 01:07:45 a4fd52d /home/user/.config/punx/a4fd52d
============= ======= ====== =================== ======= ===================================
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