From 4ace4c267bb64ad1de97bf6a6b3e0771a434d100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Beck?= Date: Tue, 30 Aug 2022 10:37:06 +0200 Subject: [PATCH] example script sophomorix-collect (python) added --- sophomorix-samba/python/modules/smbclient.py | 28 ++++++++++ .../python/scripts/sophomorix-collect | 56 +++++++++++++++++++ .../python/scripts/sophomorix-distribute | 26 +++------ 3 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 sophomorix-samba/python/scripts/sophomorix-collect diff --git a/sophomorix-samba/python/modules/smbclient.py b/sophomorix-samba/python/modules/smbclient.py index e26f9d42..d54857da 100644 --- a/sophomorix-samba/python/modules/smbclient.py +++ b/sophomorix-samba/python/modules/smbclient.py @@ -49,6 +49,34 @@ def distribute(config): return 0 +############################################################ +def collect(config): + """Collect data from (one or multiple) user(s) to another user + + config is a dictionary with the following keys: + + :scopy: True if data should be copied with server-site copy method + :from_users: list of source users + :from_path: sub dir in home of source users + :to_user: target user + :to_path: sub dir in home of target user + """ + print() + print("The following dictionary was received:") + print(config) + print() + print(f"The resulting loop is:") + + for key, values in config.items(): + print('Key :: ', key) + if(isinstance(values, list)): + for value in values: + target=f"{config['to_user']}/{config['to_path']}" + source=f"{value}/{config['from_path']}" + print(f" What to do: copy {source} to {target}") + return 0 + + print('... module sophomorix_smbclient.py loaded') diff --git a/sophomorix-samba/python/scripts/sophomorix-collect b/sophomorix-samba/python/scripts/sophomorix-collect new file mode 100644 index 00000000..cc4d5478 --- /dev/null +++ b/sophomorix-samba/python/scripts/sophomorix-collect @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +# austeilen: /usr/sbin/sophomorix-transfer -jj --scopy --from-user rrrr --to-user t20,t13,t02,t10,t16,t11,t17,t08,t26,t03,t14,t19,t06,t09,t22,t15,t24,t25,t21,t18,t01,t23,t04,t05,t12,t07 --from-path transfer/ausdruck-fertig.pdf --to-path transfer/rrrr_test/ + +# einsammeln: +# /usr/sbin/sophomorix-transfer -jj --move --keep-source-directory --from-user t20,t13,t02,t10,t16,t11,t17,t08,t26,t03,t14,t19,t06,t09,t22,t15,t24,t25,t21,t18,t01,t23,t04,t05,t12,t07, --to-user rrrr --from-path transfer/rrrr_test --to-path transfer/collected/20220401_15-30-04-test/ --to-path-addon fullinfo --no-target-directory::18230:: + +import sophomorix.smbclient +import argparse + +parser = argparse.ArgumentParser(add_help = True, + description = "SMB client for sophomorix to collect data from multiple users to one user") +parser.add_argument('--scopy', + action="store_true", # 'True' is the default + default=True, + help='copy the files with sever-site copy method') +parser.add_argument('to_user', + type=str, + help='single user that collects data') +parser.add_argument('--from-path', + type=str, + default='transfer', + help='subdir in (multiple) users home that contains the source data') +parser.add_argument('from_users', + nargs='+', # at least one argument, maybe more + type=str, + help='(multiple) users that have the source data that is collected') +parser.add_argument('--to-path', + type=str, + default='transfer', + help='subdir in single target users home') +arguments = parser.parse_args() +config = vars(arguments) + +# the arguments are collected in the dictionary 'config' +print(config) + +print("############################################################") + +# select one value from the arguments object +print(f"1) The target user is: {arguments.to_user}") +print(f"1) The source users are: {arguments.from_users}") + +# select one value from the config dictionary +print(f"2) The target user is: {config['to_user']}") +print(f"2) The source users are: {config['from_users']}") + + +sophomorix.smbclient.collect(config) + + +#help(sophomorix.smbclient.collect) + + + + diff --git a/sophomorix-samba/python/scripts/sophomorix-distribute b/sophomorix-samba/python/scripts/sophomorix-distribute index 14e4232a..d5f6393a 100644 --- a/sophomorix-samba/python/scripts/sophomorix-distribute +++ b/sophomorix-samba/python/scripts/sophomorix-distribute @@ -8,14 +8,15 @@ import sophomorix.smbclient import argparse -parser = argparse.ArgumentParser(add_help = True, description = "SMB client for sophomorix.") +parser = argparse.ArgumentParser(add_help = True, + description = "SMB client for sophomorix to distrubute data from one user to multiple users") parser.add_argument('--scopy', action="store_true", # 'True' is the default default=True, help='copy the files with sever-site copy method') parser.add_argument('from_user', type=str, - help='user that has the source data') + help='single user that has the source data') parser.add_argument('--from-path', type=str, default='transfer', @@ -23,7 +24,7 @@ parser.add_argument('--from-path', parser.add_argument('to_users', nargs='+', # at least one argument, maybe more type=str, - help='target data users ') + help='(multiple) target data users ') parser.add_argument('--to-path', type=str, default='transfer', @@ -51,19 +52,6 @@ sophomorix.smbclient.distribute(config) #help(sophomorix.smbclient.distribute) - - - - -# calling the script with: -# sophomorix-smbclient --scopy ritchie --from-path subdir bz lordjo --to-path transfer/downstream/subdir - -# Questions: -# 1) split sophomorix-smbclient in multiple scripts: -# sophomorix-distribute -# one user -> multiple users -# sophomorix-collect -# multiple user -> one user -# -# 2) dictionary that is expected from scopy function -# can webui organize data the same way before calling +# example: +# +# sophomorix-distribute --scopy chef maier mueller burger --from-path tele --to-path fon