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 | 4 |
5 import os | 5 import os |
6 | 6 |
7 def _ProcessFileData(data, path): | 7 def _ProcessFileData(data, path): |
8 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']: | 8 if os.path.splitext(path)[-1] not in ['.js', '.html', '.json']: |
9 return data | 9 return data |
10 try: | 10 try: |
11 return unicode(data, 'utf-8') | 11 return unicode(data, 'utf-8') |
12 except: | 12 except: |
13 return unicode(data, 'latin-1') | 13 return unicode(data, 'latin-1') |
14 | 14 |
15 class FileSystem(object): | 15 class FileSystem(object): |
16 """A FileSystem interface that can read files and directories. | 16 """A FileSystem interface that can read files and directories. |
17 """ | 17 """ |
18 class StatInfo(object): | 18 class StatInfo(object): |
19 """The result of calling Stat on a FileSystem. | 19 """The result of calling Stat on a FileSystem. |
20 """ | 20 """ |
21 def __init__(self, version): | 21 def __init__(self, version, child_versions): |
22 self.version = version | 22 self.version = version |
23 self.child_versions = child_versions | |
23 | 24 |
24 def Read(self, paths, binary=False): | 25 def Read(self, paths, binary=False): |
25 """Reads each file in paths and returns a dictionary mapping the path to the | 26 """Reads each file in paths and returns a dictionary mapping the path to the |
26 contents. If a path in paths ends with a '/', it is assumed to be a | 27 contents. If a path in paths ends with a '/', it is assumed to be a |
27 directory, and a list of files in the directory is mapped to the path. | 28 directory, and a list of files in the directory is mapped to the path. |
28 | 29 |
29 If binary=False, the contents of each file will be unicode parsed as utf-8, | 30 If binary=False, the contents of each file will be unicode parsed as utf-8, |
30 and failing that as latin-1 (some extension docs use latin-1). If | 31 and failing that as latin-1 (some extension docs use latin-1). If |
31 binary=True then the contents will be a str. | 32 binary=True then the contents will be a str. |
32 """ | 33 """ |
33 raise NotImplementedError() | 34 raise NotImplementedError() |
34 | 35 |
35 def ReadSingle(self, path): | 36 def ReadSingle(self, path): |
36 """Reads a single file from the FileSystem. | 37 """Reads a single file from the FileSystem. |
37 """ | 38 """ |
38 return self.Read([path]).Get()[path] | 39 return self.Read([path]).Get()[path] |
39 | 40 |
40 def Stat(self, path): | 41 def Stat(self, path): |
41 """Gets the version number of |path| if it is a directory, or the parent | 42 """Returns a |StatInfo| object containing the version of the parent |
42 directory if it is a file. | 43 directory if a file is specified, or the directory itself if a directory is |
44 specified. The |StatInfo| object also has the versions of all the children | |
45 of the directory. | |
not at google - send to devlin
2012/08/10 06:42:24
This would be a strange interface.
If a file, it
cduvall
2012/08/11 00:15:23
Done.
| |
43 """ | 46 """ |
44 raise NotImplementedError() | 47 raise NotImplementedError() |
OLD | NEW |