From 29431b3786154df191bac76587cfcb19c832abf7 Mon Sep 17 00:00:00 2001 From: jonnybravo Date: Mon, 19 Feb 2024 18:05:34 +0100 Subject: [PATCH] commit message from python script --- rclone/main/main.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/rclone/main/main.py b/rclone/main/main.py index 991382a..071bd4f 100755 --- a/rclone/main/main.py +++ b/rclone/main/main.py @@ -1,31 +1,34 @@ -#! /home/jonnybravo/Projekte/Python_Skripte/rclone/bin/python3.11 +#! /usr/bin/env python3 -import os, time +import os, time, subprocess def check_ping(hostname = str): - response = os.system("timeout 0.2 ping -c 1 " + hostname + '&> /dev/null') + list_command = list(str('timeout 0.2 ping -c 1 ' + hostname).split()) + response = subprocess.run(list_command, stdout=subprocess.PIPE) # and then check the response... - if response == 0: + if response.returncode == 0: return True else: return False - def rclone_folders_copy(folder_to_sync=list, dest_folder = str): check_list = [] for sync_folder in folder_to_sync: print("Hole Datein", 'rclone:' + sync_folder, "...") - command = os.system('rclone copy rclone:' + sync_folder + ' ' + dest_folder + os.sep + sync_folder +' --update --create-empty-src-dirs &> /dev/null') - if command == 0: + list_command = list(str('rclone copy rclone:' + sync_folder + ' ' + dest_folder + os.sep + sync_folder + ' --update --create-empty-src-dirs').split()) + command = subprocess.run(list_command, stdout=subprocess.PIPE) + if command.returncode == 0: check_list.append(True) elif command > 0: check_list.append(False) print("Folder", "rclone:" + sync_folder , "not exist") print("Kopiere Datein", dest_folder + os.sep + sync_folder, "..." ) - command = os.system('rclone copy ' + dest_folder + os.sep + sync_folder + ' ' + "rclone:" + sync_folder + ' --update --create-empty-src-dirs &> /dev/null' ) - if command == 0: + + list_command = list(str('rclone copy ' + dest_folder + os.sep + sync_folder + ' ' + "rclone:" + sync_folder + ' --update --create-empty-src-dirs').split()) + command = subprocess.run(list_command, stdout=subprocess.PIPE) + if command.returncode == 0: check_list.append(True) - elif command > 0: + elif command.returncode > 0: check_list.append(False) print("Folder", dest_folder + os.sep + sync_folder , "not exist") for check in check_list: @@ -33,11 +36,9 @@ def rclone_folders_copy(folder_to_sync=list, dest_folder = str): return False return True - - if __name__ == "__main__": nextcloud_server = "schlaubistechtalk.de" - folder_to_sync_manuell = ['ssh_keys', 'frei', 'Doku','Joplin', 'Hack'] + folder_to_sync_manuell = ['frei'] print("Check online status von", nextcloud_server) for check_count in range(1,10): if check_ping(hostname=nextcloud_server) is True: