def is_current(self, baker): try: if pickle_abi() != self.abi: return False if baker.config.env_signature() != self.env_signature: return False if not isinstance(self.mtimes, set): return False except AttributeError: return False if not self.mtimes: warn("Cachefile (%s) with no file(s) reference(s) loaded, broken cache generation?"%(self.cachefile)) return False for (fn, oepath, old_mtime) in list(self.mtimes): if oepath is not None: filepath = oelite.path.which(oepath, fn) else: filepath = fn if os.path.exists(filepath): cur_mtime = os.path.getmtime(filepath) else: cur_mtime = None if cur_mtime != old_mtime: return False return True
def grab(url, filename, timeout=120, retry=5, proxy=None, ftpmode=False): print "Grabbing", url def grab_fail_callback(data): # Only print debug here when non fatal retries, debug in other cases # is already printed if (data.exception.errno in retrycodes) and (data.tries != data.retry): print "grabbing retry %d/%d, exception %s"%( data.tries, data.retry, data.exception) try: retrycodes = urlgrabber.grabber.URLGrabberOptions().retrycodes if 12 not in retrycodes: retrycodes.append(12) if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) downloaded_file = urlgrabber.urlgrab( url, filename,timeout=timeout,retry=retry, retrycodes=retrycodes, progress_obj=SimpleProgress(), failure_callback=grab_fail_callback, copy_local=True, proxies=proxy, ftp_disable_epsv=ftpmode) if not downloaded_file: return False except urlgrabber.grabber.URLGrabError as e: warn('URLGrabError %i: %s' % (e.errno, e.strerror)) if os.path.exists(filename): os.unlink(filename) return False return True
def list_recipefiles(self, sort=True): OERECIPES = (self.config["OERECIPES"] or "").split(":") if not OERECIPES: die("OERECIPES not defined") files = [] for f in OERECIPES: if os.path.isdir(f): dirfiles = find_recipoefiles(f) files.append(dirfiles) elif os.path.isfile(f): files.append(f) else: for file in glob.iglob(f): files.append(file) oerecipes = [] for f in files: if f.endswith(".oe"): oerecipes.append(f) else: warn("skipping %s: unknown file extension"%(f)) if sort: oerecipes.sort() return oerecipes
def get_package(self, id=None, recipe=None, name=None, type=None, arch=None): """ Get package from cookbook. Returns package object if arguments match a single package. Returns None if package is not found. Throws MultiplePackages exception if more than one package is found. """ packages = self.get_packages(id=id, recipe=recipe, name=name, type=type, arch=arch) if len(packages) == 1: package = packages[0] elif len(packages) == 0: package = None elif len(packages) > 1: warn("multiple packages found in %s.%s: returning None!" % (self.__class__.__name__, inspect.stack()[0][3])) assert False package = None return package
def get_package(self, id=None, recipe=None, name=None, type=None, arch=None): """ Get package from cookbook. Returns package object if arguments match a single package. Returns None if package is not found. Throws MultiplePackages exception if more than one package is found. """ packages = self.get_packages(id=id, recipe=recipe, name=name, type=type, arch=arch) if len(packages) == 1: package = packages[0] elif len(packages) == 0: package = None elif len(packages) > 1: warn("multiple packages found in %s.%s: returning None!"%( self.__class__.__name__, inspect.stack()[0][3])) assert False package = None return package
def add_recipe(self, recipe): self.dbc.execute( "INSERT INTO recipe " "(file, type, name, version, priority) " "VALUES (?, ?, ?, ?, ?)", (recipe.filename, recipe.type, recipe.name, recipe.version, recipe.priority)) recipe_id = self.dbc.lastrowid recipe.set_id(recipe_id) self.recipes[recipe_id] = recipe task_names = recipe.get_task_names() taskseq = [] for task_name in task_names: task_nostamp = recipe.meta.get_boolean_flag(task_name, "nostamp") taskseq.append((recipe_id, task_name, task_nostamp)) if taskseq: self.dbc.executemany( "INSERT INTO task (recipe, name, nostamp) VALUES (?, ?, ?)", taskseq) for deptype in ("DEPENDS", "RDEPENDS", "FDEPENDS"): recipe_depends = [] for item in (recipe.meta.get(deptype) or "").split(): item = oelite.item.OEliteItem(item, (deptype, recipe.type)) recipe_depends.append((recipe_id, deptype, item.type, item.name, item.version)) for item in (recipe.meta.get("CLASS_"+deptype) or "").split(): item = oelite.item.OEliteItem(item, (deptype, recipe.type)) recipe_depends.append((recipe_id, deptype, item.type, item.name, item.version)) if recipe_depends: self.dbc.executemany( "INSERT INTO recipe_depend (recipe, deptype, type, item, version) " "VALUES (?, ?, ?, ?, ?)", recipe_depends) for task_name in task_names: task_id = flatten_single_value(self.dbc.execute( "SELECT id FROM task WHERE recipe=? AND name=?", (recipe_id, task_name))) for parent in recipe.meta.get_list_flag(task_name, "deps"): self.dbc.execute( "INSERT INTO task_parent (recipe, task, parent) " "VALUES (:recipe_id, :task_name, :parent)", locals()) for _deptask in recipe.meta.get_list_flag(task_name, "deptask"): deptask = _deptask.split(":", 1) if len(deptask) != 2: bb.fatal("invalid deptask:", _deptask) assert deptask[0] in ("DEPENDS", "RDEPENDS", "FDEPENDS") self.dbc.execute( "INSERT INTO task_deptask (task, deptype, deptask) " "VALUES (?, ?, ?)", ([task_id] + deptask)) for _recdeptask in recipe.meta.get_list_flag(task_name, "recdeptask"): recdeptask = _recdeptask.split(":", 1) if len(recdeptask) != 2: bb.fatal("invalid deptask:", _recdeptask) assert recdeptask[0] in ("DEPENDS", "RDEPENDS", "FDEPENDS") self.dbc.execute( "INSERT INTO task_recdeptask (task, deptype, recdeptask) " "VALUES (?, ?, ?)", ([task_id] + recdeptask)) for depends in recipe.meta.get_list_flag(task_name, "depends"): try: (parent_item, parent_task) = depends.split(":") self.dbc.execute( "INSERT INTO task_depend " "(task, parent_item, parent_task) " "VALUES (?, ?, ?)", (task_id, parent_item, parent_task)) except ValueError: err("invalid task 'depends' value for %s " "(valid syntax is item:task): %s"%( task_name, depends)) packages = recipe.meta.get_list("PACKAGES") if not packages: warn("no packages defined for recipe %s"%(recipe)) else: for package in packages: arch = (recipe.meta.get("PACKAGE_ARCH_" + package) or recipe.meta.get("RECIPE_ARCH")) type = (recipe.meta.get("PACKAGE_TYPE_" + package) or recipe.meta.get("RECIPE_TYPE")) package_id = self.add_package(recipe, package, type, arch) provides = recipe.meta.get("PROVIDES_" + package) or "" provides = provides.split() if not package in provides: provides.append(package) for item in provides: self.dbc.execute( "INSERT INTO provide (package, item) " "VALUES (?, ?)", (package_id, item)) for deptype in ("DEPENDS", "RDEPENDS"): depends = recipe.meta.get("%s_%s"%(deptype , package)) or "" for item in depends.split(): self.dbc.execute( "INSERT INTO package_depend " "(package, deptype, item) " "VALUES (?, ?, ?)", (package_id, deptype, item)) return
def get_recipe(self, id=None, task=None, package=None, filename=None, type=None, name=None, version=None, strict=True, default_type="machine"): """ Get recipe from cookbook. Returns recipe object if arguments match a single recipe. Returns None if recipe is not found. Throws MultipleRecipes exception if more than one recipe is found. """ recipes = self.get_recipes( id=id, task=task, package=package, filename=filename, type=type, name=name, version=version) if len(recipes) == 0: recipe = None elif len(recipes) == 1: recipe = recipes[0] elif strict: warn("multiple recipes found in %s.%s: returning None!"%( self.__class__.__name__, inspect.stack()[0][3])) for recipe in recipes: info("%s:%s_%s"%(recipe.type, recipe.name, recipe.version)) recipe = None else: chosen = [ recipes[0] ] for other in recipes[1:]: if chosen[0].priority > other.priority: continue if chosen[0].priority < other.priority: chosen = [ other ] continue vercmp = bb.utils.vercmp_part(chosen[0].version, other.version) if vercmp < 0: chosen = [ other ] if vercmp == 0: #debug("chosen=%s\nother=%s"%(chosen, other)) #die("you have to be more precise") chosen.append(other) if len(chosen) == 1: recipe = chosen[0] elif not default_type: warn("multiple recipes found in %s.%s: returning None!"%( self.__class__.__name__, inspect.stack()[0][3])) for recipe in chosen: info("%s:%s_%s"%(recipe.type, recipe.name, recipe.version)) recipe = None else: # there is multiple recipes with the same priority and version, # so let's try to pick the default type defaults_chosen = [] for choice in chosen: if choice.type == default_type: defaults_chosen.append(choice) if len(defaults_chosen) == 1: recipe = defaults_chosen[0] elif not defaults_chosen: debug("multiple recipes, but none with default_type (%s)"%( default_type)) recipe = None else: warn("multiple recipes found in %s.%s: returning None!"%( self.__class__.__name__, inspect.stack()[0][3])) for recipe in defaults_chosen: info("%s:%s_%s"%(recipe.type, recipe.name, recipe.version)) recipe = None return recipe
def warn(*args): oebakery.warn(" ".join(args))
def add_recipe(self, recipe): self.dbc.execute( "INSERT INTO recipe " "(file, type, name, version, priority) " "VALUES (?, ?, ?, ?, ?)", (recipe.filename, recipe.type, recipe.name, recipe.version, recipe.priority)) recipe_id = self.dbc.lastrowid recipe.set_id(recipe_id) self.recipes[recipe_id] = recipe task_names = recipe.get_task_names() taskseq = [] for task_name in task_names: task_nostamp = recipe.meta.get_boolean_flag(task_name, "nostamp") taskseq.append((recipe_id, task_name, task_nostamp)) if taskseq: self.dbc.executemany( "INSERT INTO task (recipe, name, nostamp) VALUES (?, ?, ?)", taskseq) for deptype in ("DEPENDS", "RDEPENDS", "FDEPENDS"): for item in (recipe.meta.get(deptype) or "").split(): item = oelite.item.OEliteItem(item, (deptype, recipe.type)) recipe.item_deps[deptype].add(item) for item in (recipe.meta.get("CLASS_"+deptype) or "").split(): item = oelite.item.OEliteItem(item, (deptype, recipe.type)) recipe.item_deps[deptype].add(item) for task_name in task_names: task_id = flatten_single_value(self.dbc.execute( "SELECT id FROM task WHERE recipe=? AND name=?", (recipe_id, task_name))) for parent in recipe.meta.get_list_flag(task_name, "deps"): self.dbc.execute( "INSERT INTO task_parent (recipe, task, parent) " "VALUES (:recipe_id, :task_name, :parent)", locals()) for _deptask in recipe.meta.get_list_flag(task_name, "deptask"): deptask = _deptask.split(":", 1) if len(deptask) != 2: bb.fatal("invalid deptask:", _deptask) assert deptask[0] in ("DEPENDS", "RDEPENDS", "FDEPENDS") self.dbc.execute( "INSERT INTO task_deptask (task, deptype, deptask) " "VALUES (?, ?, ?)", ([task_id] + deptask)) for _recdeptask in recipe.meta.get_list_flag(task_name, "recdeptask"): recdeptask = _recdeptask.split(":", 1) if len(recdeptask) != 2: bb.fatal("invalid deptask:", _recdeptask) assert recdeptask[0] in ("DEPENDS", "RDEPENDS", "FDEPENDS") self.dbc.execute( "INSERT INTO task_recdeptask (task, deptype, recdeptask) " "VALUES (?, ?, ?)", ([task_id] + recdeptask)) packages = recipe.meta.get_list("PACKAGES") if not packages: warn("no packages defined for recipe %s"%(recipe)) else: for package in packages: arch = (recipe.meta.get("PACKAGE_ARCH_" + package) or recipe.meta.get("RECIPE_ARCH")) type = (recipe.meta.get("PACKAGE_TYPE_" + package) or recipe.meta.get("RECIPE_TYPE")) package_id = self.add_package(recipe, package, type, arch) provides = recipe.meta.get("PROVIDES_" + package) or "" provides = provides.split() if not package in provides: provides.append(package) for item in provides: self.dbc.execute( "INSERT INTO provide (package, item) " "VALUES (?, ?)", (package_id, item)) for deptype in ("DEPENDS", "RDEPENDS"): depends = recipe.meta.get("%s_%s"%(deptype , package)) or "" for item in depends.split(): self.dbc.execute( "INSERT INTO package_depend " "(package, deptype, item) " "VALUES (?, ?, ?)", (package_id, deptype, item)) return