~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to gozerbot/myimport.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# gozerbot/myimport.py
2
 
#
3
 
#
4
 
 
5
 
""" provide own import function for absolute imports """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
from gozerbot.generic import rlog
10
 
import time
11
 
 
12
 
def my_import(name):
13
 
    """ absolute import """
14
 
    rlog(-1, 'my_import', 'importing %s' % name)
15
 
    try:
16
 
        result = __import__(name)
17
 
    except:
18
 
        rlog(100, 'my_import', 'failed to import %s' % name)
19
 
        time.sleep(1)
20
 
        raise
21
 
    mods = name.split('.')
22
 
    if len(mods) == 1:
23
 
        pass
24
 
    else:
25
 
        # expand module name
26
 
        for mod in mods[1:]:
27
 
            result = getattr(result, mod)
28
 
    return result