Skip to content

Commit c000457

Browse files
committed
Make it so other sources can be run
They are essentially hard-coded to return an empty enumerable for now, but it is a start.
1 parent 47b1d14 commit c000457

File tree

4 files changed

+80
-23
lines changed

4 files changed

+80
-23
lines changed

src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,19 @@ public void Run(ChocolateyConfiguration configuration)
210210
{
211211
foreach (var sourceRunner in _containerResolver.ResolveAll<IGetPackagesSourceRunner>())
212212
{
213-
if (sourceRunner.SourceType == "windowsfeatures" || sourceRunner.SourceType == "dotnet")
213+
foreach (var package in sourceRunner.GetInstalledPackages(configuration).ToList())
214214
{
215-
foreach (var package in sourceRunner.GetInstalledPackages(configuration).ToList())
216-
{
217-
xw.WriteStartElement("package");
218-
xw.WriteAttributeString("id", package.Identity.Id);
215+
xw.WriteStartElement("package");
216+
xw.WriteAttributeString("id", package.Identity.Id);
219217

220-
if (configuration.ExportCommand.IncludeVersionNumbers)
221-
{
222-
xw.WriteAttributeString("version", package.Identity.Version.ToString());
223-
}
218+
if (configuration.ExportCommand.IncludeVersionNumbers)
219+
{
220+
xw.WriteAttributeString("version", package.Identity.Version.ToString());
221+
}
224222

225-
xw.WriteAttributeString("sourceType", sourceRunner.SourceType);
223+
xw.WriteAttributeString("sourceType", sourceRunner.SourceType);
226224

227-
xw.WriteEndElement();
228-
}
225+
xw.WriteEndElement();
229226
}
230227
}
231228
}

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,14 @@ public virtual IEnumerable<PackageResult> List(ChocolateyConfiguration config)
311311
{
312312
foreach (var sourceRunner in _containerResolver.ResolveAll<IListSourceRunner>())
313313
{
314-
if (sourceRunner.SourceType == "windowsfeatures" || sourceRunner.SourceType == "dotnet")
314+
if (config.RegularOutput)
315315
{
316-
if (config.RegularOutput)
317-
{
318-
this.Log().Info(() => "");
319-
}
316+
this.Log().Info(() => "");
317+
}
320318

321-
foreach (var alternativeSourcePackage in sourceRunner.List(config))
322-
{
323-
yield return alternativeSourcePackage;
324-
}
319+
foreach (var alternativeSourcePackage in sourceRunner.List(config))
320+
{
321+
yield return alternativeSourcePackage;
325322
}
326323
}
327324
}

src/chocolatey/infrastructure.app/services/PythonService.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
using chocolatey.infrastructure.logging;
2929
using chocolatey.infrastructure.results;
3030
using chocolatey.infrastructure.platforms;
31+
using log4net.Util;
3132

3233
namespace chocolatey.infrastructure.app.services
3334
{
3435
/// <summary>
3536
/// Alternative Source for Installing Python packages
3637
/// </summary>
37-
public sealed class PythonService : IBootstrappableSourceRunner, IListSourceRunner, IInstallSourceRunner, IUpgradeSourceRunner, IUninstallSourceRunner
38+
public sealed class PythonService : IBootstrappableSourceRunner, IGetPackagesSourceRunner, IListSourceRunner, IInstallSourceRunner, IUpgradeSourceRunner, IUninstallSourceRunner
3839
{
3940
private readonly ICommandExecutor _commandExecutor;
4041
private readonly INugetService _nugetService;
@@ -300,11 +301,43 @@ public void ListDryRun(ChocolateyConfiguration config)
300301
this.Log().Info("Would have run '{0} {1}'".FormatWith(_exePath.EscapeCurlyBraces(), args.EscapeCurlyBraces()));
301302
}
302303

304+
public IEnumerable<PackageResult> GetInstalledPackages(ChocolateyConfiguration config)
305+
{
306+
try
307+
{
308+
EnsureExecutablePathSet();
309+
}
310+
catch (FileNotFoundException fnfex)
311+
{
312+
// Since the python executable can't be found, let's return early
313+
return Enumerable.Empty<PackageResult>();
314+
}
315+
316+
// TODO: Put stuff in here!
317+
318+
return Enumerable.Empty<PackageResult>();
319+
}
320+
303321
public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
304322
{
305-
EnsureExecutablePathSet();
323+
try
324+
{
325+
EnsureExecutablePathSet();
326+
}
327+
catch (FileNotFoundException fnfex)
328+
{
329+
if (config.RegularOutput)
330+
{
331+
this.Log().Warn(() => "0 Python packages managed with Chocolatey.");
332+
}
333+
334+
// Since the python executable can't be found, let's return early
335+
return Enumerable.Empty<PackageResult>();
336+
}
337+
306338
var args = BuildArguments(config, _listArguments);
307339
var packageResults = new List<PackageResult>();
340+
var count = 0;
308341

309342
Environment.ExitCode = _commandExecutor.Execute(
310343
_exePath,
@@ -327,6 +360,8 @@ public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
327360
{
328361
this.Log().Debug(() => "[{0}] {1}".FormatWith(AppName, logMessage.EscapeCurlyBraces()));
329362
}
363+
364+
count++;
330365
},
331366
stdErrAction: (s, e) =>
332367
{
@@ -341,6 +376,11 @@ public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
341376
allowUseWindow: true
342377
);
343378

379+
if (config.RegularOutput)
380+
{
381+
this.Log().Warn(() => @"{0} Python packages managed with Chocolatey.".FormatWith(count));
382+
}
383+
344384
return packageResults;
345385
}
346386

src/chocolatey/infrastructure.app/services/RubyGemsService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using chocolatey.infrastructure.logging;
2626
using chocolatey.infrastructure.results;
2727
using chocolatey.infrastructure.platforms;
28+
using System.IO;
2829

2930
namespace chocolatey.infrastructure.app.services
3031
{
@@ -156,10 +157,25 @@ public void ListDryRun(ChocolateyConfiguration config)
156157
this.Log().Info("Would have run '{0} {1}'".FormatWith(ExePath.EscapeCurlyBraces(), args.EscapeCurlyBraces()));
157158
}
158159

160+
public IEnumerable<PackageResult> GetInstalledPackages(ChocolateyConfiguration config)
161+
{
162+
// TODO: Need to put stuff here, similar to Python source
163+
return Enumerable.Empty<PackageResult>();
164+
}
165+
159166
public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
160167
{
168+
// TODO: Need to have a way to valid that Ruby is installed, similar to Python
169+
if (config.RegularOutput)
170+
{
171+
this.Log().Warn(() => "0 Ruby packages managed with Chocolatey.");
172+
}
173+
174+
return Enumerable.Empty<PackageResult>();
175+
161176
var packageResults = new List<PackageResult>();
162177
var args = ExternalCommandArgsBuilder.BuildArguments(config, _listArguments);
178+
var count = 0;
163179

164180
Environment.ExitCode = _commandExecutor.Execute(
165181
ExePath,
@@ -181,6 +197,8 @@ public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
181197
{
182198
this.Log().Debug(() => "[{0}] {1}".FormatWith(AppName, logMessage.EscapeCurlyBraces()));
183199
}
200+
201+
count++;
184202
},
185203
stdErrAction: (s, e) =>
186204
{
@@ -194,6 +212,11 @@ public IEnumerable<PackageResult> List(ChocolateyConfiguration config)
194212
updateProcessPath: false
195213
);
196214

215+
if (config.RegularOutput)
216+
{
217+
this.Log().Warn(() => @"{0} Ruby packages managed with Chocolatey.".FormatWith(count));
218+
}
219+
197220
return packageResults;
198221
}
199222

0 commit comments

Comments
 (0)