def run_list(self): """ Print a list of recipes. """ pkgmgr = PackageManager() recmgr = RecipeListManager() self.log.debug("Loading all package names") all_recipes = recmgr.list_all() if self.args.list is not None: all_recipes = [x for x in all_recipes if re.search(self.args.list, x)] not_installed_string = '-' format_pkg_list = lambda x: [not_installed_string] if not x else x rows = [] row_titles = { 'id': "Package Name", 'path': "Recipe Filename", 'installed_by': "Installed By", 'available_from': "Available From", } self.args.format = [x for x in self.args.format.split(",") if len(x)] if any(map(lambda x: x not in row_titles, self.args.format)): self.log.error("Invalid column formatting: {0}".format(self.args.format)) return -1 print("Loading package information...", end="") sys.stdout.flush() home_dir = os.path.expanduser("~") for pkg in all_recipes: rec = recipe.get_recipe(pkg, target=None, fail_easy=True) if rec is None: print() self.log.warn("Recipe for `{0}' is invalid.".format(pkg)) continue if rec.target != 'package': continue print(".", end="") sys.stdout.flush() row = { 'id': pkg, 'path': recmgr.get_recipe_filename(pkg).replace(home_dir, "~"), 'installed_by': format_pkg_list(pkgmgr.installed(pkg, return_pkgr_name=True)), 'available_from': ",".join(format_pkg_list(pkgmgr.exists(pkg, return_pkgr_name=True))), } if self.args.in_prefix and 'source' not in row['installed_by']: continue if row['installed_by'] == [not_installed_string] and (self.args.installed or self.args.in_prefix): continue row['installed_by'] = ",".join(row['installed_by']) rows.append(row) print("") tables.print_table( row_titles, rows, self.args.format, sort_by=self.args.sort_by, )
def run_list(self): """ Print a list of recipes. """ pkgmgr = PackageManager() recmgr = RecipeListManager() self.log.debug("Loading all package names") all_recipes = recmgr.list_all() if self.args.list is not None: all_recipes = [x for x in all_recipes if re.search(self.args.list, x)] not_installed_string = '-' format_pkg_list = lambda x: [not_installed_string] if not x else x rows = [] row_titles = { 'id': "Package Name", 'path': "Recipe Filename", 'installed_by': "Installed By", 'available_from': "Available From", } self.args.format = [x for x in self.args.format.split(",") if len(x)] if any((x not in row_titles for x in self.args.format)): self.log.error("Invalid column formatting: {0}".format(self.args.format)) return -1 print("Loading package information...", end="") sys.stdout.flush() home_dir = os.path.expanduser("~") for pkg in all_recipes: rec = recipe.get_recipe(pkg, target=None, fail_easy=True) if rec is None: print() self.log.warn("Recipe for `{0}' is invalid.".format(pkg)) continue if rec.target != 'package': continue print(".", end="") sys.stdout.flush() row = { 'id': pkg, 'path': recmgr.get_recipe_filename(pkg).replace(home_dir, "~"), 'installed_by': format_pkg_list(pkgmgr.installed(pkg, return_pkgr_name=True)), 'available_from': ",".join(format_pkg_list(pkgmgr.exists(pkg, return_pkgr_name=True))), } if self.args.in_prefix and 'source' not in row['installed_by']: continue if row['installed_by'] == [not_installed_string] and (self.args.installed or self.args.in_prefix): continue row['installed_by'] = ",".join(row['installed_by']) rows.append(row) print("") tables.print_table( row_titles, rows, self.args.format, sort_by=self.args.sort_by, )
def _list_recipes(self): """ Print a list of recipes. """ pkgmgr = PackageManager() recmgr = RecipeListManager() self.log.debug("Loading all package names") all_recipes = recmgr.list_all() if self.args.list is not None: all_recipes = [ x for x in all_recipes if re.search(self.args.list, x) ] not_installed_string = '-' format_installed_by = lambda x: [not_installed_string] if not x else x rows = [] row_titles = { 'id': "Package Name", 'path': "Recipe Filename", 'installed_by': "Installed By", } self.args.format = [x for x in self.args.format.split(",") if len(x)] if any(map(lambda x: x not in row_titles, self.args.format)): self.log.error("Invalid column formatting: {0}".format( self.args.format)) return -1 widths = {k: len(row_titles[k]) for k in row_titles.keys()} print("Loading package information...", end="") sys.stdout.flush() home_dir = os.path.expanduser("~") for pkg in all_recipes: if recipe.get_recipe(pkg, target=None).target != 'package': continue print(".", end="") sys.stdout.flush() row = { 'id': pkg, 'path': recmgr.get_recipe_filename(pkg).replace(home_dir, "~"), 'installed_by': format_installed_by( pkgmgr.installed(pkg, return_pkgr_name=True)), } if self.args.in_prefix and 'source' not in row['installed_by']: continue if row['installed_by'] == [ not_installed_string ] and (self.args.installed or self.args.in_prefix): continue row['installed_by'] = ",".join(row['installed_by']) widths = {k: max(widths[k], len(row[k])) for k in row.iterkeys()} rows.append(row) print("\n") # Sort rows if self.args.sort_by is not None and self.args.sort_by in row_titles.keys( ): rows = sorted(rows, key=lambda k: k[self.args.sort_by]) # Print Header hdr_len = 0 for col_id in self.args.format: format_string = "{0:" + str(widths[col_id]) + "} " hdr_title = format_string.format(row_titles[col_id]) print(hdr_title, end="") hdr_len += len(hdr_title) print("") print("-" * hdr_len) # Print Table for row in rows: for col_id in self.args.format: format_string = "{{0:{width}}} ".format(width=widths[col_id]) print(format_string.format(row[col_id]), end="") print("") print("")
def _list_recipes(self): """ Print a list of recipes. """ pkgmgr = PackageManager() recmgr = RecipeListManager() self.log.debug("Loading all package names") all_recipes = recmgr.list_all() if self.args.list is not None: all_recipes = [x for x in all_recipes if re.search(self.args.list, x)] not_installed_string = '-' format_installed_by = lambda x: [not_installed_string] if not x else x rows = [] row_titles = { 'id': "Package Name", 'path': "Recipe Filename", 'installed_by': "Installed By", } self.args.format = [x for x in self.args.format.split(",") if len(x)] if any(map(lambda x: x not in row_titles, self.args.format)): self.log.error("Invalid column formatting: {0}".format(self.args.format)) return -1 widths = {k: len(row_titles[k]) for k in row_titles.keys()} print("Loading package information...", end="") sys.stdout.flush() home_dir = os.path.expanduser("~") for pkg in all_recipes: if recipe.get_recipe(pkg, target=None).target != 'package': continue print(".", end="") sys.stdout.flush() row = { 'id': pkg, 'path': recmgr.get_recipe_filename(pkg).replace(home_dir, "~"), 'installed_by': format_installed_by(pkgmgr.installed(pkg, return_pkgr_name=True)), } if self.args.in_prefix and 'source' not in row['installed_by']: continue if row['installed_by'] == [not_installed_string] and (self.args.installed or self.args.in_prefix): continue row['installed_by'] = ",".join(row['installed_by']) widths = {k: max(widths[k], len(row[k])) for k in row.iterkeys()} rows.append(row) print("\n") # Sort rows if self.args.sort_by is not None and self.args.sort_by in row_titles.keys(): rows = sorted(rows, key=lambda k: k[self.args.sort_by]) # Print Header hdr_len = 0 for col_id in self.args.format: format_string = "{0:" + str(widths[col_id]) + "} " hdr_title = format_string.format(row_titles[col_id]) print(hdr_title, end="") hdr_len += len(hdr_title) print("") print("-" * hdr_len) # Print Table for row in rows: for col_id in self.args.format: format_string = "{{0:{width}}} ".format(width=widths[col_id]) print(format_string.format(row[col_id]), end="") print("") print("")