5.4 KiB
5.4 KiB
File Manager Enhancement Plan
This document outlines the plan to enhance the my-app/utils/file_manager.py script based on user feedback.
Goals:
- Add support for loading configuration from a
config.yamlfile. - Implement a new action (
--move-cold) to move inactive ("cold") files from fast storage back to slow storage based on modification time. - Add an
--interactiveflag to prompt for confirmation before moving files. - Implement a new action (
--generate-stats) to create a JSON file containing storage statistics (file counts, sizes by age) for both source and target directories. - Calculate and log the total size of files being moved by the
--move-coldaction.
Detailed Plan:
-
Configuration File (
config.yaml):- Goal: Allow users to define common settings in a YAML file.
- Implementation:
- Define structure for
config.yaml(e.g.,~/.config/file_manager/config.yamlor specified via--config). - Use
PyYAMLlibrary (requirespip install PyYAML). - Modify
parse_argumentsto load settings, allowing command-line overrides. - Add
--configargument.
- Define structure for
-
Move Cold Files Back (
--move-coldaction):- Goal: Move files from fast (target) to slow (source) storage if inactive.
- Implementation:
- Add action:
--move-cold. - Add argument:
--stale-days(default 30, uses modification timest_mtime). - New function
find_stale_files(directory, days): Scanstarget_dirbased onst_mtime. - New function
move_files_cold(relative_file_list, source_dir, target_dir, dry_run, interactive):- Similar to
move_files. - Moves files from
target_dirtosource_dirusingrsync. - Handles paths relative to
target_dir. - Calculates and logs total size of files to be moved before
rsync. - Incorporates interactive confirmation.
- Similar to
- Add action:
-
Interactive Confirmation (
--interactiveflag):- Goal: Add a safety check before moving files.
- Implementation:
- Add global flag:
--interactive. - Modify
move_filesandmove_files_cold:- If
--interactiveand not--dry-run:- Log files/count.
- Use
input()for user confirmation (yes/no). - Proceed only on "yes".
- If
- Add global flag:
-
Enhanced Reporting/Stats File (
--generate-statsaction):- Goal: Create a persistent JSON file with storage statistics.
- Implementation:
- Add action:
--generate-stats. - Add argument:
--stats-file(overrides config). - New function
analyze_directory(directory):- Walks directory, calculates total count/size, count/size by modification time brackets.
- Returns data as a dictionary.
- Modify
mainor create orchestrator for--generate-stats:- Call
analyze_directoryfor source and target. - Combine results with a timestamp.
- Write dictionary to
stats_fileusingjson.
- Call
- (Optional): Modify
--summarize-unusedto potentially use the stats file.
- Add action:
Workflow Visualization (Mermaid):
graph TD
Start --> ReadConfig{Read config.yaml (Optional)}
ReadConfig --> ParseArgs[Parse Command Line Args]
ParseArgs --> ValidateArgs{Validate Args & Config}
ValidateArgs --> ActionRouter{Route based on Action}
ActionRouter -- --generate-stats --> AnalyzeSrc[Analyze Source Dir]
AnalyzeSrc --> AnalyzeTgt[Analyze Target Dir]
AnalyzeTgt --> WriteStatsFile[Write stats.json]
WriteStatsFile --> End
ActionRouter -- --move --> FindRecent[Find Recent Files (Source)]
FindRecent --> CheckInteractiveHot{Interactive?}
CheckInteractiveHot -- Yes --> ConfirmHot(Confirm Move Hot?)
CheckInteractiveHot -- No --> ExecuteMoveHot[Execute rsync Hot (Source->Target)]
ConfirmHot -- Yes --> ExecuteMoveHot
ConfirmHot -- No --> AbortHot(Abort Hot Move)
AbortHot --> End
ExecuteMoveHot --> End
ActionRouter -- --move-cold --> FindStale[Find Stale Files (Target)]
FindStale --> CalculateColdSize[Calculate Total Size of Cold Files]
CalculateColdSize --> CheckInteractiveCold{Interactive?}
CheckInteractiveCold -- Yes --> ConfirmCold(Confirm Move Cold?)
CheckInteractiveCold -- No --> ExecuteMoveCold[Execute rsync Cold (Target->Source)]
ConfirmCold -- Yes --> ExecuteMoveCold
ConfirmCold -- No --> AbortCold(Abort Cold Move)
AbortCold --> End
ExecuteMoveCold --> End
ActionRouter -- --count --> FindRecentForCount[Find Recent Files (Source)]
FindRecentForCount --> CountFiles[Log Count]
CountFiles --> End
ActionRouter -- --summarize-unused --> SummarizeUnused[Summarize Unused (Target)]
SummarizeUnused --> LogSummary[Log Summary]
LogSummary --> End
ActionRouter -- No Action/Error --> ShowHelp[Show Help / Error]
ShowHelp --> End
Summary of Changes:
- New dependencies:
PyYAML. - New command-line arguments:
--move-cold,--stale-days,--interactive,--generate-stats,--stats-file,--config. - New functions:
find_stale_files,move_files_cold,analyze_directory. - Modifications to existing functions:
parse_arguments,move_files,main. - Introduction of
config.yamlfor settings. - Introduction of a JSON stats file for persistent reporting.