refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,181 @@
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Naming;
|
||||
|
||||
namespace Chronos.Core.Import;
|
||||
|
||||
/// <summary>An archive frame that may be the same photo.</summary>
|
||||
public sealed record ArchiveMatch(Guid FrameId, string? Sha256);
|
||||
|
||||
/// <summary>What the planner needs to know about the destination (implemented over the archive index).</summary>
|
||||
public interface IImportLookup
|
||||
{
|
||||
/// <summary>The file was imported from this card before (same path, size and time).</summary>
|
||||
Task<bool> WasImportedAsync(CardFile file, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Archive frames with this size and capture time; the planner compares hashes only for these.</summary>
|
||||
Task<IReadOnlyList<ArchiveMatch>> FindCandidatesAsync(long size, DateTime capturedAt, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Folder of the sequence an earlier import of this session went to, so a re-import continues it.</summary>
|
||||
Task<string?> FindSessionFolderAsync(string sessionKey, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>The folder is taken by something else (another sequence), so the session needs another name.</summary>
|
||||
bool IsFolderTaken(string folder);
|
||||
}
|
||||
|
||||
/// <summary>Turns card photos into an <see cref="ImportPlan"/> (BRIEF §12.4, §13). Nothing is written.</summary>
|
||||
public static class ImportPlanner
|
||||
{
|
||||
public static async Task<ImportPlan> PlanAsync(string sourceRoot, string destinationRoot, IReadOnlyList<CardPhoto> photos,
|
||||
IReadOnlyList<ImportProblem> problems, ImportOptions options, IImportLookup lookup, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var folderTemplate = PathTemplate.Parse(options.FolderTemplate);
|
||||
var fileTemplate = PathTemplate.Parse(options.FileTemplate);
|
||||
var drafts = new List<(string Key, List<CardPhoto> Photos)>();
|
||||
foreach (var body in photos.GroupBy(BodyKey, StringComparer.Ordinal))
|
||||
{
|
||||
var ordered = body.OrderBy(p => p.CaptureTime).ThenBy(p => p.File.RelativePath, StringComparer.Ordinal).ToList();
|
||||
var ranges = SessionSplitter.Split(ordered.ConvertAll(p => p.CaptureTime), options.SessionGap, options.MinimumSessionFrames,
|
||||
i => options.SplitBefore.Contains(ordered[i].File.RelativePath) ? true : options.MergeAt.Contains(ordered[i].File.RelativePath) ? false : null);
|
||||
foreach (var range in ranges)
|
||||
{
|
||||
var members = ordered.GetRange(range.Start, range.Count);
|
||||
drafts.Add((SessionKey(body.Key, members[0].CaptureTime), members));
|
||||
}
|
||||
}
|
||||
drafts.Sort((a, b) => a.Photos[0].CaptureTime.CompareTo(b.Photos[0].CaptureTime) is var c and not 0 ? c : string.CompareOrdinal(a.Key, b.Key));
|
||||
|
||||
var claimedFolders = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var sessions = new List<PlannedSession>(drafts.Count);
|
||||
for (var s = 0; s < drafts.Count; s++)
|
||||
{
|
||||
var (key, members) = drafts[s];
|
||||
var first = members[0];
|
||||
options.Titles.TryGetValue(key, out var title);
|
||||
var context = Context(first, first.CaptureTime, s + 1, 1, title);
|
||||
var folder = await lookup.FindSessionFolderAsync(key, cancellationToken).ConfigureAwait(false)
|
||||
?? UniqueFolder(folderTemplate.ExpandFolder(context), claimedFolders, lookup);
|
||||
claimedFolders.Add(folder);
|
||||
|
||||
var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var items = new List<PlannedItem>(members.Count);
|
||||
for (var i = 0; i < members.Count; i++)
|
||||
{
|
||||
var photo = members[i];
|
||||
var name = UniqueName(fileTemplate.ExpandFile(Context(photo, first.CaptureTime, s + 1, i + 1, title)), names);
|
||||
items.Add(await PlanItemAsync(sourceRoot, photo, name, options, lookup, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
sessions.Add(new PlannedSession
|
||||
{
|
||||
Number = s + 1,
|
||||
SessionKey = key,
|
||||
CameraMake = first.Metadata.Make,
|
||||
CameraModel = first.Metadata.Model,
|
||||
CameraSerial = first.Metadata.BodySerial,
|
||||
Format = first.Metadata.Format,
|
||||
Start = first.CaptureTime,
|
||||
End = members[^1].CaptureTime,
|
||||
Folder = folder,
|
||||
Title = title,
|
||||
Items = items,
|
||||
});
|
||||
}
|
||||
return new ImportPlan
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SourceRoot = Path.GetFullPath(sourceRoot),
|
||||
DestinationRoot = Path.GetFullPath(destinationRoot),
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Sessions = sessions,
|
||||
Problems = problems,
|
||||
AvailableBytes = FreeSpace(destinationRoot),
|
||||
};
|
||||
}
|
||||
|
||||
private static async Task<PlannedItem> PlanItemAsync(string sourceRoot, CardPhoto photo, string name, ImportOptions options, IImportLookup lookup,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var item = new PlannedItem
|
||||
{
|
||||
SourcePath = photo.File.RelativePath,
|
||||
Size = photo.File.Size,
|
||||
ModifiedUtc = photo.File.ModifiedUtc,
|
||||
CapturedAt = photo.CaptureTime,
|
||||
FileName = name,
|
||||
};
|
||||
if (await lookup.WasImportedAsync(photo.File, cancellationToken).ConfigureAwait(false))
|
||||
return item with { Action = ImportAction.SkipImported };
|
||||
var candidates = await lookup.FindCandidatesAsync(photo.File.Size, photo.CaptureTime, cancellationToken).ConfigureAwait(false);
|
||||
if (candidates.Count == 0) return item;
|
||||
var sha = await ContentHash.Sha256Async(Path.Combine(sourceRoot, photo.File.RelativePath), null, cancellationToken).ConfigureAwait(false);
|
||||
var match = candidates.FirstOrDefault(c => sha.Equals(c.Sha256, StringComparison.OrdinalIgnoreCase));
|
||||
if (match is null) return item with { Sha256 = sha };
|
||||
return item with
|
||||
{
|
||||
Sha256 = sha,
|
||||
ExistingFrameId = match.FrameId,
|
||||
Action = options.Duplicates == DuplicatePolicy.Skip ? ImportAction.SkipInArchive : ImportAction.Copy,
|
||||
};
|
||||
}
|
||||
|
||||
private static NamingContext Context(CardPhoto photo, DateTime sessionStart, int session, int number, string? title) => new()
|
||||
{
|
||||
CapturedAt = photo.CaptureTime,
|
||||
SessionStart = sessionStart,
|
||||
Session = session,
|
||||
Number = number,
|
||||
NumberInSession = number,
|
||||
CameraMake = photo.Metadata.Make,
|
||||
CameraModel = photo.Metadata.Model,
|
||||
Lens = photo.Metadata.LensModel,
|
||||
Iso = photo.Metadata.Iso,
|
||||
ExposureTime = photo.Metadata.ExposureTime,
|
||||
FNumber = photo.Metadata.FNumber,
|
||||
OriginalName = Path.GetFileNameWithoutExtension(photo.File.RelativePath),
|
||||
Extension = Path.GetExtension(photo.File.RelativePath).TrimStart('.'),
|
||||
Title = title,
|
||||
};
|
||||
|
||||
/// <summary>Camera body and file format: RAW+JPEG shooting yields two sequences instead of doubled frames.</summary>
|
||||
private static string BodyKey(CardPhoto p) => $"{p.Metadata.Make}|{p.Metadata.Model}|{p.Metadata.BodySerial}|{p.Metadata.Format}";
|
||||
|
||||
private static string SessionKey(string bodyKey, DateTime start) =>
|
||||
"card-" + Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(bodyKey)))[..8] + "-"
|
||||
+ start.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture);
|
||||
|
||||
private static string UniqueFolder(string folder, HashSet<string> claimed, IImportLookup lookup)
|
||||
{
|
||||
if (folder.Length == 0) folder = "Import";
|
||||
var candidate = folder;
|
||||
for (var n = 2; claimed.Contains(candidate) || lookup.IsFolderTaken(candidate); n++)
|
||||
candidate = string.Create(CultureInfo.InvariantCulture, $"{folder} ({n})");
|
||||
return candidate;
|
||||
}
|
||||
|
||||
/// <summary>Adds _2, _3… before the extension when the template gives two photos the same name.</summary>
|
||||
internal static string UniqueName(string name, HashSet<string> taken)
|
||||
{
|
||||
var candidate = name;
|
||||
var stem = Path.GetFileNameWithoutExtension(name);
|
||||
var extension = Path.GetExtension(name);
|
||||
for (var n = 2; !taken.Add(candidate); n++) candidate = string.Create(CultureInfo.InvariantCulture, $"{stem}_{n}{extension}");
|
||||
return candidate;
|
||||
}
|
||||
|
||||
private static long? FreeSpace(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var full = Path.GetFullPath(path);
|
||||
while (!Directory.Exists(full) && Path.GetDirectoryName(full) is { } parent) full = parent;
|
||||
// Windows wants a drive root; Unix accepts any directory and reports the volume it is mounted on.
|
||||
return new DriveInfo(OperatingSystem.IsWindows() ? Path.GetPathRoot(full)! : full).AvailableFreeSpace;
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or IOException or UnauthorizedAccessException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user