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

Side by Side Diff: third_party/gsutil/gslib/util.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 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
(Empty)
1 # Copyright 2010 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """Static data and helper functions."""
16
17 import boto
18 import sys
19
20 # We don't use the oauth2 authentication plugin directly; importing it here
21 # ensures that it's loaded and available by default. Note: we made this static
22 # state instead of Command instance state because the top-level gsutil code
23 # needs to check it.
24 HAVE_OAUTH2 = False
25 try:
26 from oauth2_plugin import oauth2_helper
27 HAVE_OAUTH2 = True
28 except ImportError:
29 pass
30
31 ONE_MB = 1024*1024
32
33 NO_MAX = sys.maxint
34
35 # Binary exponentiation strings.
36 _EXP_STRINGS = [
37 (0, 'B'),
38 (10, 'KB'),
39 (20, 'MB'),
40 (30, 'GB'),
41 (40, 'TB'),
42 (50, 'PB'),
43 ]
44
45
46 # Enum class for specifying listing style.
47 class ListingStyle(object):
48 SHORT = 'SHORT'
49 LONG = 'LONG'
50 LONG_LONG = 'LONG_LONG'
51
52
53 def HasConfiguredCredentials():
54 """Determines if boto credential/config file exists."""
55 config = boto.config
56 has_goog_creds = (config.has_option('Credentials', 'gs_access_key_id') and
57 config.has_option('Credentials', 'gs_secret_access_key'))
58 has_amzn_creds = (config.has_option('Credentials', 'aws_access_key_id') and
59 config.has_option('Credentials', 'aws_secret_access_key'))
60 has_oauth_creds = (HAVE_OAUTH2 and
61 config.has_option('Credentials', 'gs_oauth2_refresh_token'))
62 has_auth_plugins = config.has_option('Plugin', 'plugin_directory')
63 return (has_goog_creds or has_amzn_creds or has_oauth_creds
64 or has_auth_plugins)
65
66
67 def MakeHumanReadable(num):
68 """Generates human readable string for a number.
69
70 Args:
71 num: The number.
72
73 Returns:
74 A string form of the number using size abbreviations (KB, MB, etc.).
75 """
76 i = 0
77 while i+1 < len(_EXP_STRINGS) and num >= (2 ** _EXP_STRINGS[i+1][0]):
78 i += 1
79 rounded_val = round(float(num) / 2 ** _EXP_STRINGS[i][0], 2)
80 return '%s %s' % (rounded_val, _EXP_STRINGS[i][1])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698