Esempio n. 1
0
    def colon_notation(self):
        import brownie.itools
        module = import_string('brownie:itools')
        Assert(module).is_(brownie.itools)

        func = import_string('brownie.itools:chain')
        Assert(func).is_(brownie.itools.chain)
Esempio n. 2
0
 def invalid_name(self):
     cases = [('brownie:itools.chain', 'itools.chain'),
              ('brownie-itools:chain', 'brownie-itools')]
     for test, invalid_identifier in cases:
         with Assert.raises(ValueError) as exc:
             import_string(test)
         Assert(invalid_identifier).in_(exc.args[0])
Esempio n. 3
0
def main(tests=sys.argv[1:]):
    prefix = 'brownie.tests.'
    if not tests:
        import_string(prefix +
                      'all').run(reporter=FancyReporter(style='native'))
    for tests in (import_string(prefix + test + '.tests') for test in tests):
        tests.run(reporter=FancyReporter(style='native'))
Esempio n. 4
0
    def colon_notation(self):
        import brownie.itools
        module = import_string('brownie:itools')
        Assert(module).is_(brownie.itools)

        func = import_string('brownie.itools:chain')
        Assert(func).is_(brownie.itools.chain)
Esempio n. 5
0
def main(tests=sys.argv[1:]):
    prefix = 'brownie.tests.'
    if not tests:
        import_string(prefix + 'all').run(
            reporter=FancyReporter(style='native')
        )
    for tests in (import_string(prefix + test + '.tests') for test in tests):
        tests.run(reporter=FancyReporter(style='native'))
Esempio n. 6
0
 def invalid_name(self):
     cases = [
         ('brownie:itools.chain', 'itools.chain'),
         ('brownie-itools:chain', 'brownie-itools')
     ]
     for test, invalid_identifier in cases:
         with Assert.raises(ValueError) as exc:
             import_string(test)
         Assert(invalid_identifier).in_(exc.args[0])
Esempio n. 7
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     try:
         return import_string("pyvisdk.mo.{}.{}".format(
             camel_to_under(class_name), class_name))
     except ImportError:
         raise ValueError(class_name)
Esempio n. 8
0
File: config.py Progetto: dag/detest
 def getobject(self, section, option):
     strings = self.get(section, option)
     for string in strings.split():
         try:
             return importing.import_string(string)
         except ImportError:
             continue
     raise ImportError(strings)
Esempio n. 9
0
def change_version_in_setup_py():
    from brownie.importing import import_string
    long_version = import_string("{}.__version__".format(get_name())).__version__
    short_version = shorten_version(long_version)
    with open("setup.py") as fd:
        setup_py = fd.read()
    with open("setup.py", "w") as fd:
        fd.write(setup_py.replace(long_version, short_version))
Esempio n. 10
0
    def _create_mo_obj(self, class_name, obj_content, parent):
        mo_f = import_string('pyvisdk.mo.%s.%s' % (camel_to_under(obj_content.obj._type), obj_content.obj._type))
        rv = mo_f(self, ref=obj_content.obj)

        # now, run through the propSet
        #if hasattr(obj_content, "propSet"):
        #    for prop in obj_content.propSet:
        #        # for each prop of the new object, create any data/managed objects
        #        setattr(rv, prop.name, self._parse_object_content(prop.val, parent=rv))
        return rv
Esempio n. 11
0
    def _create_do_obj(self, class_name, obj_content, parent):
        mod_name = 'pyvisdk.do.%s' % camel_to_under(class_name)
        do = import_string('%s.%s' % (mod_name, class_name))

        kwargs = {}
        for attr_name in filter(lambda x: not x.startswith('_'), dir(obj_content)):
            attr_data = getattr(obj_content, attr_name)
            kwargs[attr_name] = self._parse_object_content(attr_data, parent=do)

        rv = do(self, **kwargs)
        return rv
Esempio n. 12
0
    def _create_mo_obj(self, class_name, obj_content, parent):
        mo_f = import_string(
            'pyvisdk.mo.%s.%s' %
            (camel_to_under(obj_content.obj._type), obj_content.obj._type))
        rv = mo_f(self, ref=obj_content.obj)

        # now, run through the propSet
        #if hasattr(obj_content, "propSet"):
        #    for prop in obj_content.propSet:
        #        # for each prop of the new object, create any data/managed objects
        #        setattr(rv, prop.name, self._parse_object_content(prop.val, parent=rv))
        return rv
Esempio n. 13
0
    def _create_do_obj(self, class_name, obj_content, parent):
        mod_name = 'pyvisdk.do.%s' % camel_to_under(class_name)
        do = import_string('%s.%s' % (mod_name, class_name))

        kwargs = {}
        for attr_name in filter(lambda x: not x.startswith('_'),
                                dir(obj_content)):
            attr_data = eval('obj_content.%s' % attr_name)
            kwargs[attr_name] = self._parse_object_content(attr_data,
                                                           parent=do)

        rv = do(self, **kwargs)
        return rv
Esempio n. 14
0
def _get_platform_specific_storagemodel_class():
    # do platform-specific magic here.
    from .base import StorageModel as PlatformStorageModel  # helps IDEs
    from brownie.importing import import_string
    plat = get_platform_name()
    platform_module_string = "{}.{}".format(__name__, plat)
    platform_module = import_string(platform_module_string)
    try:
        PlatformStorageModel = getattr(platform_module, "{}StorageModel".format(plat.capitalize()))
    except AttributeError:
        msg = "Failed to import platform-specific storage model"
        logger.exception(msg)
        raise chain(ImportError(msg))
    return PlatformStorageModel
Esempio n. 15
0
def _get_platform_specific_mountmanager_class():
    from .base import MountManager as PlatformMountManager
    from brownie.importing import import_string
    plat = get_platform_string().split('-')[0]
    platform_module_string = "{}.{}".format(__name__, plat)
    platform_module = import_string(platform_module_string)
    try:
        PlatformMountManager = getattr(
            platform_module, "{}MountManager".format(plat.capitalize()))
    except AttributeError:
        msg = "Failed to import platform-specific mount manager"
        logger.exception(msg)
        raise chain(ImportError(msg))
    return PlatformMountManager
Esempio n. 16
0
 def import_object(self):
     from brownie.itools import chain
     func = import_string('brownie.itools.chain')
     Assert(func).is_(chain)
Esempio n. 17
0
def import_handler(name):
    from pyvisdk.utils import camel_to_under
    from brownie.importing import import_string
    return import_string('{}.ha_cli_handler_{}.{}'.format(__name__, camel_to_under(name), name))
Esempio n. 18
0
def import_handler(name):
    from pyvisdk.utils import camel_to_under
    from brownie.importing import import_string
    return import_string('{}.ha_cli_handler_{}.{}'.format(
        __name__, camel_to_under(name), name))
Esempio n. 19
0
 def by_name(self):
     import __main__
     module = import_string('__main__')
     Assert(module).is_(__main__)
Esempio n. 20
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     try:
         return import_string("pyvisdk.mo.{}.{}".format(camel_to_under(class_name), class_name))
     except ImportError:
         raise ValueError(class_name)
Esempio n. 21
0
 def import_non_existing_module(self):
     with Assert.raises(ImportError):
         import_string('foobar')
Esempio n. 22
0
 def import_object(self):
     from brownie.itools import chain
     func = import_string('brownie.itools.chain')
     Assert(func).is_(chain)
Esempio n. 23
0
def import_string(name):
    return importing.import_string(str(name))
Esempio n. 24
0
    def _parse_object_content(self, obj_content, parent=None):
        rv = None
        class_name = obj_content.__class__.__name__
        class_name_upper = class_name[0].upper() + class_name[1:]
        if isinstance(obj_content, list):
            rv = []
            for obj in obj_content:
                rv.append(self._parse_object_content(obj, parent))

        elif type(obj_content) == types.NoneType:
            return obj_content

        elif issubclass(obj_content.__class__, BaseEntity):
            rv = obj_content

        elif class_name == 'ObjectContent':
            # create the managed object
            if not parent:
                rv = self._create_mo_obj(class_name, obj_content, parent)
            else:
                rv = []
                # now, run through the propSet
                if hasattr(obj_content, "propSet"):
                    for prop in obj_content.propSet:
                        rv.append(self._parse_object_content(prop.val))
                if len(rv) == 1:
                    rv = rv[0]

        elif class_name == "ManagedObjectReference":
            # managed object reference is too generic, so we get to the real type
            mo_f = import_string('pyvisdk.mo.%s.%s' % (camel_to_under(obj_content._type), obj_content._type))
            rv = mo_f(self, ref=obj_content)

        elif class_name in DataObjectTypes:
            rv = self._create_do_obj(class_name, obj_content, parent)

        elif class_name == 'Text':
            # obj_context is instance of suds.sax.text.Text which is a subclass of unicode
            # we need to return the text in proper encoding
            rv = str(obj_content.encode('UTF-8'))

        elif class_name in ['long', 'bool', 'int', 'datetime', 'str']:
            return obj_content

        elif "ArrayOf" in class_name:
            rv = []
            _type = class_name[7:]
            if not hasattr(obj_content, _type):
                _type = _type.lower()
            _list = getattr(obj_content, _type)
            for obj in _list:
                rv.append(self._parse_object_content(obj, parent))

        elif hasattr(obj_content, 'value') and hasattr(obj_content, '_type'):
            name = obj_content._type
            mod_name = 'pyvisdk.mo.%s' % camel_to_under(name)
            mo = import_string('%s.%s' % (mod_name, name))
            rv = mo(self, ref=obj_content)

        # TODO: ArrayOf....  ArrayOfManagedObjectReference ArrayOfAlarmState ArrayOfString ArrayOfInt ArrayOfPermission
        # TODO: val datetime datastore  entity host vm key

        elif class_name_upper in DataObjectTypes:
            rv = self._create_do_obj(class_name_upper, obj_content, parent)

        #elif class_name_upper in ManagedObjectTypes:
        #    rv = self._create_mo_obj(class_name_upper, obj_content, parent)

        else:
            log.warning("Unknown content type: %s" % class_name)
            rv = obj_content

        return rv
Esempio n. 25
0
 def by_path(self):
     import brownie.itools
     module = import_string('brownie.itools')
     Assert(module).is_(brownie.itools)
Esempio n. 26
0
    def _parse_object_content(self, obj_content, parent=None):
        rv = None
        class_name = obj_content.__class__.__name__
        class_name_upper = class_name[0].upper() + class_name[1:]
        if isinstance(obj_content, list):
            rv = []
            for obj in obj_content:
                rv.append(self._parse_object_content(obj, parent))

        elif type(obj_content) == types.NoneType:
            return obj_content

        elif issubclass(obj_content.__class__, BaseEntity):
            rv = obj_content

        elif class_name == 'ObjectContent':
            # create the managed object
            if not parent:
                rv = self._create_mo_obj(class_name, obj_content, parent)
            else:
                rv = []
                # now, run through the propSet
                if hasattr(obj_content, "propSet"):
                    for prop in obj_content.propSet:
                        rv.append(self._parse_object_content(prop.val))
                if len(rv) == 1:
                    rv = rv[0]

        elif class_name == "ManagedObjectReference":
            # managed object reference is too generic, so we get to the real type
            mo_f = import_string(
                'pyvisdk.mo.%s.%s' %
                (camel_to_under(obj_content._type), obj_content._type))
            rv = mo_f(self, ref=obj_content)

        elif class_name in DataObjectTypes:
            rv = self._create_do_obj(class_name, obj_content, parent)

        elif class_name == 'Text':
            # obj_context is instance of suds.sax.text.Text which is a subclass of unicode
            # we need to return the text in proper encoding
            rv = str(obj_content.encode('UTF-8'))

        elif class_name in ['long', 'bool', 'int', 'datetime', 'str']:
            return obj_content

        elif "ArrayOf" in class_name:
            rv = []
            _type = class_name[7:]
            if not hasattr(obj_content, _type):
                _type = _type.lower()
            _list = getattr(obj_content, _type)
            for obj in _list:
                rv.append(self._parse_object_content(obj, parent))

        elif hasattr(obj_content, 'value') and hasattr(obj_content, '_type'):
            name = obj_content._type
            mod_name = 'pyvisdk.mo.%s' % camel_to_under(name)
            mo = import_string('%s.%s' % (mod_name, name))
            rv = mo(self, ref=obj_content)

        # TODO: ArrayOf....  ArrayOfManagedObjectReference ArrayOfAlarmState ArrayOfString ArrayOfInt ArrayOfPermission
        # TODO: val datetime datastore  entity host vm key

        elif class_name_upper in DataObjectTypes:
            rv = self._create_do_obj(class_name_upper, obj_content, parent)

        #elif class_name_upper in ManagedObjectTypes:
        #    rv = self._create_mo_obj(class_name_upper, obj_content, parent)

        else:
            log.warning("Unknown content type: %s" % class_name)
            rv = obj_content

        return rv
Esempio n. 27
0
 def import_non_existing_module(self):
     with Assert.raises(ImportError):
         import_string('foobar')
Esempio n. 28
0
def get_c_api_module():
    from brownie.importing import import_string
    from os import name
    from mock import Mock
    is_windows = name == "nt"
    return import_string("infi.eventlog.c_api" if is_windows else "infi.eventlog.c_api.mock")
Esempio n. 29
0
 def _getManagedObjectType(self, class_name):
     # inspired by pyvisdk.vim
     return import_string("pyvisdk.mo.{}.{}".format(
         camel_to_under(class_name), class_name))
Esempio n. 30
0
def has_event(event):
    if isinstance(event, basestring):
        event = import_string(event)

    return has_item(IsEventOfType(event))
Esempio n. 31
0
 def by_name(self):
     import __main__
     module = import_string('__main__')
     Assert(module).is_(__main__)
Esempio n. 32
0
 def by_path(self):
     import brownie.itools
     module = import_string('brownie.itools')
     Assert(module).is_(brownie.itools)