Fix small typos and remove unused code

Change-Id: I4d07b285b781e99d5a233f1525b136e7e857b92f
This commit is contained in:
Darja Malyavkina 2016-09-28 18:06:46 +03:00
parent 5cf1030ca8
commit cb049588f8
7 changed files with 15 additions and 131 deletions

View File

@ -1,35 +0,0 @@
# Copyright 2012 OpenStack Foundation
# 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.
"""
Base utilities to build API operation managers and objects on top of.
DEPRECATED post v.0.12.0. Use 'glareclient.openstack.common.apiclient.base'
instead of this module."
"""
import warnings
from glareclient.openstack.common.apiclient import base
warnings.warn("The 'glareclient.common.base' module is deprecated post "
"v.0.12.0. Use 'glareclient.openstack.common.apiclient.base' "
"instead of this one.", DeprecationWarning)
getid = base.getid
Manager = base.ManagerWithFind
Resource = base.Resource

View File

@ -19,7 +19,7 @@ import six
class _ProgressBarBase(object): class _ProgressBarBase(object):
"""A progress bar provider for a wrapped obect. """A progress bar provider for a wrapped object.
Base abstract class used by specific class wrapper to show Base abstract class used by specific class wrapper to show
a progress bar when the wrapped object are consumed. a progress bar when the wrapped object are consumed.

View File

@ -18,9 +18,7 @@ from __future__ import print_function
import errno import errno
import hashlib import hashlib
import os import os
import re
import six import six
import six.moves.urllib.parse as urlparse
import sys import sys
if os.name == 'nt': if os.name == 'nt':
@ -34,16 +32,6 @@ from oslo_utils import importutils
SENSITIVE_HEADERS = ('X-Auth-Token', ) SENSITIVE_HEADERS = ('X-Auth-Token', )
# Decorator for cli-args
def arg(*args, **kwargs):
def _decorator(func):
# Because of the semantics of decorator composition if we just append
# to the options list positional options will appear to be backwards.
func.__dict__.setdefault('arguments', []).insert(0, (args, kwargs))
return func
return _decorator
def env(*vars, **kwargs): def env(*vars, **kwargs):
"""Search for the first defined of possibly many env vars. """Search for the first defined of possibly many env vars.
@ -66,36 +54,10 @@ def import_versioned_module(version, submodule=None):
def exit(msg='', exit_code=1): def exit(msg='', exit_code=1):
if msg: if msg:
print_err(msg) print(encodeutils.safe_decode(msg), file=sys.stderr)
sys.exit(exit_code) sys.exit(exit_code)
def print_err(msg):
print(encodeutils.safe_decode(msg), file=sys.stderr)
def strip_version(endpoint):
"""Strip version from the last component of endpoint if present."""
# NOTE(flaper87): This shouldn't be necessary if
# we make endpoint the first argument. However, we
# can't do that just yet because we need to keep
# backwards compatibility.
if not isinstance(endpoint, six.string_types):
raise ValueError("Expected endpoint")
version = None
# Get rid of trailing '/' if present
endpoint = endpoint.rstrip('/')
url_parts = urlparse.urlparse(endpoint)
(scheme, netloc, path, __, __, __) = url_parts
path = path.lstrip('/')
# regex to match 'v1' or 'v2.0' etc
if re.match('v\d+\.?\d*', path):
version = float(path.lstrip('v'))
endpoint = scheme + '://' + netloc
return endpoint, version
def integrity_iter(iter, checksum): def integrity_iter(iter, checksum):
"""Check blob integrity. """Check blob integrity.
@ -114,31 +76,6 @@ def integrity_iter(iter, checksum):
(md5sum, checksum)) (md5sum, checksum))
def safe_header(name, value):
if value is not None and name in SENSITIVE_HEADERS:
h = hashlib.sha1(value)
d = h.hexdigest()
return name, "{SHA1}%s" % d
else:
return name, value
def endpoint_version_from_url(endpoint, default_version=None):
if endpoint:
endpoint, version = strip_version(endpoint)
return endpoint, version or default_version
else:
return None, default_version
def debug_enabled(argv):
if bool(env('GLARECLIENT_DEBUG')) is True:
return True
if '--debug' in argv or '-d' in argv:
return True
return False
class IterableWithLength(object): class IterableWithLength(object):
def __init__(self, iterable, length): def __init__(self, iterable, length):
self.iterable = iterable self.iterable = iterable

View File

@ -96,7 +96,7 @@ class ShowArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser
@ -170,12 +170,12 @@ class UpdateArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
parser.add_argument( parser.add_argument(
'--name', '--name',
metavar='<NAME>', metavar='<NAME>',
help='Name of the artifact', help='Name of the artifact.',
), ),
parser.add_argument( parser.add_argument(
'--remove-property', '--remove-property',
@ -228,7 +228,7 @@ class DeleteArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser
@ -254,7 +254,7 @@ class ActivateArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser
@ -280,7 +280,7 @@ class DeactivateArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser
@ -306,7 +306,7 @@ class ReactivateArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser
@ -319,7 +319,7 @@ class ReactivateArtifact(command.ShowOne):
class PublishArtifact(command.ShowOne): class PublishArtifact(command.ShowOne):
"""Publish the artifact""" """Publish the artifact"""
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(PublishArtifact, self).get_parser(prog_name) parser = super(PublishArtifact, self).get_parser(prog_name)
@ -332,7 +332,7 @@ class PublishArtifact(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
return parser return parser

View File

@ -50,11 +50,11 @@ class UploadBlob(command.ShowOne):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
parser.add_argument( parser.add_argument(
'--file', '--file',
metavar='<TYPE_NAME>', metavar='<FILE_PATH>',
help='Local file that contains data to be uploaded.', help='Local file that contains data to be uploaded.',
) )
parser.add_argument( parser.add_argument(
@ -109,7 +109,7 @@ class DownloadBlob(command.Command):
parser.add_argument( parser.add_argument(
'id', 'id',
metavar='<ID>', metavar='<ID>',
help='ID of the artifact to update', help='ID of the artifact to update.',
) )
parser.add_argument( parser.add_argument(
'--progress', '--progress',

View File

@ -15,7 +15,6 @@
import mock import mock
from oslo_utils import encodeutils
import six import six
import testtools import testtools
@ -64,20 +63,3 @@ class TestUtils(testtools.TestCase):
i = utils.IterableWithLength(data, 10) i = utils.IterableWithLength(data, 10)
self.assertRaises(IOError, _iterate, i) self.assertRaises(IOError, _iterate, i)
data.close.assert_called_with() data.close.assert_called_with()
def test_safe_header(self):
self.assertEqual(('somekey', 'somevalue'),
utils.safe_header('somekey', 'somevalue'))
self.assertEqual(('somekey', None),
utils.safe_header('somekey', None))
for sensitive_header in utils.SENSITIVE_HEADERS:
(name, value) = utils.safe_header(
sensitive_header,
encodeutils.safe_encode('somestring'))
self.assertEqual(sensitive_header, name)
self.assertTrue(value.startswith("{SHA1}"))
(name, value) = utils.safe_header(sensitive_header, None)
self.assertEqual(sensitive_header, name)
self.assertIsNone(value)

View File

@ -27,7 +27,7 @@ class Controller(object):
self.sort_dir_values = ('asc', 'desc') self.sort_dir_values = ('asc', 'desc')
def _check_type_name(self, type_name): def _check_type_name(self, type_name):
"""Check that type name and type versions were specified""" """Check that type name and type versions were specified."""
type_name = type_name or self.type_name type_name = type_name or self.type_name
if type_name is None: if type_name is None:
msg = "Type name must be specified" msg = "Type name must be specified"