Skip to content

Commit

Permalink
example script sophomorix-collect (python) added
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbeck committed Aug 30, 2022
1 parent 3e9b2d7 commit 4ace4c2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 19 deletions.
28 changes: 28 additions & 0 deletions sophomorix-samba/python/modules/smbclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
56 changes: 56 additions & 0 deletions sophomorix-samba/python/scripts/sophomorix-collect
Original file line number Diff line number Diff line change
@@ -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)




26 changes: 7 additions & 19 deletions sophomorix-samba/python/scripts/sophomorix-distribute
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@
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',
help='subdir in users home that contains the source data')
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',
Expand Down Expand Up @@ -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

0 comments on commit 4ace4c2

Please sign in to comment.