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