-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployToPi.py
45 lines (38 loc) · 1.38 KB
/
deployToPi.py
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
#!/usr/bin/env python3
import os
import subprocess
from pathlib import Path
import sys
def deploy_to_pi():
# Configuration
PI_HOST = "pi.local"
PI_USER = "dev"
REMOTE_DIR = "~/"
try:
# Use rsync to copy files
print("Syncing files to Raspberry Pi...")
rsync_command = [
'rsync',
'-av', # archive mode, verbose
'--progress', # show progress
'--exclude', '.git/', # exclude git directory
'--exclude', 'venv/', # exclude virtual environment
'--exclude', '__pycache__/',
'--exclude', '*.pyc',
'--exclude', '*.pyo',
'--exclude', '*.pyd',
'--exclude', '.env/',
'--exclude', '.DS_Store',
'./', # current directory
f'{PI_USER}@{PI_HOST}:{REMOTE_DIR}/'
]
# If you have a .gitignore file, use it for excludes
if os.path.exists('.gitignore'):
rsync_command.insert(-2, '--exclude-from=.gitignore')
subprocess.run(rsync_command, check=True)
print("\nFiles deployed successfully to Raspberry Pi")
except subprocess.CalledProcessError as e:
print(f"Error deploying files: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
deploy_to_pi()