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
|
# Easy access to interfaces
|
||||||
def api(
|
def api(
|
||||||
namespaces, host="localhost", port=80, routes={}, use_cache=True
|
namespaces, host="localhost", port=80, routes={}
|
||||||
):
|
):
|
||||||
"""Web server (API) interface
|
"""Web server (API) interface
|
||||||
|
|
||||||
|
@ -85,16 +85,13 @@ def api(
|
||||||
- port -- Server port to bind to
|
- port -- Server port to bind to
|
||||||
- routes -- A dict of additional routes to add in the form of
|
- routes -- A dict of additional routes to add in the form of
|
||||||
{(method, uri): callback}
|
{(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.actionsmap import ActionsMap
|
||||||
from moulinette.interfaces.api import Interface, ActionsMapParser
|
from moulinette.interfaces.api import Interface, ActionsMapParser
|
||||||
try:
|
try:
|
||||||
actionsmap = ActionsMap(ActionsMapParser,
|
actionsmap = ActionsMap(ActionsMapParser,
|
||||||
namespaces=namespaces,
|
namespaces=namespaces)
|
||||||
use_cache=use_cache)
|
|
||||||
interface = Interface(actionsmap=actionsmap,
|
interface = Interface(actionsmap=actionsmap,
|
||||||
routes=routes)
|
routes=routes)
|
||||||
interface.run(host, port)
|
interface.run(host, port)
|
||||||
|
@ -113,7 +110,6 @@ def api(
|
||||||
def cli(
|
def cli(
|
||||||
namespaces,
|
namespaces,
|
||||||
args,
|
args,
|
||||||
use_cache=True,
|
|
||||||
output_as=None,
|
output_as=None,
|
||||||
password=None,
|
password=None,
|
||||||
timeout=None,
|
timeout=None,
|
||||||
|
@ -127,8 +123,6 @@ def cli(
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
- namespaces -- The list of namespaces to use
|
- namespaces -- The list of namespaces to use
|
||||||
- args -- A list of argument strings
|
- 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
|
- output_as -- Output result in another format, see
|
||||||
moulinette.interfaces.cli.Interface for possible values
|
moulinette.interfaces.cli.Interface for possible values
|
||||||
- password -- The password to use in case of authentication
|
- password -- The password to use in case of authentication
|
||||||
|
@ -141,7 +135,6 @@ def cli(
|
||||||
try:
|
try:
|
||||||
actionsmap = ActionsMap(ActionsMapParser,
|
actionsmap = ActionsMap(ActionsMapParser,
|
||||||
namespaces=namespaces,
|
namespaces=namespaces,
|
||||||
use_cache=use_cache,
|
|
||||||
parser_kwargs=parser_kwargs)
|
parser_kwargs=parser_kwargs)
|
||||||
interface = Interface(actionsmap=actionsmap)
|
interface = Interface(actionsmap=actionsmap)
|
||||||
interface.run(args, output_as=output_as, password=password, timeout=timeout)
|
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
|
- parser_class -- The BaseActionsMapParser derived class to use
|
||||||
for parsing the actions map
|
for parsing the actions map
|
||||||
- namespaces -- The list of namespaces to use
|
- 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
|
- parser_kwargs -- A dict of arguments to pass to the parser
|
||||||
class at construction
|
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):
|
if not issubclass(parser_class, BaseActionsMapParser):
|
||||||
raise ValueError("Invalid parser class '%s'" % parser_class.__name__)
|
raise ValueError("Invalid parser class '%s'" % parser_class.__name__)
|
||||||
self.parser_class = parser_class
|
self.parser_class = parser_class
|
||||||
self.use_cache = use_cache
|
|
||||||
|
|
||||||
moulinette_env = init_moulinette_env()
|
moulinette_env = init_moulinette_env()
|
||||||
DATA_DIR = moulinette_env["DATA_DIR"]
|
DATA_DIR = moulinette_env["DATA_DIR"]
|
||||||
|
@ -439,21 +436,19 @@ class ActionsMap(object):
|
||||||
actionsmap_yml_stat.st_mtime,
|
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:
|
try:
|
||||||
# Attempt to load cache
|
# Attempt to load cache
|
||||||
with open(actionsmap_pkl) as f:
|
with open(actionsmap_pkl) as f:
|
||||||
actionsmaps[n] = pickle.load(f)
|
actionsmaps[n] = pickle.load(f)
|
||||||
# TODO: Switch to python3 and catch proper exception
|
# TODO: Switch to python3 and catch proper exception
|
||||||
except (IOError, EOFError):
|
except (IOError, EOFError):
|
||||||
self.use_cache = False
|
self.from_cache = False
|
||||||
actionsmaps = self.generate_cache(namespaces)
|
actionsmaps = self.generate_cache(namespaces)
|
||||||
elif use_cache: # cached file doesn't exists
|
else: # cache file doesn't exists
|
||||||
self.use_cache = False
|
self.from_cache = False
|
||||||
actionsmaps = self.generate_cache(namespaces)
|
actionsmaps = self.generate_cache(namespaces)
|
||||||
elif n not in actionsmaps:
|
|
||||||
with open(actionsmap_yml) as f:
|
|
||||||
actionsmaps[n] = ordered_yaml_load(f)
|
|
||||||
|
|
||||||
# Load translations
|
# Load translations
|
||||||
m18n.load_namespace(n)
|
m18n.load_namespace(n)
|
||||||
|
@ -668,11 +663,10 @@ class ActionsMap(object):
|
||||||
An interface relevant's parser object
|
An interface relevant's parser object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Get extra parameters
|
|
||||||
if self.use_cache:
|
# If loading from cache, extra were already checked when cache was
|
||||||
validate_extra = False
|
# loaded ? Not sure about this ... old code is a bit mysterious...
|
||||||
else:
|
validate_extra = not self.from_cache
|
||||||
validate_extra = True
|
|
||||||
|
|
||||||
# Instantiate parser
|
# Instantiate parser
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Reference in a new issue