-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
595 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (2018) Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# Python libs | ||
import threading | ||
|
||
|
||
# Globals vars: | ||
# globals()['map_category_resources_ov'] | ||
|
||
lock = threading.Lock() | ||
|
||
|
||
class CategoryResource(object): | ||
def __init__(self, resource_id, resource, function): | ||
self.resource_id = resource_id | ||
self.resource = resource | ||
self.function = function | ||
|
||
|
||
def init_map_category_resources(): | ||
globals()['map_category_resources_ov'] = dict() | ||
|
||
|
||
def _get_map_category_resources(): | ||
return globals()['map_category_resources_ov'] | ||
|
||
|
||
def set_map_category_resources_entry(resource_id, resource, function): | ||
# Check if the resource's category is already cached | ||
if get_category_by_resource_id(resource_id): | ||
return | ||
|
||
with lock: | ||
_get_map_category_resources()[resource_id] = \ | ||
CategoryResource(resource_id, resource, function) | ||
|
||
|
||
def get_category_by_resource_id(resource_id): | ||
"""Get cached resource category by resource ID""" | ||
cached_category = _get_map_category_resources().get(resource_id) | ||
|
||
return cached_category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.