Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 | |
| 17 | import os |
| 18 | |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 19 | all_commands = {} |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | |
| 21 | my_dir = os.path.dirname(__file__) |
| 22 | for py in os.listdir(my_dir): |
| 23 | if py == '__init__.py': |
| 24 | continue |
| 25 | |
| 26 | if py.endswith('.py'): |
| 27 | name = py[:-3] |
| 28 | |
| 29 | clsn = name.capitalize() |
| 30 | while clsn.find('_') > 0: |
| 31 | h = clsn.index('_') |
| 32 | clsn = clsn[0:h] + clsn[h + 1:].capitalize() |
| 33 | |
| 34 | mod = __import__(__name__, |
| 35 | globals(), |
| 36 | locals(), |
| 37 | ['%s' % name]) |
| 38 | mod = getattr(mod, name) |
| 39 | try: |
| 40 | cmd = getattr(mod, clsn)() |
| 41 | except AttributeError: |
Chirayu Desai | 217ea7d | 2013-03-01 19:14:38 +0530 | [diff] [blame] | 42 | raise SyntaxError('%s/%s does not define class %s' % ( |
David Pursehouse | abdf750 | 2020-02-12 14:58:39 +0900 | [diff] [blame] | 43 | __name__, py, clsn)) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | |
| 45 | name = name.replace('_', '-') |
| 46 | cmd.NAME = name |
David Pursehouse | 5c6eeac | 2012-10-11 16:44:48 +0900 | [diff] [blame] | 47 | all_commands[name] = cmd |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | |
Mike Frysinger | d3639c5 | 2020-02-25 15:12:37 -0500 | [diff] [blame^] | 49 | # Add 'branch' as an alias for 'branches'. |
| 50 | all_commands['branch'] = all_commands['branches'] |