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
9b0e4c6f
Commit
9b0e4c6f
authored
7 years ago
by
Sven Mäder
Browse files
Options
Downloads
Plain Diff
Merge branch 'local-rda' into 'master'
Local rda See merge request core/python!11
parents
ebe828dd
b8325cd7
No related branches found
No related tags found
1 merge request
!11
Local rda
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/showgroup.py
+7
-1
7 additions, 1 deletion
bin/showgroup.py
lib/isg/argparser.py
+8
-1
8 additions, 1 deletion
lib/isg/argparser.py
lib/isg/dphysldap.py
+33
-27
33 additions, 27 deletions
lib/isg/dphysldap.py
with
48 additions
and
29 deletions
bin/showgroup.py
+
7
−
1
View file @
9b0e4c6f
...
@@ -16,12 +16,17 @@ OPTS['report'] = ['reportEnabled', 'reportUid']
...
@@ -16,12 +16,17 @@ OPTS['report'] = ['reportEnabled', 'reportUid']
OPTS
[
'
mail
'
]
=
'
mail
'
OPTS
[
'
mail
'
]
=
'
mail
'
OPTS
[
'
telephone
'
]
=
'
telephoneNumber
'
OPTS
[
'
telephone
'
]
=
'
telephoneNumber
'
NOOPTS
=
collections
.
OrderedDict
()
NOOPTS
[
'
no-member
'
]
=
'
memberUid
'
NOOPTS
[
'
no-gid
'
]
=
'
gidNumber
'
NOOPTS
[
'
no-owner
'
]
=
'
owner
'
def
main
():
def
main
():
description
=
'
Show groups or group members
'
description
=
'
Show groups or group members
'
arg
=
'
group
'
arg
=
'
group
'
arg_help
=
'
The group name (cn), or wildcards (*, cn* , *cn*)
'
arg_help
=
'
The group name (cn), or wildcards (*, cn* , *cn*)
'
args
=
argparser
.
simple
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
OPTS
)
args
=
argparser
.
simple
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
OPTS
,
noopts
=
NOOPTS
)
ldap
=
dphysldap
.
Ldap
()
ldap
=
dphysldap
.
Ldap
()
...
@@ -38,6 +43,7 @@ def main():
...
@@ -38,6 +43,7 @@ def main():
if
len
(
groups
)
!=
1
:
if
len
(
groups
)
!=
1
:
#groups.sort('cn')
#groups.sort('cn')
groups
.
remove_attrs
([
v
for
k
,
v
in
NOOPTS
.
items
()
if
args
[
k
]])
print
(
groups
)
print
(
groups
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
lib/isg/argparser.py
+
8
−
1
View file @
9b0e4c6f
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
argparse
import
argparse
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
()):
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
()
,
noopts
=
dict
()
):
"""
"""
Get cmd argument with simplified argparser
Get cmd argument with simplified argparser
"""
"""
...
@@ -19,6 +19,13 @@ def simple(description, arg=None, arg_help='', opts=dict()):
...
@@ -19,6 +19,13 @@ def simple(description, arg=None, arg_help='', opts=dict()):
action
=
'
store_const
'
,
const
=
True
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
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
)
parser
.
add_argument
(
'
--help
'
,
action
=
'
help
'
,
parser
.
add_argument
(
'
--help
'
,
action
=
'
help
'
,
help
=
'
Show this help message and exit
'
)
help
=
'
Show this help message and exit
'
)
...
...
This diff is collapsed.
Click to expand it.
lib/isg/dphysldap.py
+
33
−
27
View file @
9b0e4c6f
...
@@ -143,34 +143,57 @@ class Ldap(object):
...
@@ -143,34 +143,57 @@ class Ldap(object):
return
[
Group
(
e
)
for
e
in
entries
]
return
[
Group
(
e
)
for
e
in
entries
]
class
Group
s
(
list
):
class
Entrie
s
(
list
):
"""
"""
Abstraction class for
Group
s imitating list
Abstraction class for
Entrie
s imitating list
"""
"""
def
__init__
(
self
,
ldap
,
attrs
,
*
args
):
def
__init__
(
self
,
ldap
,
attrs
,
*
args
):
list
.
__init__
(
self
,
*
args
)
list
.
__init__
(
self
,
*
args
)
self
.
_ldap
=
ldap
self
.
_ldap
=
ldap
self
.
_
attrs
=
attrs
self
.
attrs
=
attrs
def
__str__
(
self
):
def
__str__
(
self
):
"""
"""
Modifies the
"
informal
"
string value of str(x) or print(x)
Modifies the
"
informal
"
string value of str(x) or print(x)
to return
group
s in tabulated form
to return
entrie
s in tabulated form
"""
"""
headers
=
self
.
_attrs
table
=
[[
e
[
a
]
for
a
in
self
.
attrs
]
for
e
in
self
]
table
=
[[
g
[
h
]
for
h
in
headers
]
for
g
in
self
]
return
tabulate
.
tabulate
(
table
,
tablefmt
=
FMT
,
headers
=
self
.
attrs
)
return
tabulate
.
tabulate
(
table
,
tablefmt
=
FMT
,
headers
=
headers
)
#def sort(self, attr):
#def sort(self, attr):
# self = sorted(self, key=lambda k: k[attr].__str__())
# self = sorted(self, key=lambda k: k[attr].__str__())
def
remove_attr
(
self
,
attr
):
if
attr
in
self
.
attrs
:
self
.
attrs
.
remove
(
attr
)
def
remove_attrs
(
self
,
attrs
):
if
isinstance
(
attrs
,
list
):
for
attr
in
attrs
:
self
.
remove_attr
(
attr
)
else
:
self
.
remove_attr
(
attrs
)
def
search
(
self
,
query
):
"""
Query syntax: `<attributeName>: <attributeValue(s)>`
AttributeValue: `a`, `a*`, `*a*`, `a;b`
"""
self
.
clear
()
self
.
extend
(
self
.
_ldap
.
get_entries
(
query
=
query
,
attributes
=
self
.
attrs
))
class
Groups
(
Entries
):
"""
Abstraction class for Groups imitating list
"""
def
search
(
self
,
cn
):
def
search
(
self
,
cn
):
"""
"""
Search example: `cn`, `cn*`, `*cn*`, `cn1;cn2`
Search example: `cn`, `cn*`, `*cn*`, `cn1;cn2`
"""
"""
query
=
'
cn: {0}
'
.
format
(
cn
)
query
=
'
cn: {0}
'
.
format
(
cn
)
self
.
clear
()
self
.
clear
()
self
.
extend
(
self
.
_ldap
.
get_groups
(
query
=
query
,
attributes
=
self
.
_
attrs
))
self
.
extend
(
self
.
_ldap
.
get_groups
(
query
=
query
,
attributes
=
self
.
attrs
))
def
members
(
self
,
index
=
None
):
def
members
(
self
,
index
=
None
):
"""
"""
...
@@ -185,31 +208,14 @@ class Groups(list):
...
@@ -185,31 +208,14 @@ class Groups(list):
return
self
[
index
][
'
memberUid
'
]
return
self
[
index
][
'
memberUid
'
]
class
Users
(
list
):
class
Users
(
Entries
):
"""
"""
Abstraction class for Users imitating list
Abstraction class for Users imitating list
"""
"""
def
__init__
(
self
,
ldap
,
attrs
,
*
args
):
list
.
__init__
(
self
,
*
args
)
self
.
_ldap
=
ldap
self
.
_attrs
=
attrs
def
__str__
(
self
):
"""
Modifies the
"
informal
"
string value of str(x) or print(x)
to return users in tabulated form
"""
headers
=
self
.
_attrs
table
=
[[
u
[
h
]
for
h
in
headers
]
for
u
in
self
]
return
tabulate
.
tabulate
(
table
,
tablefmt
=
FMT
,
headers
=
self
.
_attrs
)
#def sort(self, attr):
# self = sorted(self, key=lambda d: d[attr].__str__())
def
search
(
self
,
uid
):
def
search
(
self
,
uid
):
"""
"""
Search example: `uid`, `uid*`, `*uid*`, `uid1;uid2`
Search example: `uid`, `uid*`, `*uid*`, `uid1;uid2`
"""
"""
query
=
'
uid: {0}
'
.
format
(
uid
)
query
=
'
uid: {0}
'
.
format
(
uid
)
self
.
clear
()
self
.
clear
()
self
.
extend
(
self
.
_ldap
.
get_users
(
query
=
query
,
attributes
=
self
.
_
attrs
))
self
.
extend
(
self
.
_ldap
.
get_users
(
query
=
query
,
attributes
=
self
.
attrs
))
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