-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchown
executable file
·55 lines (46 loc) · 1.82 KB
/
chown
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
#!/usr/bin/env python
import kas
import argparse
import os
import getpass
def check_owner(owner):
'''
checks if new owner is acceptable: so either phpuser or current KAS user
:param owner: requested new owner
:return: True if new owner name is accepatable, False if not
'''
if owner == "":
return False
if owner == "phpuser" or owner == kas.get_user():
return True
return False
if __name__ == "__main__":
#version of this tool
__version__ = "0.2"
# get arguments from CLI
parser = argparse.ArgumentParser(description='chown tool for hoster all-inkl.com using their KAS API, '
'homepage: https://github.com/e-dschungel/kas_tools')
parser.add_argument('-R', '--recursive', action='store_true',
help='operate recursively on files and directories')
parser.add_argument('owner', help='can be `phpuser` or your current KAS user (i.e. `w123456`)')
parser.add_argument('path', nargs='*', help = 'path to be chowned')
parser.add_argument('--version', action='version',
version='%(prog)s ' + __version__)
args = parser.parse_args()
#make sure path is absolute
args.path = [os.path.abspath(path) for path in args.path]
#check input
kas = kas.KAS()
if not check_owner(args.owner):
raise IOError("Invalid owner name!")
for path in args.path:
if not os.path.exists(path):
raise IOError("{} does not exist".format(path))
#get KAS user and password
kas_user = kas.get_user()
password = getpass.getpass("KAS password for user {}: ".format(kas_user))
#log into KAS
kas.login(kas_user, password)
#execute chown
for path in args.path:
kas.update_chown(args.owner, kas.fix_chown_path(path), args.recursive)