base
This commit is contained in:
75
app/main.py
75
app/main.py
@@ -713,20 +713,67 @@ class DiskReorganizer:
|
|||||||
return f"{size:.1f}PB"
|
return f"{size:.1f}PB"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
p=argparse.ArgumentParser();s=p.add_subparsers(dest='cmd',required=True)
|
parser = argparse.ArgumentParser(description='Disk Reorganizer - Free up a disk for Linux dual-boot')
|
||||||
i=s.add_parser('index');i.add_argument('root');i.add_argument('name')
|
subparsers = parser.add_subparsers(dest='command', required=True)
|
||||||
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')
|
# Index command
|
||||||
d=s.add_parser('dedupe');d.add_argument('--disk');d.add_argument('--no-chunks',action='store_true')
|
index_parser = subparsers.add_parser('index', help='Index files on a disk')
|
||||||
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')
|
index_parser.add_argument('disk_root', help='Root path of disk (e.g., D:\\\\)')
|
||||||
r=s.add_parser('report');r.add_argument('--fmt',default='text');r.add_argument('--dups',action='store_true');r.add_argument('--preview')
|
index_parser.add_argument('disk_name', help='Logical name for the disk')
|
||||||
a=p.parse_args();t=DiskReorganizer()
|
|
||||||
if a.cmd=='index':t.index_disk(a.root,a.name)
|
# Plan command
|
||||||
elif a.cmd=='dedupe':t.run_deduplication(a.disk,not a.no_chunks)
|
plan_parser = subparsers.add_parser('plan', help='Create migration plan')
|
||||||
elif a.cmd=='merge':t.plan_merge(a.sources,a.target,a.out,a.filter,a.net)
|
plan_parser.add_argument('target_disk', help='Disk to free up')
|
||||||
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'])}")
|
plan_parser.add_argument('dest_disks', nargs='+', help='Destination disks')
|
||||||
elif a.cmd=='execute':t.execute_migration(a.file,a.dry)
|
|
||||||
elif a.cmd=='report':t.generate_report(a.fmt,a.dups,a.preview)
|
# 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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user