Esempio n. 1
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            recipe_file = join(recipes_dir, name, '__init__.py')
            if exists(recipe_file):
                break
            recipe_file = None

        if not recipe_file:
            raise IOError('Recipe does not exist: {}'.format(name))

        mod = import_recipe('pythonforandroid.recipes.{}'.format(name),
                            recipe_file)
        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe = mod.recipe
        recipe.ctx = ctx
        cls.recipes[name] = recipe
        return recipe
Esempio n. 2
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            recipe_file = join(recipes_dir, name, '__init__.py')
            if exists(recipe_file):
                break
            recipe_file = None

        if not recipe_file:
            raise IOError('Recipe folder does not exist')

        mod = import_recipe('pythonforandroid.recipes.{}'.format(name), recipe_file)
        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe = mod.recipe
        recipe.recipe_dir = dirname(recipe_file)
        recipe.ctx = ctx
        cls.recipes[name] = recipe
        return recipe
Esempio n. 3
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        name = name.lower()
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            if not exists(recipes_dir):
                continue
            # Find matching folder (may differ in case):
            for subfolder in listdir(recipes_dir):
                if subfolder.lower() == name:
                    recipe_file = join(recipes_dir, subfolder, '__init__.py')
                    if exists(recipe_file):
                        name = subfolder  # adapt to actual spelling
                        break
                    recipe_file = None
            if recipe_file is not None:
                break

        if not recipe_file:
            raise ValueError('Recipe does not exist: {}'.format(name))

        mod = import_recipe('pythonforandroid.recipes.{}'.format(name), recipe_file)
        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe = mod.recipe
        recipe.ctx = ctx
        cls.recipes[name.lower()] = recipe
        return recipe
Esempio n. 4
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        name = name.lower()
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            if not exists(recipes_dir):
                continue
            # Find matching folder (may differ in case):
            for subfolder in listdir(recipes_dir):
                if subfolder.lower() == name:
                    recipe_file = join(recipes_dir, subfolder, '__init__.py')
                    if exists(recipe_file):
                        name = subfolder  # adapt to actual spelling
                        break
                    recipe_file = None
            if recipe_file is not None:
                break

        if not recipe_file:
            raise ValueError('Recipe does not exist: {}'.format(name))

        mod = import_recipe('pythonforandroid.recipes.{}'.format(name), recipe_file)
        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe = mod.recipe
        recipe.ctx = ctx
        cls.recipes[name.lower()] = recipe
        return recipe
Esempio n. 5
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            recipe_file = join(recipes_dir, name, '__init__.py')
            if exists(recipe_file):
                break
            recipe_file = None

        # Try to get it from an extension point first because
        # these are explicitly installed by the user
        pip_recipe = cls.get_pip_installed_recipe(name, ctx)
        if pip_recipe:
            recipe, recipe_file = pip_recipe
            recipe.from_pip = True
        elif recipe_file:
            mod = import_recipe('pythonforandroid.recipes.{}'.format(name), recipe_file)
            recipe = mod.recipe
        else:
            raise IOError('Recipe does not exist: {}'.format(name))

        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe.recipe_dir = dirname(recipe_file)
        recipe.ctx = ctx
        cls.recipes[name] = recipe
        return recipe
Esempio n. 6
0
    def get_recipe(cls, name, ctx):
        '''Returns the Recipe with the given name, if it exists.'''
        if not hasattr(cls, "recipes"):
            cls.recipes = {}
        if name in cls.recipes:
            return cls.recipes[name]

        recipe_file = None
        for recipes_dir in cls.recipe_dirs(ctx):
            recipe_file = join(recipes_dir, name, '__init__.py')
            if exists(recipe_file):
                break
            recipe_file = None

        # Try to get it from an extension point first because
        # these are explicitly installed by the user
        pip_recipe = cls.get_pip_installed_recipe(name, ctx)
        if pip_recipe:
            recipe, recipe_file = pip_recipe
            recipe.from_pip = True
        elif recipe_file:
            mod = import_recipe('pythonforandroid.recipes.{}'.format(name), recipe_file)
            recipe = mod.recipe
        else:
            raise IOError('Recipe does not exist: {}'.format(name))

        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        recipe.recipe_dir = dirname(recipe_file)
        recipe.ctx = ctx
        cls.recipes[name] = recipe
        return recipe
Esempio n. 7
0
    def get_bootstrap(cls, name, ctx):
        '''Returns an instance of a bootstrap with the given name.

        This is the only way you should access a bootstrap class, as
        it sets the bootstrap directory correctly.
        '''
        if name is None:
            return None
        if not hasattr(cls, 'bootstraps'):
            cls.bootstraps = {}
        if name in cls.bootstraps:
            return cls.bootstraps[name]
        mod = importlib.import_module('pythonforandroid.bootstraps.{}'
                                      .format(name))
        if len(logger.handlers) > 1:
            logger.removeHandler(logger.handlers[1])
        bootstrap = mod.bootstrap
        bootstrap.bootstrap_dir = join(ctx.root_dir, 'bootstraps', name)
        bootstrap.ctx = ctx
        return bootstrap