Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
python
Commits
a522e3aa
Commit
a522e3aa
authored
3 years ago
by
Maciej Bonin
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.phys.ethz.ch:core/python
parents
86598f7e
e1aca827
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+6
-0
6 additions, 0 deletions
README.md
bin/showgroup.py
+25
-7
25 additions, 7 deletions
bin/showgroup.py
lib/isg/argparser.py
+30
-8
30 additions, 8 deletions
lib/isg/argparser.py
lib/isg/dphysldap.py
+1
-1
1 addition, 1 deletion
lib/isg/dphysldap.py
with
62 additions
and
16 deletions
README.md
+
6
−
0
View file @
a522e3aa
...
...
@@ -23,6 +23,12 @@ Install the requirements.
apt install python3 python3-dev python3-setuptools python3-pip libacl1-dev libkrb5-dev
```
Optional packages:
```
apt install python3-venv
```
### git / pip
**Recommended**
install from a clean venv (may be needed if you have any conflicting outdated modules installed as packages):
...
...
This diff is collapsed.
Click to expand it.
bin/showgroup.py
+
25
−
7
View file @
a522e3aa
...
...
@@ -20,13 +20,20 @@ NOOPTS = collections.OrderedDict()
NOOPTS
[
'
no-member
'
]
=
'
memberUid
'
NOOPTS
[
'
no-gid
'
]
=
'
gidNumber
'
NOOPTS
[
'
no-owner
'
]
=
'
owner
'
NOOPTS
[
'
no-uid
'
]
=
'
uidNumber
'
NOOPTS
[
'
no-name
'
]
=
'
gecos
'
def
main
():
description
=
'
Show groups or group members
'
arg
=
'
group
'
arg_help
=
'
The group name (cn), or wildcards (*, cn* , *cn*)
'
args
=
argparser
.
simple
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
OPTS
,
noopts
=
NOOPTS
)
parser
=
argparser
.
extendable
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
OPTS
,
noopts
=
NOOPTS
)
parser
.
add_argument
(
'
--uids
'
,
dest
=
'
uid_only
'
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show uids only
'
)
parser
.
add_argument
(
'
--names
'
,
dest
=
'
name_only
'
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show real names only
'
)
args
=
vars
(
parser
.
parse_args
())
ldap
=
dphysldap
.
Ldap
()
...
...
@@ -50,23 +57,34 @@ def main():
group
=
groups
[
0
]
members
=
group
[
'
memberUid
'
]
print
(
'
Group {} ({}):
'
.
format
(
group
[
'
cn
'
],
group
[
'
gidNumber
'
]))
print
(
'
Owner: {}
'
.
format
(
group
[
'
owner
'
]))
print
(
'
Report: {}
'
.
format
(
group
[
'
reportEnabled
'
]))
print
(
'
Reported to: {}
'
.
format
(
group
[
'
reportUid
'
]))
if
not
args
[
'
name_only
'
]
and
not
args
[
'
uid_only
'
]:
print
(
'
Group {} ({}):
'
.
format
(
group
[
'
cn
'
],
group
[
'
gidNumber
'
]))
print
(
'
Owner: {}
'
.
format
(
group
[
'
owner
'
]))
print
(
'
Report: {}
'
.
format
(
group
[
'
reportEnabled
'
]))
print
(
'
Reported to: {}
'
.
format
(
group
[
'
reportUid
'
]))
if
members
:
del
OPTS
[
'
report
'
]
attrs
=
[
'
uid
'
,
'
uidNumber
'
,
'
gecos
'
]
attrs
.
extend
([
v
for
k
,
v
in
OPTS
.
items
()
if
args
[
k
]])
for
attr
in
[
v
for
k
,
v
in
NOOPTS
.
items
()
if
args
[
k
]]:
if
attr
in
attrs
:
attrs
.
remove
(
attr
)
users
=
dphysldap
.
Users
(
ldap
,
attrs
)
users
.
search
(
'
;
'
.
join
(
members
))
users
.
sort
(
'
uid
'
)
print
(
'
Members:
'
)
print
(
users
)
if
args
[
'
uid_only
'
]:
for
user
in
users
:
print
(
user
[
'
uid
'
])
elif
args
[
'
name_only
'
]:
for
user
in
users
:
print
(
user
[
'
gecos
'
])
else
:
print
(
'
Members:
'
)
print
(
users
)
else
:
print
(
'
Members: none
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/isg/argparser.py
+
30
−
8
View file @
a522e3aa
...
...
@@ -2,9 +2,10 @@
import
argparse
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
def
extendable
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
"""
Get
cmd argument with
simplified argparser
Get
extendable
simplified argparser
"""
parser
=
argparse
.
ArgumentParser
(
add_help
=
False
,
description
=
description
)
...
...
@@ -15,18 +16,39 @@ def simple(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
for
k
,
v
in
opts
.
items
():
if
isinstance
(
v
,
list
):
v
=
'
,
'
.
join
(
v
)
parser
.
add_argument
(
'
-
'
+
k
[:
1
],
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
try
:
parser
.
add_argument
(
'
-
'
+
k
[:
1
],
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
except
argparse
.
ArgumentError
:
parser
.
add_argument
(
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
for
k
,
v
in
noopts
.
items
():
if
isinstance
(
v
,
list
):
v
=
'
,
'
.
join
(
v
)
parser
.
add_argument
(
'
-
'
+
k
[
3
:
4
].
upper
(),
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
try
:
parser
.
add_argument
(
'
-
'
+
k
[
3
:
4
].
upper
(),
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
except
argparse
.
ArgumentError
:
parser
.
add_argument
(
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
parser
.
add_argument
(
'
--help
'
,
action
=
'
help
'
,
help
=
'
Show this help message and exit
'
)
return
parser
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
"""
Get cmd argument with simplified argparser
"""
parser
=
extendable
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
opts
,
noopts
=
noopts
)
return
vars
(
parser
.
parse_args
())
This diff is collapsed.
Click to expand it.
lib/isg/dphysldap.py
+
1
−
1
View file @
a522e3aa
...
...
@@ -60,7 +60,7 @@ class Entry(collections.abc.MutableMapping):
def
__len__
(
self
):
return
len
(
self
.
_dict
)
def
__str__
(
self
):
"""
Modifies the
"
informal
"
string value of str(x) or print(x)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment