| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import json | 4 import json |
| 5 import urlparse | 5 import urlparse |
| 6 | 6 |
| 7 class Page(object): | 7 class Page(object): |
| 8 def __init__(self, url, attributes=None): | 8 def __init__(self, url, attributes=None): |
| 9 self.url = url | 9 self.url = url |
| 10 parsed_url = urlparse.urlparse(url) | 10 parsed_url = urlparse.urlparse(url) |
| 11 if parsed_url.scheme == None: # pylint: disable=E1101 | 11 if parsed_url.scheme == None: # pylint: disable=E1101 |
| 12 raise Exception('urls must be fully qualified: %s' % url) | 12 raise Exception('urls must be fully qualified: %s' % url) |
| 13 self.interactions = 'scroll' | 13 self.interactions = 'scroll' |
| 14 self.credentials = None | 14 self.credentials = None |
| 15 self.is_gmail = False | 15 self.is_gmail = False |
| 16 self.wait_time_after_navigate = 2 | 16 self.wait_time_after_navigate = 2 |
| 17 self.scroll_is_infinite = False | 17 self.scroll_is_infinite = False |
| 18 | 18 |
| 19 if attributes: | 19 if attributes: |
| 20 for k, v in attributes.iteritems(): | 20 for k, v in attributes.iteritems(): |
| 21 setattr(self, k, v) | 21 setattr(self, k, v) |
| 22 | 22 |
| 23 def __str__(self): | 23 def __str__(self): |
| 24 return self.url | 24 return self.url |
| 25 | 25 |
| 26 class PageSet(object): | 26 class PageSet(object): |
| 27 def __init__(self, description='', file_path=''): | 27 def __init__(self, description='', archive_path='', file_path=''): |
| 28 self.description = description | 28 self.description = description |
| 29 self.archive_path = archive_path |
| 29 self.file_path = file_path | 30 self.file_path = file_path |
| 30 self.pages = [] | 31 self.pages = [] |
| 31 | 32 |
| 32 @classmethod | 33 @classmethod |
| 33 def FromFile(cls, file_path): | 34 def FromFile(cls, file_path): |
| 34 with open(file_path, 'r') as f: | 35 with open(file_path, 'r') as f: |
| 35 contents = f.read() | 36 contents = f.read() |
| 36 data = json.loads(contents) | 37 data = json.loads(contents) |
| 37 return cls.FromDict(data, file_path) | 38 return cls.FromDict(data, file_path) |
| 38 | 39 |
| 39 @classmethod | 40 @classmethod |
| 40 def FromDict(cls, data, file_path=''): | 41 def FromDict(cls, data, file_path=''): |
| 41 page_set = cls(data['description'], file_path) | 42 page_set = cls(data['description'], data['archive_path'], file_path) |
| 42 for page_attributes in data['pages']: | 43 for page_attributes in data['pages']: |
| 43 url = page_attributes.pop('url') | 44 url = page_attributes.pop('url') |
| 44 page = Page(url, page_attributes) | 45 page = Page(url, page_attributes) |
| 45 page_set.pages.append(page) | 46 page_set.pages.append(page) |
| 46 return page_set | 47 return page_set |
| 47 | 48 |
| 48 def __iter__(self): | 49 def __iter__(self): |
| 49 return self.pages.__iter__() | 50 return self.pages.__iter__() |
| OLD | NEW |