blob: c3de9d1e247ceb5544b9fb4d630b7cf50edd5846 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07002#
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
17import os
18
Mike Frysingerbb930462020-02-25 15:18:31 -050019# A mapping of the subcommand name to the class that implements it.
David Pursehouse5c6eeac2012-10-11 16:44:48 +090020all_commands = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070021
22my_dir = os.path.dirname(__file__)
23for py in os.listdir(my_dir):
24 if py == '__init__.py':
25 continue
26
27 if py.endswith('.py'):
28 name = py[:-3]
29
30 clsn = name.capitalize()
31 while clsn.find('_') > 0:
32 h = clsn.index('_')
33 clsn = clsn[0:h] + clsn[h + 1:].capitalize()
34
35 mod = __import__(__name__,
36 globals(),
37 locals(),
38 ['%s' % name])
39 mod = getattr(mod, name)
40 try:
Mike Frysingerbb930462020-02-25 15:18:31 -050041 cmd = getattr(mod, clsn)
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070042 except AttributeError:
Chirayu Desai217ea7d2013-03-01 19:14:38 +053043 raise SyntaxError('%s/%s does not define class %s' % (
David Pursehouseabdf7502020-02-12 14:58:39 +090044 __name__, py, clsn))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070045
46 name = name.replace('_', '-')
47 cmd.NAME = name
David Pursehouse5c6eeac2012-10-11 16:44:48 +090048 all_commands[name] = cmd
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070049
Mike Frysingerd3639c52020-02-25 15:12:37 -050050# Add 'branch' as an alias for 'branches'.
51all_commands['branch'] = all_commands['branches']