Skip to content

Commit

Permalink
[Alpha 0.0.3] Update
Browse files Browse the repository at this point in the history
[Alpha 0.0.3] Update
  • Loading branch information
AuroraZiling authored Apr 3, 2024
2 parents 825cd80 + 4e08ecf commit e598954
Show file tree
Hide file tree
Showing 45 changed files with 1,197 additions and 650 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "PipManager Continuous Integration"
on:
push:
branches:
- main
- development

jobs:
build:
Expand Down
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,8 @@ Double click `PipManager.exe` or `PipManager_withRuntime.exe` *If you have not i

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## Roadmap

### Features

- [x] Install Package
- [x] Default *pip install*
- [x] requirements.txt Import
- [x] Download Distributions
- [ ] Install via distributions
- [ ] Install via VCS
- [x] Update Package
- [x] Delete Package
- [x] Show Packages in list
- [x] Multi-environment Management
- [x] Search Package
- [ ] Dependency Completion Check
- [ ] Scenario Recommendation
- [ ] Cache Management
- [ ] Tools
- [ ] Embedded Lite Python Script Editor

### Long-term

- Logging
- Localization
- Rules of action exceptions

See the [Open Issues](https://github.com/AuroraZiling/PipManager/issues) for a full list of proposed features (and known issues).

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## Contributing

Expand All @@ -113,8 +85,6 @@ See the [Open Issues](https://github.com/AuroraZiling/PipManager/issues) for a f
4. Push to the Branch `development`
5. Open a Pull Request

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## License

Distributed under the MIT License. See `LICENSE` for more information.
Expand Down
8 changes: 4 additions & 4 deletions src/PipManager.PackageSearch/PackageSearchService.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using HtmlAgilityPack;
using PipManager.PackageSearch.Wrappers.Query;
using Serilog;

namespace PipManager.PackageSearch;

public class PackageSearchService(HttpClient httpClient) : IPackageSearchService
{
public Dictionary<(string, int), QueryWrapper> QueryCaches { get; set; } = [];
private Dictionary<(string, int), QueryWrapper> QueryCaches { get; } = [];

public async Task<QueryWrapper> Query(string name, int page = 1)
{
if (QueryCaches.ContainsKey((name, page)))
{
return QueryCaches[(name, page)];
}
var htmlContent = "";
string htmlContent;
try
{
htmlContent = await httpClient.GetStringAsync($"https://pypi.org/search/?q={name}&page={page}");
}
catch (Exception exception) when (exception is TaskCanceledException || exception is HttpRequestException)
catch (Exception exception) when (exception is TaskCanceledException or HttpRequestException)
{
return new QueryWrapper
{
Expand Down Expand Up @@ -53,6 +52,7 @@ public async Task<QueryWrapper> Query(string name, int page = 1)
Version = resultItem.ChildNodes[1].ChildNodes[3].InnerText,
Description = resultItem.ChildNodes[3].InnerText,
Url = $"https://pypi.org{resultItem.Attributes["href"].Value}",
// ReSharper disable once StringLiteralTypo
UpdateTime = DateTime.ParseExact(resultItem.ChildNodes[1].ChildNodes[5].ChildNodes[0].Attributes["datetime"].Value, "yyyy-MM-ddTHH:mm:sszzz", null, System.Globalization.DateTimeStyles.RoundtripKind)
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/PipManager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static T GetService<T>()

[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool FreeConsole();
private static partial void FreeConsole();

private bool _showConsoleWindow;
private bool _experimentMode;
Expand Down
2 changes: 1 addition & 1 deletion src/PipManager/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PipManager;

public static class AppInfo
{
public static readonly string AppVersion = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3) ?? string.Empty;
public static readonly string AppVersion = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3);

public static readonly string ConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
public static readonly string CrushesDir = Path.Combine(Directory.GetCurrentDirectory(), "crashes");
Expand Down
80 changes: 48 additions & 32 deletions src/PipManager/AppStarting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using PipManager.Helpers;

namespace PipManager;

public partial class AppStarting
{
[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool AllocConsole();
private static partial void AllocConsole();

public readonly AppConfig Config;
private readonly AppConfig _config;
public bool ShowConsoleWindow = false;

public AppStarting()
{
Config = ConfigurationService.LoadConfiguration();
_config = ConfigurationService.LoadConfiguration();
Directory.CreateDirectory(AppInfo.CrushesDir);
Directory.CreateDirectory(AppInfo.LogDir);
Directory.CreateDirectory(AppInfo.CachesDir);
}

public void LoadLanguage()
{
var language = Config.Personalization.Language;
var language = _config.Personalization.Language;
if (language != "Auto")
{
I18NExtension.Culture = new CultureInfo(language);
Expand Down Expand Up @@ -61,10 +62,10 @@ public void StartLogging()

public void LogDeletion()
{
if (!Config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return;
if (!_config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return;
var fileList = Directory.GetFileSystemEntries(AppInfo.LogDir);
var logFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
if (logFileAmount >= Config.Personalization.LogAutoDeletionTimes)
if (logFileAmount >= _config.Personalization.LogAutoDeletionTimes)
{
var directoryInfo = new DirectoryInfo(AppInfo.LogDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
Expand All @@ -77,7 +78,7 @@ public void LogDeletion()
}
catch
{
continue;
// ignored
}
}
Log.Information($"{logFileAmount} log file(s) deleted");
Expand All @@ -86,27 +87,29 @@ public void LogDeletion()

public void CrushesDeletion()
{
if (!Config.Personalization.CrushesAutoDeletion || !Directory.Exists(AppInfo.CrushesDir)) return;
if (!_config.Personalization.CrushesAutoDeletion || !Directory.Exists(AppInfo.CrushesDir)) return;
var fileList = Directory.GetFileSystemEntries(AppInfo.CrushesDir);
var crushFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
if (crushFileAmount >= Config.Personalization.CrushesAutoDeletionTimes)
if (crushFileAmount < _config.Personalization.CrushesAutoDeletionTimes)
{
var directoryInfo = new DirectoryInfo(AppInfo.CrushesDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
foreach (var file in filesInfo)
return;
}

var directoryInfo = new DirectoryInfo(AppInfo.CrushesDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
foreach (var file in filesInfo)
{
if (file.Extension != ".txt") continue;
try
{
if (file.Extension != ".txt") continue;
try
{
File.Delete(file.FullName);
}
catch
{
continue;
}
File.Delete(file.FullName);
}
catch
{
// ignored
}
Log.Information($"{crushFileAmount} crush file(s) deleted");
}
Log.Information($"{crushFileAmount} crush file(s) deleted");
}

public void CachesDeletion()
Expand All @@ -115,19 +118,32 @@ public void CachesDeletion()
var directoryInfo = new DirectoryInfo(AppInfo.CachesDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
var cacheFileAmount = 0;
foreach (var subDir in directoryInfo.GetDirectories("tempTarGz-*", SearchOption.AllDirectories))
{
try
{
subDir.Delete(true);
}
catch (Exception)
{
// ignored
}
}
foreach (var file in filesInfo)
{
if (file.Name.StartsWith("temp_"))
if (!file.Name.StartsWith("temp_"))
{
try
{
File.Delete(file.FullName);
cacheFileAmount++;
}
catch
{
continue;
}
continue;
}

try
{
File.Delete(file.FullName);
cacheFileAmount++;
}
catch
{
// ignored
}
}
Log.Information($"{cacheFileAmount} cache file(s) deleted");
Expand Down
4 changes: 3 additions & 1 deletion src/PipManager/Helpers/ThreadIdEnricher.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Serilog.Core;
using Serilog.Events;

namespace PipManager.Helpers;

internal class ThreadIdEnricher : ILogEventEnricher
{
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
"ThreadId", Environment.CurrentManagedThreadId));
"ThreadId", Environment.CurrentManagedThreadId));
}
}
Loading

0 comments on commit e598954

Please sign in to comment.