From 7c5df059df27f3141ca76d6b580b98ac772ee6a6 Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 13 Dec 2025 02:05:17 +0100 Subject: [PATCH] base --- app/main.py | 75 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/app/main.py b/app/main.py index 82d937f..0044d4b 100644 --- a/app/main.py +++ b/app/main.py @@ -713,20 +713,67 @@ class DiskReorganizer: return f"{size:.1f}PB" def main(): - p=argparse.ArgumentParser();s=p.add_subparsers(dest='cmd',required=True) - i=s.add_parser('index');i.add_argument('root');i.add_argument('name') - pl=s.add_parser('plan');pl.add_argument('target');pl.add_argument('dests',nargs='+') - e=s.add_parser('execute');e.add_argument('file');e.add_argument('--dry',action='store_true') - d=s.add_parser('dedupe');d.add_argument('--disk');d.add_argument('--no-chunks',action='store_true') - m=s.add_parser('merge');m.add_argument('--sources',nargs='+',required=True);m.add_argument('--target',required=True);m.add_argument('--out',default='merge.json');m.add_argument('--filter',action='store_true');m.add_argument('--net') - r=s.add_parser('report');r.add_argument('--fmt',default='text');r.add_argument('--dups',action='store_true');r.add_argument('--preview') - a=p.parse_args();t=DiskReorganizer() - if a.cmd=='index':t.index_disk(a.root,a.name) - elif a.cmd=='dedupe':t.run_deduplication(a.disk,not a.no_chunks) - elif a.cmd=='merge':t.plan_merge(a.sources,a.target,a.out,a.filter,a.net) - elif a.cmd=='plan':plan=t.plan_migration(a.target,a.dests);print(f"\nPlan {plan['file_count']} files {t.format_size(plan['total_size'])}") - elif a.cmd=='execute':t.execute_migration(a.file,a.dry) - elif a.cmd=='report':t.generate_report(a.fmt,a.dups,a.preview) + parser = argparse.ArgumentParser(description='Disk Reorganizer - Free up a disk for Linux dual-boot') + subparsers = parser.add_subparsers(dest='command', required=True) + + # Index command + index_parser = subparsers.add_parser('index', help='Index files on a disk') + index_parser.add_argument('disk_root', help='Root path of disk (e.g., D:\\\\)') + index_parser.add_argument('disk_name', help='Logical name for the disk') + + # Plan command + plan_parser = subparsers.add_parser('plan', help='Create migration plan') + plan_parser.add_argument('target_disk', help='Disk to free up') + plan_parser.add_argument('dest_disks', nargs='+', help='Destination disks') + + # Execute command + exec_parser = subparsers.add_parser('execute', help='Execute migration plan') + exec_parser.add_argument('plan_file', help='Path to plan JSON file') + exec_parser.add_argument('--dry-run', action='store_true', help='Simulate without actual file operations') + + # Dedupe command + dedupe_parser = subparsers.add_parser('dedupe', help='Deduplicate files and compute checksums') + dedupe_parser.add_argument('--disk', help='Optional: Only dedupe specific disk') + dedupe_parser.add_argument('--no-chunks', action='store_true', help='Disable chunk-level deduplication') + + # Merge command + merge_parser = subparsers.add_parser('merge', help='Plan multi-disk merge with deduplication') + merge_parser.add_argument('--sources', nargs='+', required=True, help='Source disks to merge') + merge_parser.add_argument('--target', required=True, help='Target disk') + merge_parser.add_argument('--output', default='merge_plan.json', help='Output plan file') + merge_parser.add_argument('--filter-system', action='store_true', help='Filter system/build files') + merge_parser.add_argument('--network', help='Network target (e.g., user@host:/path)') + + # Report command + report_parser = subparsers.add_parser('report', help='Show current status') + report_parser.add_argument('--format', choices=['text', 'json'], default='text', help='Report format') + report_parser.add_argument('--show-duplicates', action='store_true', help='Show duplicate files') + report_parser.add_argument('--preview-merge', help='Preview merge plan from file') + + args = parser.parse_args() + tool = DiskReorganizer() + + if args.command == 'index': + tool.index_disk(args.disk_root, args.disk_name) + + elif args.command == 'dedupe': + tool.run_deduplication(disk=args.disk, use_chunks=not args.no_chunks) + + elif args.command == 'merge': + tool.plan_merge(sources=args.sources, target=args.target, output_file=args.output, + filter_system=args.filter_system, network_target=args.network) + + elif args.command == 'plan': + plan = tool.plan_migration(args.target_disk, args.dest_disks) + if plan: + print(f"\nPlan generated: {plan['file_count']} files, {tool.format_size(plan['total_size'])}") + print(f"Destination disks: {', '.join(plan['destination_disks'])}") + + elif args.command == 'execute': + tool.execute_migration(args.plan_file, dry_run=args.dry_run) + + elif args.command == 'report': + tool.generate_report(format=args.format, show_duplicates=args.show_duplicates, preview_merge=args.preview_merge) if __name__ == '__main__': main() \ No newline at end of file