From 6b3f25a8ef2a13d3dd1ff30fc98626defbca5484 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Fri, 6 Dec 2013 10:14:59 +0100 Subject: [PATCH] [solo.commands.command] add sharedlock and exclusivelock decorators --- client/solo/commands/command.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/client/solo/commands/command.py b/client/solo/commands/command.py index b459cbc28..e5ad1e153 100644 --- a/client/solo/commands/command.py +++ b/client/solo/commands/command.py @@ -51,6 +51,36 @@ def _fix_argparse_print_help(): _fix_argparse_print_help() +def sharedlock(func): + """ + Solo command methods decorator that acquires the Installed + Packages Repository lock in shared mode and calls the wrapped + function with an extra argument (the Installed Packages + Repository object instance). + """ + def wrapped(zelf, entropy_client, *args, **kwargs): + inst_repo = entropy_client.installed_repository() + with inst_repo.shared(): + return func(zelf, entropy_client, inst_repo, *args, **kwargs) + + return wrapped + + +def exclusivelock(func): + """ + Solo command methods decorator that acquires the Installed + Packages Repository lock in exclusive mode and calls the wrapped + function with an extra argument (the Installed Packages + Repository object instance). + """ + def wrapped(zelf, entropy_client, *args, **kwargs): + inst_repo = entropy_client.installed_repository() + with inst_repo.exclusive(): + return func(zelf, entropy_client, inst_repo, *args, **kwargs) + + return wrapped + + class SoloCommand(object): """ Base class for Solo commands