Oslo provides a function, to_slug() in strutils that is substantially similar to slugify() provided in utils by python-troveclient. Remove slugify() and use to_slug() instead. Change-Id: I97bc7cfc2c0e7d14e7617037bff431cdc1eee50f Closes-Bug: #1266127 Author: Christian Berendt <berendt@b1-systems.de>
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
#    Copyright 2012 OpenStack Foundation
 | 
						|
#
 | 
						|
#    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.
 | 
						|
 | 
						|
import os
 | 
						|
 | 
						|
 | 
						|
class HookableMixin(object):
 | 
						|
    """Mixin so classes can register and run hooks."""
 | 
						|
    _hooks_map = {}
 | 
						|
 | 
						|
    @classmethod
 | 
						|
    def add_hook(cls, hook_type, hook_func):
 | 
						|
        if hook_type not in cls._hooks_map:
 | 
						|
            cls._hooks_map[hook_type] = []
 | 
						|
 | 
						|
        cls._hooks_map[hook_type].append(hook_func)
 | 
						|
 | 
						|
    @classmethod
 | 
						|
    def run_hooks(cls, hook_type, *args, **kwargs):
 | 
						|
        hook_funcs = cls._hooks_map.get(hook_type) or []
 | 
						|
        for hook_func in hook_funcs:
 | 
						|
            hook_func(*args, **kwargs)
 | 
						|
 | 
						|
 | 
						|
def env(*vars, **kwargs):
 | 
						|
    """Returns environment variables.
 | 
						|
 | 
						|
    Returns the first environment variable set
 | 
						|
    if none are non-empty, defaults to '' or keyword arg default.
 | 
						|
    """
 | 
						|
    for v in vars:
 | 
						|
        value = os.environ.get(v, None)
 | 
						|
        if value:
 | 
						|
            return value
 | 
						|
    return kwargs.get('default', '')
 |