OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
7 | 7 |
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
10 run pydoc on this file. | 10 run pydoc on this file. |
(...skipping 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2985 } | 2985 } |
2986 self._GetResultFromJSONRequest(cmd_dict, windex=window_index) | 2986 self._GetResultFromJSONRequest(cmd_dict, windex=window_index) |
2987 try: | 2987 try: |
2988 f = open(filename) | 2988 f = open(filename) |
2989 all_data = f.read() | 2989 all_data = f.read() |
2990 f.close() | 2990 f.close() |
2991 return all_data | 2991 return all_data |
2992 finally: | 2992 finally: |
2993 shutil.rmtree(tempdir, ignore_errors=True) | 2993 shutil.rmtree(tempdir, ignore_errors=True) |
2994 | 2994 |
2995 def ImportSettings(self, import_from, first_run, | 2995 def ImportSettings(self, import_from, import_items, windex=0): |
2996 import_items, windex=0): | |
2997 """Import the specified import items from the specified browser. | 2996 """Import the specified import items from the specified browser. |
2998 | 2997 |
2999 Implements the features available in the "Import Settings" part of the | 2998 Implements the features available in the "Import Settings" part of the |
3000 first-run UI dialog. | 2999 first-run UI dialog. |
3001 | 3000 |
3002 Args: | 3001 Args: |
3003 import_from: A string indicating which browser to import from. Possible | 3002 import_from: A string indicating which browser to import from. Possible |
3004 strings (depending on which browsers are installed on the | 3003 strings (depending on which browsers are installed on the |
3005 machine) are: 'Mozilla Firefox', 'Google Toolbar', | 3004 machine) are: 'Mozilla Firefox', 'Google Toolbar', |
3006 'Microsoft Internet Explorer', 'Safari' | 3005 'Microsoft Internet Explorer', 'Safari' |
3007 first_run: A boolean indicating whether this is the first run of | |
3008 the browser. | |
3009 If it is not the first run then: | |
3010 1) Bookmarks are only imported to the bookmarks bar if there | |
3011 aren't already bookmarks. | |
3012 2) The bookmark bar is shown. | |
3013 import_items: A list of strings indicating which items to import. | 3006 import_items: A list of strings indicating which items to import. |
3014 Strings that can be in the list are: | 3007 Strings that can be in the list are: |
3015 HISTORY, FAVORITES, PASSWORDS, SEARCH_ENGINES, HOME_PAGE, | 3008 HISTORY, FAVORITES, PASSWORDS, SEARCH_ENGINES, HOME_PAGE, |
3016 ALL (note: COOKIES is not supported by the browser yet) | 3009 ALL (note: COOKIES is not supported by the browser yet) |
3017 windex: window index, defaults to 0. | 3010 windex: window index, defaults to 0. |
3018 | 3011 |
3019 Raises: | 3012 Raises: |
3020 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 3013 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
3021 """ | 3014 """ |
3022 cmd_dict = { # Prepare command for the json interface | 3015 cmd_dict = { # Prepare command for the json interface |
3023 'command': 'ImportSettings', | 3016 'command': 'ImportSettings', |
3024 'import_from': import_from, | 3017 'import_from': import_from, |
3025 'first_run': first_run, | |
3026 'import_items': import_items | 3018 'import_items': import_items |
3027 } | 3019 } |
3028 return self._GetResultFromJSONRequest(cmd_dict, windex=windex) | 3020 return self._GetResultFromJSONRequest(cmd_dict, windex=windex) |
3029 | 3021 |
3030 def AddSavedPassword(self, password_dict, windex=0): | 3022 def AddSavedPassword(self, password_dict, windex=0): |
3031 """Adds the given username-password combination to the saved passwords. | 3023 """Adds the given username-password combination to the saved passwords. |
3032 | 3024 |
3033 Args: | 3025 Args: |
3034 password_dict: a dictionary that represents a password. Example: | 3026 password_dict: a dictionary that represents a password. Example: |
3035 { 'username_value': 'user@example.com', # Required | 3027 { 'username_value': 'user@example.com', # Required |
(...skipping 3172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6208 successful = result.wasSuccessful() | 6200 successful = result.wasSuccessful() |
6209 if not successful: | 6201 if not successful: |
6210 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6202 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6211 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6203 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6212 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6204 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6213 sys.exit(not successful) | 6205 sys.exit(not successful) |
6214 | 6206 |
6215 | 6207 |
6216 if __name__ == '__main__': | 6208 if __name__ == '__main__': |
6217 Main() | 6209 Main() |
OLD | NEW |