mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
We don't need to be able to not use the cache...
This commit is contained in:
parent
b6258de2db
commit
fce96ad48f
2 changed files with 12 additions and 25 deletions
|
@ -73,7 +73,7 @@ def init(logging_config=None, **kwargs):
|
|||
|
||||
# Easy access to interfaces
|
||||
def api(
|
||||
namespaces, host="localhost", port=80, routes={}, use_cache=True
|
||||
namespaces, host="localhost", port=80, routes={}
|
||||
):
|
||||
"""Web server (API) interface
|
||||
|
||||
|
@ -85,16 +85,13 @@ def api(
|
|||
- port -- Server port to bind to
|
||||
- routes -- A dict of additional routes to add in the form of
|
||||
{(method, uri): callback}
|
||||
- use_cache -- False if it should parse the actions map file
|
||||
instead of using the cached one
|
||||
|
||||
"""
|
||||
from moulinette.actionsmap import ActionsMap
|
||||
from moulinette.interfaces.api import Interface, ActionsMapParser
|
||||
try:
|
||||
actionsmap = ActionsMap(ActionsMapParser,
|
||||
namespaces=namespaces,
|
||||
use_cache=use_cache)
|
||||
namespaces=namespaces)
|
||||
interface = Interface(actionsmap=actionsmap,
|
||||
routes=routes)
|
||||
interface.run(host, port)
|
||||
|
@ -113,7 +110,6 @@ def api(
|
|||
def cli(
|
||||
namespaces,
|
||||
args,
|
||||
use_cache=True,
|
||||
output_as=None,
|
||||
password=None,
|
||||
timeout=None,
|
||||
|
@ -127,8 +123,6 @@ def cli(
|
|||
Keyword arguments:
|
||||
- namespaces -- The list of namespaces to use
|
||||
- args -- A list of argument strings
|
||||
- use_cache -- False if it should parse the actions map file
|
||||
instead of using the cached one
|
||||
- output_as -- Output result in another format, see
|
||||
moulinette.interfaces.cli.Interface for possible values
|
||||
- password -- The password to use in case of authentication
|
||||
|
@ -141,7 +135,6 @@ def cli(
|
|||
try:
|
||||
actionsmap = ActionsMap(ActionsMapParser,
|
||||
namespaces=namespaces,
|
||||
use_cache=use_cache,
|
||||
parser_kwargs=parser_kwargs)
|
||||
interface = Interface(actionsmap=actionsmap)
|
||||
interface.run(args, output_as=output_as, password=password, timeout=timeout)
|
||||
|
|
|
@ -405,18 +405,15 @@ class ActionsMap(object):
|
|||
- parser_class -- The BaseActionsMapParser derived class to use
|
||||
for parsing the actions map
|
||||
- namespaces -- The list of namespaces to use
|
||||
- use_cache -- False if it should parse the actions map file
|
||||
instead of using the cached one
|
||||
- parser_kwargs -- A dict of arguments to pass to the parser
|
||||
class at construction
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, parser_class, namespaces=[], use_cache=True, parser_kwargs={}):
|
||||
def __init__(self, parser_class, namespaces=[], parser_kwargs={}):
|
||||
if not issubclass(parser_class, BaseActionsMapParser):
|
||||
raise ValueError("Invalid parser class '%s'" % parser_class.__name__)
|
||||
self.parser_class = parser_class
|
||||
self.use_cache = use_cache
|
||||
|
||||
moulinette_env = init_moulinette_env()
|
||||
DATA_DIR = moulinette_env["DATA_DIR"]
|
||||
|
@ -439,21 +436,19 @@ class ActionsMap(object):
|
|||
actionsmap_yml_stat.st_mtime,
|
||||
)
|
||||
|
||||
if use_cache and os.path.exists(actionsmap_pkl):
|
||||
if os.path.exists(actionsmap_pkl):
|
||||
self.from_cache = True
|
||||
try:
|
||||
# Attempt to load cache
|
||||
with open(actionsmap_pkl) as f:
|
||||
actionsmaps[n] = pickle.load(f)
|
||||
# TODO: Switch to python3 and catch proper exception
|
||||
except (IOError, EOFError):
|
||||
self.use_cache = False
|
||||
self.from_cache = False
|
||||
actionsmaps = self.generate_cache(namespaces)
|
||||
elif use_cache: # cached file doesn't exists
|
||||
self.use_cache = False
|
||||
else: # cache file doesn't exists
|
||||
self.from_cache = False
|
||||
actionsmaps = self.generate_cache(namespaces)
|
||||
elif n not in actionsmaps:
|
||||
with open(actionsmap_yml) as f:
|
||||
actionsmaps[n] = ordered_yaml_load(f)
|
||||
|
||||
# Load translations
|
||||
m18n.load_namespace(n)
|
||||
|
@ -668,11 +663,10 @@ class ActionsMap(object):
|
|||
An interface relevant's parser object
|
||||
|
||||
"""
|
||||
# Get extra parameters
|
||||
if self.use_cache:
|
||||
validate_extra = False
|
||||
else:
|
||||
validate_extra = True
|
||||
|
||||
# If loading from cache, extra were already checked when cache was
|
||||
# loaded ? Not sure about this ... old code is a bit mysterious...
|
||||
validate_extra = not self.from_cache
|
||||
|
||||
# Instantiate parser
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue