Skip to content

Commit e598954

Browse files
authored
[Alpha 0.0.3] Update
[Alpha 0.0.3] Update
2 parents 825cd80 + 4e08ecf commit e598954

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1197
-650
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: "PipManager Continuous Integration"
33
on:
44
push:
55
branches:
6-
- main
6+
- development
77

88
jobs:
99
build:

README.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,8 @@ Double click `PipManager.exe` or `PipManager_withRuntime.exe` *If you have not i
7474

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

77-
## Roadmap
78-
79-
### Features
80-
81-
- [x] Install Package
82-
- [x] Default *pip install*
83-
- [x] requirements.txt Import
84-
- [x] Download Distributions
85-
- [ ] Install via distributions
86-
- [ ] Install via VCS
87-
- [x] Update Package
88-
- [x] Delete Package
89-
- [x] Show Packages in list
90-
- [x] Multi-environment Management
91-
- [x] Search Package
92-
- [ ] Dependency Completion Check
93-
- [ ] Scenario Recommendation
94-
- [ ] Cache Management
95-
- [ ] Tools
96-
- [ ] Embedded Lite Python Script Editor
97-
98-
### Long-term
99-
100-
- Logging
101-
- Localization
102-
- Rules of action exceptions
103-
10477
See the [Open Issues](https://github.com/AuroraZiling/PipManager/issues) for a full list of proposed features (and known issues).
10578

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

10880
## Contributing
10981

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

116-
<p align="right">(<a href="#readme-top">back to top</a>)</p>
117-
11888
## License
11989

12090
Distributed under the MIT License. See `LICENSE` for more information.

src/PipManager.PackageSearch/PackageSearchService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
using HtmlAgilityPack;
22
using PipManager.PackageSearch.Wrappers.Query;
3-
using Serilog;
43

54
namespace PipManager.PackageSearch;
65

76
public class PackageSearchService(HttpClient httpClient) : IPackageSearchService
87
{
9-
public Dictionary<(string, int), QueryWrapper> QueryCaches { get; set; } = [];
8+
private Dictionary<(string, int), QueryWrapper> QueryCaches { get; } = [];
109

1110
public async Task<QueryWrapper> Query(string name, int page = 1)
1211
{
1312
if (QueryCaches.ContainsKey((name, page)))
1413
{
1514
return QueryCaches[(name, page)];
1615
}
17-
var htmlContent = "";
16+
string htmlContent;
1817
try
1918
{
2019
htmlContent = await httpClient.GetStringAsync($"https://pypi.org/search/?q={name}&page={page}");
2120
}
22-
catch (Exception exception) when (exception is TaskCanceledException || exception is HttpRequestException)
21+
catch (Exception exception) when (exception is TaskCanceledException or HttpRequestException)
2322
{
2423
return new QueryWrapper
2524
{
@@ -53,6 +52,7 @@ public async Task<QueryWrapper> Query(string name, int page = 1)
5352
Version = resultItem.ChildNodes[1].ChildNodes[3].InnerText,
5453
Description = resultItem.ChildNodes[3].InnerText,
5554
Url = $"https://pypi.org{resultItem.Attributes["href"].Value}",
55+
// ReSharper disable once StringLiteralTypo
5656
UpdateTime = DateTime.ParseExact(resultItem.ChildNodes[1].ChildNodes[5].ChildNodes[0].Attributes["datetime"].Value, "yyyy-MM-ddTHH:mm:sszzz", null, System.Globalization.DateTimeStyles.RoundtripKind)
5757
});
5858
}

src/PipManager/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static T GetService<T>()
129129

130130
[LibraryImport("kernel32.dll")]
131131
[return: MarshalAs(UnmanagedType.Bool)]
132-
private static partial bool FreeConsole();
132+
private static partial void FreeConsole();
133133

134134
private bool _showConsoleWindow;
135135
private bool _experimentMode;

src/PipManager/AppInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace PipManager;
55

66
public static class AppInfo
77
{
8-
public static readonly string AppVersion = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3) ?? string.Empty;
8+
public static readonly string AppVersion = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3);
99

1010
public static readonly string ConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
1111
public static readonly string CrushesDir = Path.Combine(Directory.GetCurrentDirectory(), "crashes");

src/PipManager/AppStarting.cs

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
using System.Globalization;
55
using System.IO;
66
using System.Runtime.InteropServices;
7+
using PipManager.Helpers;
78

89
namespace PipManager;
910

1011
public partial class AppStarting
1112
{
1213
[LibraryImport("kernel32.dll")]
1314
[return: MarshalAs(UnmanagedType.Bool)]
14-
private static partial bool AllocConsole();
15+
private static partial void AllocConsole();
1516

16-
public readonly AppConfig Config;
17+
private readonly AppConfig _config;
1718
public bool ShowConsoleWindow = false;
1819

1920
public AppStarting()
2021
{
21-
Config = ConfigurationService.LoadConfiguration();
22+
_config = ConfigurationService.LoadConfiguration();
2223
Directory.CreateDirectory(AppInfo.CrushesDir);
2324
Directory.CreateDirectory(AppInfo.LogDir);
2425
Directory.CreateDirectory(AppInfo.CachesDir);
2526
}
2627

2728
public void LoadLanguage()
2829
{
29-
var language = Config.Personalization.Language;
30+
var language = _config.Personalization.Language;
3031
if (language != "Auto")
3132
{
3233
I18NExtension.Culture = new CultureInfo(language);
@@ -61,10 +62,10 @@ public void StartLogging()
6162

6263
public void LogDeletion()
6364
{
64-
if (!Config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return;
65+
if (!_config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return;
6566
var fileList = Directory.GetFileSystemEntries(AppInfo.LogDir);
6667
var logFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
67-
if (logFileAmount >= Config.Personalization.LogAutoDeletionTimes)
68+
if (logFileAmount >= _config.Personalization.LogAutoDeletionTimes)
6869
{
6970
var directoryInfo = new DirectoryInfo(AppInfo.LogDir);
7071
var filesInfo = directoryInfo.GetFileSystemInfos();
@@ -77,7 +78,7 @@ public void LogDeletion()
7778
}
7879
catch
7980
{
80-
continue;
81+
// ignored
8182
}
8283
}
8384
Log.Information($"{logFileAmount} log file(s) deleted");
@@ -86,27 +87,29 @@ public void LogDeletion()
8687

8788
public void CrushesDeletion()
8889
{
89-
if (!Config.Personalization.CrushesAutoDeletion || !Directory.Exists(AppInfo.CrushesDir)) return;
90+
if (!_config.Personalization.CrushesAutoDeletion || !Directory.Exists(AppInfo.CrushesDir)) return;
9091
var fileList = Directory.GetFileSystemEntries(AppInfo.CrushesDir);
9192
var crushFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
92-
if (crushFileAmount >= Config.Personalization.CrushesAutoDeletionTimes)
93+
if (crushFileAmount < _config.Personalization.CrushesAutoDeletionTimes)
9394
{
94-
var directoryInfo = new DirectoryInfo(AppInfo.CrushesDir);
95-
var filesInfo = directoryInfo.GetFileSystemInfos();
96-
foreach (var file in filesInfo)
95+
return;
96+
}
97+
98+
var directoryInfo = new DirectoryInfo(AppInfo.CrushesDir);
99+
var filesInfo = directoryInfo.GetFileSystemInfos();
100+
foreach (var file in filesInfo)
101+
{
102+
if (file.Extension != ".txt") continue;
103+
try
97104
{
98-
if (file.Extension != ".txt") continue;
99-
try
100-
{
101-
File.Delete(file.FullName);
102-
}
103-
catch
104-
{
105-
continue;
106-
}
105+
File.Delete(file.FullName);
106+
}
107+
catch
108+
{
109+
// ignored
107110
}
108-
Log.Information($"{crushFileAmount} crush file(s) deleted");
109111
}
112+
Log.Information($"{crushFileAmount} crush file(s) deleted");
110113
}
111114

112115
public void CachesDeletion()
@@ -115,19 +118,32 @@ public void CachesDeletion()
115118
var directoryInfo = new DirectoryInfo(AppInfo.CachesDir);
116119
var filesInfo = directoryInfo.GetFileSystemInfos();
117120
var cacheFileAmount = 0;
121+
foreach (var subDir in directoryInfo.GetDirectories("tempTarGz-*", SearchOption.AllDirectories))
122+
{
123+
try
124+
{
125+
subDir.Delete(true);
126+
}
127+
catch (Exception)
128+
{
129+
// ignored
130+
}
131+
}
118132
foreach (var file in filesInfo)
119133
{
120-
if (file.Name.StartsWith("temp_"))
134+
if (!file.Name.StartsWith("temp_"))
121135
{
122-
try
123-
{
124-
File.Delete(file.FullName);
125-
cacheFileAmount++;
126-
}
127-
catch
128-
{
129-
continue;
130-
}
136+
continue;
137+
}
138+
139+
try
140+
{
141+
File.Delete(file.FullName);
142+
cacheFileAmount++;
143+
}
144+
catch
145+
{
146+
// ignored
131147
}
132148
}
133149
Log.Information($"{cacheFileAmount} cache file(s) deleted");
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using Serilog.Core;
22
using Serilog.Events;
33

4+
namespace PipManager.Helpers;
5+
46
internal class ThreadIdEnricher : ILogEventEnricher
57
{
68
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
79
{
810
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
9-
"ThreadId", Environment.CurrentManagedThreadId));
11+
"ThreadId", Environment.CurrentManagedThreadId));
1012
}
1113
}

0 commit comments

Comments
 (0)