-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_functions.py
More file actions
57 lines (52 loc) · 1.76 KB
/
app_functions.py
File metadata and controls
57 lines (52 loc) · 1.76 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
51
52
53
54
55
56
57
import subprocess
import threading
import os
from datetime import datetime
RECEIVER_PROCESS = None
def log_activity(message):
with open('activity.log', 'a') as f:
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
f.write(f"[{timestamp}] {message}\n")
def start_receiver():
global RECEIVER_PROCESS
if RECEIVER_PROCESS is None or RECEIVER_PROCESS.poll() is not None:
RECEIVER_PROCESS = subprocess.Popen(['python', 'receiver.py'])
log_activity("Receiver started")
return True
return False
def stop_receiver():
global RECEIVER_PROCESS
if RECEIVER_PROCESS and RECEIVER_PROCESS.poll() is None:
RECEIVER_PROCESS.terminate()
RECEIVER_PROCESS = None
log_activity("Receiver stopped")
return True
return False
def send_files(ip, file_paths):
# print(f"Starting send_files function for IP: {ip}")
results = []
print(f"File paths: {file_paths}")
for path in file_paths:
print(f"Processing file: {path}")
try:
print("trying to send file")
result = subprocess.run(
['python3', 'sender.py', ip, path],
capture_output=True,
text=True,
timeout=60
)
results.append({
'file': os.path.basename(path),
'output': result.stdout,
'error': result.stderr
})
# log_activity(f"Sent {os.path.basename(path)} to {ip}")
except Exception as e:
results.append({
'file': os.path.basename(path),
'output': '',
'error': str(e)
})
# log_activity(f"Failed to send {os.path.basename(path)}: {str(e)}")
return results