__init__.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2008 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import os
  17. all_commands = {}
  18. my_dir = os.path.dirname(__file__)
  19. for py in os.listdir(my_dir):
  20. if py == '__init__.py':
  21. continue
  22. if py.endswith('.py'):
  23. name = py[:-3]
  24. clsn = name.capitalize()
  25. while clsn.find('_') > 0:
  26. h = clsn.index('_')
  27. clsn = clsn[0:h] + clsn[h + 1:].capitalize()
  28. mod = __import__(__name__,
  29. globals(),
  30. locals(),
  31. ['%s' % name])
  32. mod = getattr(mod, name)
  33. try:
  34. cmd = getattr(mod, clsn)()
  35. except AttributeError:
  36. raise SyntaxError('%s/%s does not define class %s' % (
  37. __name__, py, clsn))
  38. name = name.replace('_', '-')
  39. cmd.NAME = name
  40. all_commands[name] = cmd
  41. # Add 'branch' as an alias for 'branches'.
  42. all_commands['branch'] = all_commands['branches']