from copy import deepcopy from itertools import product from sys import exit from pythonforandroid.logger import (info, warning, error) from pythonforandroid.recipe import Recipe from pythonforandroid.bootstrap import Bootstrap class RecipeOrder(dict): def __init__(self, ctx): self.ctx = ctx def conflicts(self, name): for name in self.keys(): try: recipe = Recipe.get_recipe(name, self.ctx) conflicts = recipe.conflicts except IOError: conflicts = [] if any([c in self for c in conflicts]): return True return False def recursively_collect_orders(name, ctx, orders=[]): '''For each possible recipe ordering, try to add the new recipe name to that order. Recursively do the same thing with all the dependencies of each recipe. ''' try: recipe = Recipe.get_recipe(name, ctx) if recipe.depends is None: dependencies = [] else: # make all dependencies into lists so that product will work dependencies = [([dependency] if not isinstance( dependency, (list, tuple)) else dependency) for dependency in recipe.depends] if recipe.conflicts is None: conflicts = [] else: conflicts = recipe.conflicts except IOError: # The recipe does not exist, so we assume it can be installed # via pip with no extra dependencies dependencies = [] conflicts = [] new_orders = [] # for each existing recipe order, see if we can add the new recipe name for order in orders: if name in order: new_orders.append(deepcopy(order)) continue if order.conflicts(name): continue if any([conflict in order