Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/common/extensions/docs/server2/app_yaml_helper.py

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: epic rebase Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 4
5 import logging 5 import logging
6 6
7 _APP_YAML_CONTAINER = ''' 7 _APP_YAML_CONTAINER = '''
8 application: chrome-apps-doc 8 application: chrome-apps-doc
9 version: %s 9 version: %s
10 runtime: python27 10 runtime: python27
11 api_version: 1 11 api_version: 1
12 threadsafe: false 12 threadsafe: false
13 ''' 13 '''
14 14
15 class AppYamlHelper(object): 15 class AppYamlHelper(object):
16 '''Parses the app.yaml file, and is able to step back in the host file 16 '''Parses the app.yaml file, and is able to step back in the host file
17 system's revision history to find when it changed to some given version. 17 system's revision history to find when it changed to some given version.
18 ''' 18 '''
19 def __init__(self, 19 def __init__(self,
20 app_yaml_path, 20 app_yaml_path,
21 file_system_at_head, 21 file_system_at_head,
22 object_store_creator, 22 object_store_creator,
23 host_file_system_creator, 23 host_file_system_creator):
24 branch):
25 self._app_yaml_path = app_yaml_path 24 self._app_yaml_path = app_yaml_path
26 self._file_system_at_head = file_system_at_head 25 self._file_system_at_head = file_system_at_head
27 self._store = object_store_creator.Create( 26 self._store = object_store_creator.Create(
28 AppYamlHelper, 27 AppYamlHelper,
29 category=file_system_at_head.GetIdentity(), 28 category=file_system_at_head.GetIdentity(),
30 start_empty=False) 29 start_empty=False)
31 self._host_file_system_creator = host_file_system_creator 30 self._host_file_system_creator = host_file_system_creator
32 self._branch = branch
33 31
34 @staticmethod 32 @staticmethod
35 def ExtractVersion(app_yaml, key='version'): 33 def ExtractVersion(app_yaml, key='version'):
36 '''Extracts the 'version' key from the contents of an app.yaml file. 34 '''Extracts the 'version' key from the contents of an app.yaml file.
37 Allow overriding the key to parse e.g. the cron file ('target'). 35 Allow overriding the key to parse e.g. the cron file ('target').
38 ''' 36 '''
39 # We could properly parse this using a yaml library but Python doesn't have 37 # We could properly parse this using a yaml library but Python doesn't have
40 # one built in so whatevs. 38 # one built in so whatevs.
41 key_colon = '%s:' % key 39 key_colon = '%s:' % key
42 versions = [line.strip()[len(key_colon):].strip() 40 versions = [line.strip()[len(key_colon):].strip()
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 found = None 111 found = None
114 next_file_system = self._file_system_at_head 112 next_file_system = self._file_system_at_head
115 113
116 while has_greater_app_version(next_file_system): 114 while has_greater_app_version(next_file_system):
117 found = get_app_yaml_revision(next_file_system) 115 found = get_app_yaml_revision(next_file_system)
118 # Back up a revision then find when app.yaml was last updated before then. 116 # Back up a revision then find when app.yaml was last updated before then.
119 if found == 0: 117 if found == 0:
120 logging.warning('All revisions are greater than %s' % app_version) 118 logging.warning('All revisions are greater than %s' % app_version)
121 return 0 119 return 0
122 next_file_system = self._host_file_system_creator.Create( 120 next_file_system = self._host_file_system_creator.Create(
123 self._branch,
124 revision=found - 1) 121 revision=found - 1)
125 122
126 if found is None: 123 if found is None:
127 raise ValueError('All revisions are less than %s' % app_version) 124 raise ValueError('All revisions are less than %s' % app_version)
128 return found 125 return found
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | chrome/common/extensions/docs/server2/app_yaml_helper_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698