def run(self, args): to_install = [] for req in args.requirements: name, spec = parse_requirement(req) try: name = self.manager.resolve_mod_name(name, remote=True) req = Requirement(name, spec) releases = start_iter( self.manager.resolve_remote_requirement( req, ignore_game_ver=args.ignore_game_ver)) except StopIteration: releases = [] except ModNotFoundError as ex: print("Error: %s" % ex) continue if not args.held and req.name in self.config.hold: print("%s is held. " "Use -H to install it anyway." % (req.name)) continue local_mod = self.manager.get_mod(req.name) for release in releases: if local_mod: local_ver = local_mod.version release_ver = Version(release.version) if not args.reinstall and release_ver == local_ver: print("%s==%s is already installed. " "Use -R to reinstall it." % (local_mod.name, local_ver)) break elif not args.downgrade and release_ver < local_ver: print( "%s is already installed in a more recent version." " Use -D to downgrade it." % (local_mod.name)) break to_install.append((name, release)) break else: print("No match found for %s" % (req, )) continue for name, release in to_install: self.install(args, name, release) if not args.no_deps: self.install_deps(args)
def get_releases(self, mod_name, game_version): try: mod = getattr(self.db.mods, mod_name) except AttributeError: raise ModNotFoundError(mod_name) if match_game_version(mod.latest_release, game_version): latest = mod.latest_release yield latest mod = self.api.get_mod(mod_name) res = [release for release in mod.releases if match_game_version(release, game_version) and release.version != latest.version] res.sort(key=lambda r: Version(r.version), reverse=True) yield from res
def set_mod_enabled(self, name, enabled=True): mod = self.get_mod_json(name) if not mod: mod = {'enabled': '', 'name': name} self.mods_json.mods.append(mod) mod = self.get_mod_json(name) if enabled != self.is_mod_enabled(name): if self.config.game_version < Version('0.15'): # Factorio < 0.15 uses "true"/"false" strings # instead of booleans mod.enabled = 'true' if enabled else 'false' else: mod.enabled = enabled self.mods_json.save() return True else: return False
def version(self): return Version(self.info.version)
def game_version_major(self): return Version('.'.join(self.game_version.split('.')[:2]))
def run(self, args): installed = self.manager.find_mods() updates = [] if args.ignore_game_ver: game_ver = None else: game_ver = self.config.game_version_major self.db.update() for local_mod in installed: print("Checking: %s" % local_mod.name) try: release = next( self.manager.get_releases(local_mod.name, game_ver)) except StopIteration: continue found_update = False local_ver = local_mod.version latest_ver = local_ver latest_release = None for release in remote_mod.releases: if not args.ignore_game_ver and \ parse_game_version(release) != game_ver: continue release_ver = Version(release.version) if release_ver > latest_ver: found_update = True latest_ver = release_ver latest_release = release update_mod = True if found_update: print("Found update: %s %s" % (local_mod.name, latest_ver)) if not args.unpacked and not local_mod.packed: print("%s is unpacked. " "Use -U to update it anyway." % (local_mod.name)) update_mod = False if not args.held and local_mod.name in self.config.hold: print("%s is held. " "Use -H to update it anyway." % local_mod.name) update_mod = False if update_mod: updates.append((local_mod, latest_release)) if not updates: print("No updates were found") return print("Found %d update%s:" % ( len(updates), "s" if len(updates) != 1 else "", )) for local_mod, release in updates: print(" %s %s -> %s" % (local_mod.name, local_mod.version, release.version)) if not args.show: if not args.yes and prompt("Continue?", "Y/n") != "y": return for local_mod, release in updates: self.manager.install_mod(local_mod.name, release)