~shakhat/stackalytics/0.3

« back to all changes in this revision

Viewing changes to stackalytics/openstack/common/importutils.py

  • Committer: Ilya Shakhat
  • Date: 2013-07-10 19:05:47 UTC
  • Revision ID: git-v1:b7f19335f6c6a710d1e8925f8a9675d9e7115741
Implementation of blueprint stackalytics-core

* Data updater is implemented
* Completed implementation of commit processor
* Logging is added into commit processor and runtime storage
* Commit processor is fixed
* Domain-company map is inverted
* Extracted get update count into separate function
* Fixed regex that matches diff statistics (lines inserted, lines deleted and files changed)
* Implemented caching of unknown users
* Replaced dictionaries by sets for pids and branches
* Vcs is responsible for module and branches fields of commit record
* Added release tags support
* Implemented statistics by company
* Added config for releases
* Implemented front-end for companies details
* Implemented front-end for modules details
* Fixed metric switch
* Implemented timeline rendering
* Release selector is fixed
* Chdir is needed after cloning a new repo
* Company details screen is implemented
* Fixed invalid emails processing by Launchpad
* Fixed parsing of 0 files changed case
* Module details screen implemented
* Commit message is cleared and links are inserted
* Engineer details screen is implemented
* Fixed mapping from company to email for subdomains of 3rd level
* Fixed wrong user structure for users not found by LP
* Also coverage for commit processor
* Fixed company matching algorithm
* The company was not matched when user email had more domains than company's one
* Add option to enforce sync with default data
* Default data is added. Old confs removed
* Add *.local into gitignore

Scripts cleanup

Moved from pylibmc to python-memcached

Library pylibmc depends on libmemcached and doesn't work on CentOS (version conflict bw lib requirement and memcached).

Change-Id: I0cc61c6d344ba24442ec954635010b518c0efa95

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 OpenStack Foundation.
 
4
# All Rights Reserved.
 
5
#
 
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
# not use this file except in compliance with the License. You may obtain
 
8
# a copy of the License at
 
9
#
 
10
# http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
# Unless required by applicable law or agreed to in writing, software
 
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
# License for the specific language governing permissions and limitations
 
16
# under the License.
 
17
 
 
18
"""
 
19
Import related utilities and helper functions.
 
20
"""
 
21
 
 
22
import sys
 
23
import traceback
 
24
 
 
25
 
 
26
def import_class(import_str):
 
27
    """Returns a class from a string including module and class."""
 
28
    mod_str, _sep, class_str = import_str.rpartition('.')
 
29
    try:
 
30
        __import__(mod_str)
 
31
        return getattr(sys.modules[mod_str], class_str)
 
32
    except (ValueError, AttributeError):
 
33
        raise ImportError('Class %s cannot be found (%s)' %
 
34
                          (class_str,
 
35
                           traceback.format_exception(*sys.exc_info())))
 
36
 
 
37
 
 
38
def import_object(import_str, *args, **kwargs):
 
39
    """Import a class and return an instance of it."""
 
40
    return import_class(import_str)(*args, **kwargs)
 
41
 
 
42
 
 
43
def import_object_ns(name_space, import_str, *args, **kwargs):
 
44
    """Tries to import object from default namespace.
 
45
 
 
46
Imports a class and return an instance of it, first by trying
 
47
to find the class in a default namespace, then failing back to
 
48
a full path if not found in the default namespace.
 
49
"""
 
50
    import_value = "%s.%s" % (name_space, import_str)
 
51
    try:
 
52
        return import_class(import_value)(*args, **kwargs)
 
53
    except ImportError:
 
54
        return import_class(import_str)(*args, **kwargs)
 
55
 
 
56
 
 
57
def import_module(import_str):
 
58
    """Import a module."""
 
59
    __import__(import_str)
 
60
    return sys.modules[import_str]
 
61
 
 
62
 
 
63
def try_import(import_str, default=None):
 
64
    """Try to import a module and if it fails return default."""
 
65
    try:
 
66
        return import_module(import_str)
 
67
    except ImportError:
 
68
        return default