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

Side by Side Diff: appengine/components/components/config/fs.py

Issue 2778533002: config: store binary configs (Closed)
Patch Set: addressed comments Created 3 years, 8 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
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """fs.Provider reads configs from the filesystem.""" 5 """fs.Provider reads configs from the filesystem."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 9
10 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
(...skipping 10 matching lines...) Expand all
21 21
22 Some functions are made NDB tasklets because they follow common interface. 22 Some functions are made NDB tasklets because they follow common interface.
23 See api._get_config_provider for context. 23 See api._get_config_provider for context.
24 """ 24 """
25 25
26 def __init__(self, root): 26 def __init__(self, root):
27 assert root 27 assert root
28 self.root = root 28 self.root = root
29 29
30 @ndb.tasklet 30 @ndb.tasklet
31 def get_async(self, config_set, path, **kwargs): 31 def get_async(self, config_set, path, dest_type=None, **kwargs):
32 """Reads a (revision, config) from a file, where revision is always None. 32 """Reads a (revision, config) from a file, where revision is always None.
33 33
34 Kwargs are not used, but reported as warnings. 34 Kwargs are not used, but reported as warnings.
35 """ 35 """
36 assert config_set 36 assert config_set
37 assert path 37 assert path
38 if kwargs: 38 if kwargs:
39 logging.warning( 39 logging.warning(
40 'config: parameters %r are ignored in the filesystem mode', 40 'config: parameters %r are ignored in the filesystem mode',
41 kwargs.keys()) 41 kwargs.keys())
42 filename = os.path.join( 42 filename = os.path.join(
43 self.root, 43 self.root,
44 config_set.replace('/', os.path.sep), 44 config_set.replace('/', os.path.sep),
45 SEPARATOR, 45 SEPARATOR,
46 path.replace('/', os.path.sep)) 46 path.replace('/', os.path.sep))
47 filename = os.path.abspath(filename) 47 filename = os.path.abspath(filename)
48 assert filename.startswith(os.path.abspath(self.root)), filename 48 assert filename.startswith(os.path.abspath(self.root)), filename
49 content = None 49 content = None
50 if os.path.exists(filename): 50 if os.path.exists(filename):
51 with open(filename, 'r') as f: 51 with open(filename, 'r') as f:
52 content = f.read() 52 content = f.read()
53 raise ndb.Return((None, content)) 53 config = common._convert_config(content, dest_type)
54 raise ndb.Return(None, config)
54 55
55 def get_project_ids(self): 56 def get_project_ids(self):
56 # A project_id cannot contain a slash, so recursion is not needed. 57 # A project_id cannot contain a slash, so recursion is not needed.
57 projects_dir = os.path.join(self.root, 'projects') 58 projects_dir = os.path.join(self.root, 'projects')
58 if not os.path.isdir(projects_dir): 59 if not os.path.isdir(projects_dir):
59 return 60 return
60 for pid in os.listdir(projects_dir): 61 for pid in os.listdir(projects_dir):
61 if os.path.isdir(os.path.join(projects_dir, pid)): 62 if os.path.isdir(os.path.join(projects_dir, pid)):
62 yield pid 63 yield pid
63 64
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 """Returns URL of where configs for given config set are stored. 119 """Returns URL of where configs for given config set are stored.
119 120
120 Returns: 121 Returns:
121 Always None for file system. 122 Always None for file system.
122 """ 123 """
123 raise ndb.Return(None) 124 raise ndb.Return(None)
124 125
125 126
126 def get_provider(): # pragma: no cover 127 def get_provider(): # pragma: no cover
127 return Provider(common.CONSTANTS.CONFIG_DIR) 128 return Provider(common.CONSTANTS.CONFIG_DIR)
OLDNEW
« no previous file with comments | « appengine/components/components/config/api_test.py ('k') | appengine/components/components/config/proto/project_config_pb2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698