DevStack supporting tools in python
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.

cmd.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright 2017 IBM
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. import argparse
  15. import sys
  16. import devstack.dsconf
  17. def iniset(inifile, args):
  18. inifile.set(args.section, args.name, args.value)
  19. def inirm(inifile, args):
  20. inifile.remove(args.section, args.name)
  21. def inicomment(inifile, args):
  22. inifile.comment(args.section, args.name)
  23. def iniuncomment(inifile, args):
  24. inifile.uncomment(args.section, args.name)
  25. def parse_args(argv):
  26. parser = argparse.ArgumentParser(prog='dsconf')
  27. subparsers = parser.add_subparsers(title='commands',
  28. help='sub-command help')
  29. parser_iniset = subparsers.add_parser('iniset', help='iniset help')
  30. parser_iniset.set_defaults(func=iniset)
  31. parser_iniset.add_argument('inifile', help='name of file')
  32. parser_iniset.add_argument('section', help='name of section')
  33. parser_iniset.add_argument('name', help='name')
  34. parser_iniset.add_argument('value', help='value')
  35. parser_inicomment = subparsers.add_parser('inicomment', help='inicomment help')
  36. parser_inicomment.set_defaults(func=inicomment)
  37. parser_inicomment.add_argument('inifile', help='name of file')
  38. parser_inicomment.add_argument('section', help='name of section')
  39. parser_inicomment.add_argument('name', help='name')
  40. parser_iniuncomment = subparsers.add_parser('iniuncomment', help='iniuncomment help')
  41. parser_iniuncomment.set_defaults(func=iniuncomment)
  42. parser_iniuncomment.add_argument('inifile', help='name of file')
  43. parser_iniuncomment.add_argument('section', help='name of section')
  44. parser_iniuncomment.add_argument('name', help='name')
  45. parser_inirm = subparsers.add_parser('inirm', help='inirm help')
  46. parser_inirm.set_defaults(func=inirm)
  47. parser_inirm.add_argument('inifile', help='name of file')
  48. parser_inirm.add_argument('section', help='name of section')
  49. parser_inirm.add_argument('name', help='name')
  50. return parser.parse_args()
  51. def main(argv=None):
  52. args = parse_args(argv or sys.argv)
  53. if hasattr(args, 'inifile'):
  54. f = devstack.dsconf.IniFile(args.inifile)
  55. args.func(f, args)
  56. return