From feaa39ef1cae4fe4a866ec432bfba57e1ec6d388 Mon Sep 17 00:00:00 2001 From: Nicolas Desseauve Date: Sun, 28 Dec 2014 14:16:43 +0100 Subject: [PATCH 1/2] Add a --all option to upgrade. --- Action/Upgrade.cs | 49 ++++++++++++++++++++++++++++++++++++++++++++++- Options.cs | 3 +++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Action/Upgrade.cs b/Action/Upgrade.cs index 28aadbfbec..45918dcbba 100644 --- a/Action/Upgrade.cs +++ b/Action/Upgrade.cs @@ -1,11 +1,14 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using log4net; namespace CKAN.CmdLine { public class Upgrade : ICommand { + private static readonly ILog log = LogManager.GetLogger(typeof(Upgrade)); + public IUser User { get; set; } public Upgrade(IUser user) @@ -23,19 +26,63 @@ public int RunCommand(CKAN.KSP ksp, object raw_options) options.modules.Add(MainClass.LoadCkanFromFile(ksp, options.ckan_file).identifier); } - if (options.modules.Count == 0) + if (options.modules.Count == 0 && ! options.upgrade_all) { // What? No files specified? User.RaiseMessage("Usage: ckan upgrade Mod [Mod2, ...]"); + User.RaiseMessage(" or ckan upgrade --all"); return Exit.BADOPT; } User.RaiseMessage("\nUpgrading modules...\n"); // TODO: These instances all need to go. try + { + if (options.upgrade_all) + { + var installed = new Dictionary(ksp.Registry.Installed()); + var to_upgrade = new List(); + + foreach (KeyValuePair mod in installed) + { + Version current_version = mod.Value; + + if ((current_version is ProvidesVersion) || (current_version is DllVersion)) + { + continue; + } + else + { + try + { + // Check if upgrades are available + CkanModule latest = ksp.Registry.LatestAvailable(mod.Key, ksp.Version()); + + if (latest.version.IsGreaterThan(mod.Value)) + { + // Upgradable + log.InfoFormat("New version {0} found for {1}", + latest.version, latest.identifier); + to_upgrade.Add(latest); + } + + } + catch (ModuleNotFoundKraken) + { + log.InfoFormat("{0} is installed, but no longer in the registry", + mod.Key); + } + } + + } + + ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); + } + else { ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); } + } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage(kraken.Message); diff --git a/Options.cs b/Options.cs index 3925e4c177..a7b2f116bb 100644 --- a/Options.cs +++ b/Options.cs @@ -144,6 +144,9 @@ internal class UpgradeOptions : CommonOptions [Option("with-all-suggests", HelpText = "Install suggested modules all the way down")] public bool with_all_suggests { get; set; } + [Option("all", HelpText = "Upgrade all available updated modules")] + public bool upgrade_all { get; set; } + // TODO: How do we provide helptext on this? [ValueList(typeof (List))] public List modules { get; set; } From 9dc765c965ab2bb266dc3e1fcbbdef40cf393528 Mon Sep 17 00:00:00 2001 From: Nicolas Desseauve Date: Sun, 28 Dec 2014 14:23:03 +0100 Subject: [PATCH 2/2] Really upgrade + indentation. --- Action/Upgrade.cs | 69 ++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/Action/Upgrade.cs b/Action/Upgrade.cs index 45918dcbba..a415f30de4 100644 --- a/Action/Upgrade.cs +++ b/Action/Upgrade.cs @@ -35,53 +35,54 @@ public int RunCommand(CKAN.KSP ksp, object raw_options) } User.RaiseMessage("\nUpgrading modules...\n"); - // TODO: These instances all need to go. + try { - if (options.upgrade_all) - { - var installed = new Dictionary(ksp.Registry.Installed()); - var to_upgrade = new List(); - - foreach (KeyValuePair mod in installed) + if (options.upgrade_all) { - Version current_version = mod.Value; + var installed = new Dictionary(ksp.Registry.Installed()); + var to_upgrade = new List(); - if ((current_version is ProvidesVersion) || (current_version is DllVersion)) + foreach (KeyValuePair mod in installed) { - continue; - } - else - { - try + Version current_version = mod.Value; + + if ((current_version is ProvidesVersion) || (current_version is DllVersion)) { - // Check if upgrades are available - CkanModule latest = ksp.Registry.LatestAvailable(mod.Key, ksp.Version()); + continue; + } + else + { + try + { + // Check if upgrades are available + CkanModule latest = ksp.Registry.LatestAvailable(mod.Key, ksp.Version()); - if (latest.version.IsGreaterThan(mod.Value)) + if (latest.version.IsGreaterThan(mod.Value)) + { + // Upgradable + log.InfoFormat("New version {0} found for {1}", + latest.version, latest.identifier); + to_upgrade.Add(latest); + } + + } + catch (ModuleNotFoundKraken) { - // Upgradable - log.InfoFormat("New version {0} found for {1}", - latest.version, latest.identifier); - to_upgrade.Add(latest); + log.InfoFormat("{0} is installed, but no longer in the registry", + mod.Key); } - - } - catch (ModuleNotFoundKraken) - { - log.InfoFormat("{0} is installed, but no longer in the registry", - mod.Key); } + } + ModuleInstaller.GetInstance(ksp, User).Upgrade(to_upgrade, new NetAsyncDownloader(User)); + } + else + { + // TODO: These instances all need to go. + ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); } - - ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); - } - else - { - ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); - } } catch (ModuleNotFoundKraken kraken) {