Sync units module from olso
There are lots of numeric expressions across some projects, such as 1024*1024 , 1024**3, 1000, 1000000 etc. This patch adds binary and decimal unit constants. Replacing nummeric experssions with these constants makes code more readable. Change-Id: I45fb5a10009f22b1eedb07b3e52f1ce40403b068
This commit is contained in:
parent
0c1f60d06b
commit
127fc7505c
40
glance/openstack/common/units.py
Normal file
40
glance/openstack/common/units.py
Normal file
@ -0,0 +1,40 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013 IBM Corp
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Unit constants
|
||||
"""
|
||||
|
||||
#Binary unit constants.
|
||||
Ki = 1024
|
||||
Mi = 1024 ** 2
|
||||
Gi = 1024 ** 3
|
||||
Ti = 1024 ** 4
|
||||
Pi = 1024 ** 5
|
||||
Ei = 1024 ** 6
|
||||
Zi = 1024 ** 7
|
||||
Yi = 1024 ** 8
|
||||
|
||||
#Decimal unit constants.
|
||||
k = 1000
|
||||
M = 1000 ** 2
|
||||
G = 1000 ** 3
|
||||
T = 1000 ** 4
|
||||
P = 1000 ** 5
|
||||
E = 1000 ** 6
|
||||
Z = 1000 ** 7
|
||||
Y = 1000 ** 8
|
@ -13,6 +13,7 @@ module=notifier
|
||||
module=policy
|
||||
module=strutils
|
||||
module=timeutils
|
||||
module=units
|
||||
module=uuidutils
|
||||
|
||||
# The base module to hold the copy of openstack.common
|
||||
|
Loading…
Reference in New Issue
Block a user