Changes¶
Change tracking for audit trails and dry-run support.
CHANGELIST¶
The global list of all changes made during execution.
import fscm
fscm.file("/etc/config", "content")
fscm.run("systemctl restart myapp", sudo=True)
for change in fscm.CHANGELIST:
print(change)
Change Types¶
All changes inherit from the Change base class.
File Changes¶
FileAdd¶
A new file was created.
FileModify¶
An existing file was modified.
FileRm¶
A file was removed.
Directory Changes¶
DirAdd¶
A directory was created.
Permission Changes¶
ChmodModify¶
File permissions were changed.
ChownModify¶
File ownership was changed.
Symlink Changes¶
SymlinkAdd¶
A symbolic link was created.
Command Changes¶
CmdRun¶
A command was executed.
Package Changes¶
PkgAdd¶
A package was installed.
Working with Changes¶
Iterate Changes¶
Filter by Type¶
# Get all file changes
file_changes = [c for c in fscm.CHANGELIST if isinstance(c, fscm.FileAdd)]
# Get all package installations
packages = [c for c in fscm.CHANGELIST if isinstance(c, fscm.PkgAdd)]
Check if Changes Were Made¶
Clear Changes¶
Change Properties¶
All Change objects have:
| Property | Type | Description |
|---|---|---|
timestamp |
datetime | When the change occurred |
msg |
str | Human-readable description |
Example: Audit Report¶
import fscm
from datetime import datetime
def generate_audit_report():
"""Generate a report of all changes."""
report = []
report.append(f"Audit Report - {datetime.now()}")
report.append("=" * 50)
for change in fscm.CHANGELIST:
timestamp = change.timestamp.strftime("%H:%M:%S")
report.append(f"[{timestamp}] {type(change).__name__}")
report.append(f" {change.msg}")
report.append("=" * 50)
report.append(f"Total changes: {len(fscm.CHANGELIST)}")
return "\n".join(report)
# After running your configuration
print(generate_audit_report())
Example: Conditional Restart¶
import fscm
# Configure the application
fscm.file("/etc/myapp/config.yaml", new_config)
fscm.file("/etc/myapp/secrets.env", secrets)
# Only restart if config files changed
config_changed = any(
isinstance(c, (fscm.FileAdd, fscm.FileModify))
and "/etc/myapp/" in str(getattr(c, 'filename', ''))
for c in fscm.CHANGELIST
)
if config_changed:
fscm.run("systemctl restart myapp", sudo=True)