-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_session.py
More file actions
executable file
·50 lines (42 loc) · 1.51 KB
/
start_session.py
File metadata and controls
executable file
·50 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import os
import sys
import json
import subprocess
import click
from secure_workspace import SecureWorkspace
def start_workspace():
"""Initialize and start a new secure workspace session."""
workspace = SecureWorkspace()
workspace.logger.info("\nInitializing secure workspace...")
# Get initial state of files
cmd = ['find', os.path.expanduser('~'), '-type', 'f']
try:
result = subprocess.run(cmd, capture_output=True, text=True)
files = result.stdout.splitlines()
except subprocess.SubprocessError:
workspace.logger.error("Failed to get initial file list")
return False
# Track initial state
tracked_files = 0
for filepath in files:
if workspace._should_track_file(filepath):
norm_path = workspace._normalize_path(filepath)
workspace.original_state[norm_path] = workspace._calculate_file_hash(norm_path)
workspace._backup_file(norm_path)
tracked_files += 1
# Save state
with open(workspace.STATE_FILE, 'w') as f:
json.dump({
'backup_path': workspace.backup_path,
'original_state': workspace.original_state
}, f)
workspace.logger.info(f"Secure workspace started - tracking {tracked_files} files")
workspace.logger.info("Any new files or modifications will be tracked and reverted when stopping")
return True
@click.command()
def main():
if not start_workspace():
sys.exit(1)
if __name__ == '__main__':
main()