1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 from caching_file_system
import CachingFileSystem
10 from empty_dir_file_system
import EmptyDirFileSystem
11 from environment
import IsTest
12 from extensions_paths
import LOCAL_GCS_DIR
, LOCAL_GCS_DEBUG_CONF
13 from gcs_file_system
import CloudStorageFileSystem
14 from local_file_system
import LocalFileSystem
15 from path_util
import ToDirectory
18 class CloudStorageFileSystemProvider(object):
19 '''Provides CloudStorageFileSystem bound to a GCS bucket.
21 def __init__(self
, object_store_creator
):
22 self
._object
_store
_creator
= object_store_creator
24 def Create(self
, bucket
):
25 '''Creates a CloudStorageFileSystemProvider.
27 |bucket| is the name of GCS bucket, eg devtools-docs. It is expected
28 that this bucket has Read permission for this app in its ACLs.
30 Optional configuration can be set in a local_debug/gcs_debug.conf file:
31 use_local_fs=True|False
32 remote_bucket_prefix=<prefix>
34 If running in Preview mode or in Development mode with use_local_fs set to
35 True, buckets and files are looked for inside the local_debug folder instead
36 of in the real GCS server.
39 return EmptyDirFileSystem()
41 debug_bucket_prefix
= None
43 if os
.path
.exists(LOCAL_GCS_DEBUG_CONF
):
44 with
open(LOCAL_GCS_DEBUG_CONF
, "r") as token_file
:
45 properties
= dict(line
.strip().split('=', 1) for line
in token_file
)
46 use_local_fs
= properties
.get('use_local_fs', 'False')=='True'
47 debug_bucket_prefix
= properties
.get('remote_bucket_prefix', None)
48 logging
.debug('gcs: prefixing all bucket names with %s' %
52 return LocalFileSystem(ToDirectory(os
.path
.join(LOCAL_GCS_DIR
, bucket
)))
54 if debug_bucket_prefix
:
55 bucket
= debug_bucket_prefix
+ bucket
57 return CachingFileSystem(CloudStorageFileSystem(bucket
),
58 self
._object
_store
_creator
)
62 class EmptyImpl(object):
63 def Create(self
, bucket
):
64 return EmptyDirFileSystem()