blob: 051dda06fb370f26c354ddad3003c42cab0a0da1 [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001# Copyright (C) 2008 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16
Mike Frysingerbb930462020-02-25 15:18:31 -050017# A mapping of the subcommand name to the class that implements it.
David Pursehouse5c6eeac2012-10-11 16:44:48 +090018all_commands = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070019
20my_dir = os.path.dirname(__file__)
21for py in os.listdir(my_dir):
22 if py == '__init__.py':
23 continue
24
25 if py.endswith('.py'):
26 name = py[:-3]
27
28 clsn = name.capitalize()
29 while clsn.find('_') > 0:
30 h = clsn.index('_')
31 clsn = clsn[0:h] + clsn[h + 1:].capitalize()
32
33 mod = __import__(__name__,
34 globals(),
35 locals(),
36 ['%s' % name])
37 mod = getattr(mod, name)
38 try:
Mike Frysingerbb930462020-02-25 15:18:31 -050039 cmd = getattr(mod, clsn)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070040 except AttributeError:
Chirayu Desai217ea7d2013-03-01 19:14:38 +053041 raise SyntaxError('%s/%s does not define class %s' % (
David Pursehouseabdf7502020-02-12 14:58:39 +090042 __name__, py, clsn))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070043
44 name = name.replace('_', '-')
45 cmd.NAME = name
David Pursehouse5c6eeac2012-10-11 16:44:48 +090046 all_commands[name] = cmd
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070047
Mike Frysingerd3639c52020-02-25 15:12:37 -050048# Add 'branch' as an alias for 'branches'.
49all_commands['branch'] = all_commands['branches']