commit 6f4102f52df654730f9dc30a445c1aeef8afac9e Author: Patrick Sulzle Date: Mon Jun 17 23:22:27 2024 +0200 initial diff --git a/src/config.ini b/src/config.ini new file mode 100644 index 0000000..29bc08a --- /dev/null +++ b/src/config.ini @@ -0,0 +1,20 @@ +[main] +host = sjoelnas +user = admin + +[source] +path = "." + +[muziek] +albums = /share/Multimedia/Muziek/Albums3 +verzamel = /share/Multimedia/Muziek/Verzamelalbum + +[film] +aktie = /share/Multimedia/Films/Aktie +drama = /share/Multimedia/Films/Drama +klassieker = /share/Multimedia/Films/Klassieker + +[boek] +nl = /share/Download/Boeken +en = "/share/Download/engelse boeken" +magazine = /Download/Magazines diff --git a/src/copymenu.py b/src/copymenu.py new file mode 100755 index 0000000..da7a0a0 --- /dev/null +++ b/src/copymenu.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 + +import configparser +import os +import subprocess + +from simple_term_menu import TerminalMenu + +inifile = 'config.ini' + +def readconfig(): + config = configparser.ConfigParser() + config.read(inifile) + user = config['main']['user'] + host = config['main']['host'] + path = config['boek']['nl'] + assemble = user + "@" + host + ":" + path + return assemble + +def change_config(): + print("Config aangepast") + exit() + +def copy_files(): + print("Files from:", os.getcwd()) + files = os.listdir(".") # array of files in cwd + copy_menu = TerminalMenu( + files, + multi_select = True, + show_multi_select_hint = True, + ) + copy_menu_index = copy_menu.show() + selection = copy_menu.chosen_menu_entries # array of files chosen in menu + counter = 0 + for selected in selection: + cmd = "rsync" + arg = "-avz" + dest = readconfig() + process_out = subprocess.run([cmd, arg, selected, dest]) + counter = counter + 1 + + return counter + + +def main(): + main_menu_title = "Main menu for multiple file copy with rsync command\nsulzlep@gmail.com\n" + main_menu_items = ["[c] copy", "[e] edit config", "[q] quit"] + main_menu_exit = False + + terminal_menu = TerminalMenu( + menu_entries = main_menu_items, + title = main_menu_title, + cycle_cursor = True, + clear_screen = True, + ) + + while not main_menu_exit: + menu_entry_index = terminal_menu.show() + if menu_entry_index == 0: + print("Copy files") + nr = copy_files() + print("\n\n\nThere are", nr, "files copied\n" ) + input("Press enter to continue...") + elif menu_entry_index == 1: + print("Edit config") + change_config() + print (res) + input("Press enter to continue...") + elif menu_entry_index == 2: + print("Quitting") + main_menu_exit = True + +if __name__ == "__main__": + main()