| |
@@ -1,113 +0,0 @@
|
| |
- #!/usr/bin/env python
|
| |
-
|
| |
- """
|
| |
- Small script to remove the cache of one or more widgets while keeping the
|
| |
- other ones un-touched.
|
| |
-
|
| |
- This is really useful for development purposes as it allow seeing changes
|
| |
- made to a widget without dropping the entire cache database.
|
| |
- """
|
| |
-
|
| |
- from __future__ import print_function, unicode_literals
|
| |
-
|
| |
- import argparse
|
| |
-
|
| |
- import hubs.app
|
| |
- import hubs.models
|
| |
- import hubs.widgets.base
|
| |
- from hubs.database import Session
|
| |
-
|
| |
-
|
| |
- db = Session()
|
| |
- # Register widgets
|
| |
- hubs.widgets.registry.register_list(hubs.app.app.config["WIDGETS"])
|
| |
-
|
| |
-
|
| |
- def do_list(args):
|
| |
- ''' List the different widget for which there is data cached. '''
|
| |
- for w_instance in db.query(hubs.models.Widget).all():
|
| |
- if not w_instance.enabled:
|
| |
- continue
|
| |
- widget = w_instance.module
|
| |
- for fn_name, fn_class in widget.get_cached_functions().items():
|
| |
- if fn_class(w_instance).is_cached():
|
| |
- print(('- Widget cached {inst.hub_id} (#{inst.idx}) '
|
| |
- 'in {inst.plugin}').format(inst=w_instance))
|
| |
-
|
| |
-
|
| |
- def do_clean(args):
|
| |
- ''' Clean the widget for which there is data cached. '''
|
| |
- for widget in args.widgets:
|
| |
- widget_instance = hubs.models.Widget.get(widget)
|
| |
-
|
| |
- if widget_instance is None:
|
| |
- widget_instances = db.query(hubs.models.Widget).filter_by(
|
| |
- plugin=widget).all()
|
| |
- else:
|
| |
- widget_instances = [widget_instance]
|
| |
-
|
| |
- if not widget_instances:
|
| |
- print('No widget found for {0}'.format(widget))
|
| |
-
|
| |
- for widget_instance in widget_instances:
|
| |
- print('- Removing cached {0} (#{1}) in {2}'.format(
|
| |
- widget_instance.hub_id,
|
| |
- widget_instance.idx,
|
| |
- widget_instance.plugin))
|
| |
- functions = widget_instance.module.get_cached_functions().values()
|
| |
- for fn_class in functions:
|
| |
- fn_class(widget_instance).invalidate()
|
| |
-
|
| |
-
|
| |
- def setup_parser():
|
| |
- '''
|
| |
- Set the main arguments.
|
| |
- '''
|
| |
- parser = argparse.ArgumentParser(prog="smart_cache_invalidator")
|
| |
- subparsers = parser.add_subparsers(title='actions')
|
| |
-
|
| |
- # List
|
| |
- parser_list = subparsers.add_parser(
|
| |
- 'list',
|
| |
- help='List the different widgets for which there is cached data')
|
| |
- parser_list.set_defaults(func=do_list)
|
| |
-
|
| |
- # Clean
|
| |
- parser_clean = subparsers.add_parser(
|
| |
- 'clean', help='Clean the specified widget')
|
| |
- parser_clean.add_argument(
|
| |
- 'widgets', nargs="+",
|
| |
- help="Identifier or name of the one or moe widgets to clean")
|
| |
- parser_clean.set_defaults(func=do_clean)
|
| |
-
|
| |
- return parser
|
| |
-
|
| |
-
|
| |
- def main():
|
| |
- ''' Main function '''
|
| |
- return_code = 0
|
| |
-
|
| |
- # Set up parser for global args
|
| |
- parser = setup_parser()
|
| |
-
|
| |
- # Parse the commandline
|
| |
- try:
|
| |
- arg = parser.parse_args()
|
| |
- except argparse.ArgumentTypeError as err:
|
| |
- print("\nError: {0}".format(err))
|
| |
- return 1
|
| |
-
|
| |
- try:
|
| |
- arg.func(arg)
|
| |
- except KeyboardInterrupt:
|
| |
- print("\nInterrupted by user.")
|
| |
- return_code = 2
|
| |
- except Exception as err:
|
| |
- print('Error: {0}'.format(err))
|
| |
- return_code = 3
|
| |
-
|
| |
- return return_code
|
| |
-
|
| |
-
|
| |
- if __name__ == '__main__':
|
| |
- main()
|
| |
Just a few fixes and reorganization, plus integration of the cache scripts that were at the root of the repo.