OpenStack Source Explorer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

project_filter.py 901B

123456789101112131415161718192021222324252627282930313233343536
  1. import argparse
  2. from aeromancer.db.models import Project
  3. class ProjectFilter(object):
  4. """Manage the arguments for filtering queries by project.
  5. """
  6. @staticmethod
  7. def add_arguments(parser):
  8. """Given an argparse.ArgumentParser add arguments.
  9. """
  10. grp = parser.add_argument_group('Project Filter')
  11. grp.add_argument(
  12. '--project',
  13. action='append',
  14. default=[],
  15. dest='projects',
  16. help='projects to limit search, by exact name',
  17. )
  18. @classmethod
  19. def from_parsed_args(cls, parsed_args):
  20. return cls(projects=parsed_args.projects)
  21. def __init__(self, projects):
  22. self.projects = projects
  23. def update_query(self, query):
  24. if self.projects:
  25. query = query.filter(
  26. Project.name.in_(self.projects)
  27. )
  28. return query