def getConfigs(self, path): base_path = utils.concatPaths(path, self.config_name) base_path = os.path.expanduser(base_path) files = [] for r, _, f in os.walk(base_path): for file in f: files.append(os.path.join(r, file)) return files
def test_trailing_slash(self): self.assertEqual(utils.concatPaths("/test/pth/", "rest/of/path"), "/test/pth/rest/of/path")
def test_no_trailing_or_leading_slashes(self): self.assertEqual(utils.concatPaths("/test/pth", "rest/of/path"), "/test/pth/rest/of/path")
def command(args, cfg): manager_order = cfg['managers']['order'].splitlines() manager_order = [s for s in manager_order if s] pkg_path = utils.concatPaths(cfg['paths']['base_path'], cfg['paths']['pkg_path']) for integration in manager_order: manager = managers[integration](args.verbose) # Get a list of packages pkgs = manager.getPackages(pkg_path) # Update the manager print("[" + manager.config_name + "] update") if not (args.dry_run): if not manager.update(): print(manager.config_name + " failed to update") sys.exit(1) if args.verbose >= 1 or args.dry_run: print(manager.config_name + " updated") # Install new packages print("[" + manager.config_name + "] install new packages") # Compare with the list of full packages because some of the requested # packages might be dependencies on others, so .leaves() would be wrong new_pkgs = pkgs.difference(manager.list()) if args.verbose >= 1 or args.dry_run: print("The following " + manager.config_name + " packages will be installed") print(list(new_pkgs)) if not (args.dry_run): if not manager.install(list(new_pkgs)): print("Failed to install packages for " + manager.config_name) sys.exit(1) # Uninstall old packages print("[" + manager.config_name + "] uninstall old packages") # Compare with the packages that aren't dependencies (leaves) so that we # don't uninstall a required package old_pkgs = manager.leaves().difference(pkgs) if args.verbose >= 1 or args.dry_run: print("The following " + manager.config_name + " packages will be uninstalled") print(list(old_pkgs)) if not (args.dry_run): if not manager.uninstall(list(old_pkgs)): print("Failed to uninstall packages for " + manager.config_name) sys.exit(1) # Update installed packages print("[" + manager.config_name + "] update packages") if not args.update_all: # Don't update packages we can't know have latest versions non_updatable_pkgs = manager.list_non_updatable() updatable_pkgs = pkgs.difference(non_updatable_pkgs) else: updatable_pkgs = pkgs if args.verbose >= 1 or args.dry_run: print("The following " + manager.config_name + " packages will be upgraded") print(list(updatable_pkgs)) if not (args.dry_run): if not manager.upgrade(list(updatable_pkgs)): print("Failed to upgrade packages for " + manager.config_name) sys.exit(1)
import os from configparser import ConfigParser import utils base_path = "~/.config/mpm" config_file_path = utils.concatPaths(base_path, "config.ini") default_config = {"paths": {"base_path": base_path, "pkg_path": "pkgs"}, "managers": {"order": ""}} def loadConfig(config_path): cfg = ConfigParser() # Load defaults cfg.read_dict(default_config) cfg.read(os.path.expanduser(config_path)) return cfg
def command(args, cfg): manager_order = cfg['managers']['order'].splitlines() manager_order = [s for s in manager_order if s] pkg_path = utils.concatPaths(cfg['paths']['base_path'], cfg['paths']['pkg_path']) rows = [] for integration in manager_order: print("[" + integration + "]") manager = managers[integration](False) # Get listed packages pkgs_by_config = manager.getPackagesByConfig(pkg_path) all_pkgs = set(reduce(lambda a, b: a + b, pkgs_by_config.values())) # Get the packages to be *installed* # Compare with the list of full packages because some of the requested # packages might be dependencies on others, so .leaves() would be wrong new_pkgs = all_pkgs.difference(manager.list()) # Get the packages to be *uninstalled* # Compare with the packages that aren't dependencies (leaves) so that we # don't uninstall a required package old_pkgs = manager.leaves().difference(all_pkgs) # Print new packages print(" [new]") no_pkgs = True for cfg_path in sorted(pkgs_by_config.keys()): pkgs = set(pkgs_by_config[cfg_path]) new_pkgs = pkgs.intersection(new_pkgs) if len(new_pkgs) != 0: print(" [" + cfg_path + "]") for pkg in new_pkgs: print(" " + pkg) no_pkgs = False if no_pkgs: print(" (none)") print() # Print existing packages print(" [existing]") no_pkgs = True for cfg_path in sorted(pkgs_by_config.keys()): pkgs = set(pkgs_by_config[cfg_path]) existing_pkgs = pkgs.difference(new_pkgs.union(old_pkgs)) if len(existing_pkgs) != 0: print(" [" + cfg_path + "]") for pkg in existing_pkgs: print(" " + pkg) no_pkgs = False if no_pkgs: print(" (none)") print() # Print new packages print(" [old]") no_pkgs = True for cfg_path in sorted(pkgs_by_config.keys()): pkgs = set(pkgs_by_config[cfg_path]) old_pkgs = pkgs.intersection(old_pkgs) if len(old_pkgs) != 0: print(" [" + cfg_path + "]") for pkg in old_pkgs: print(" " + pkg) no_pkgs = False if no_pkgs: print(" (none)") print()