1#!/usr/bin/env monkeyrunner
2# Copyright 2010, The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15from com.android.monkeyrunner import MonkeyRunner as mr
16
17import os
18import sys
19
20supported_formats = ['html', 'text', 'sdk-docs']
21
22if len(sys.argv) != 3:
23  print 'help.py: format output'
24  sys.exit(1)
25
26(format, saveto_path) = sys.argv[1:]
27
28if not format.lower() in supported_formats:
29  print 'format %s is not a supported format' % format
30  sys.exit(2)
31
32output = mr.help(format=format)
33if not output:
34  print 'Error generating help format'
35  sys.exit(3)
36
37dirname = os.path.dirname(saveto_path)
38try:
39    os.makedirs(dirname)
40except:
41    print 'oops'
42    pass # It already existed
43
44fp = open(saveto_path, 'w')
45fp.write(output)
46fp.close()
47
48sys.exit(0)
49