blob: 273410388f559d0c1bbe90b9f99b677bbc0aef36 [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
David Pursehouse5c6eeac2012-10-11 16:44:48 +090019all_commands = {}
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070020
21my_dir = os.path.dirname(__file__)
22for 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 Desai217ea7d2013-03-01 19:14:38 +053042 raise SyntaxError('%s/%s does not define class %s' % (
43 __name__, py, clsn))
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070044
45 name = name.replace('_', '-')
46 cmd.NAME = name
David Pursehouse5c6eeac2012-10-11 16:44:48 +090047 all_commands[name] = cmd
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070048
David Pursehouse5c6eeac2012-10-11 16:44:48 +090049if 'help' in all_commands:
50 all_commands['help'].commands = all_commands