Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mailman-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
irt-public
mailman-tools
Commits
873c3871
Commit
873c3871
authored
6 years ago
by
Conrad Holmberg
Browse files
Options
Downloads
Patches
Plain Diff
Added proper json infomation of user.
parent
d26de76a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
manage_users.py
+34
-28
34 additions, 28 deletions
manage_users.py
with
34 additions
and
28 deletions
manage_users.py
+
34
−
28
View file @
873c3871
...
...
@@ -10,30 +10,32 @@ except ImportError:
import
simplejson
as
json
# Get the entire email list
def
get_
email
_
list
s
(
email_lists
):
def
get_ml_fqdns
(
ml_fqdns
):
"""
Get the entire
email
list
members
"""
members
=
''
for
email_list
in
email_list
s
:
members
+=
email_list
+
"
\n
"
for
ml_fqdn
in
ml_fqdn
s
:
members
+=
ml_fqdn
+
"
\n
"
return
members
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Manage Users in Mailman Email Lists.
"
)
CORE_URI
=
os
.
environ
.
get
(
'
MAILMAN_CORE_URI
'
,
'
http://mailman-core:8001/3.1
'
)
CORE_URI
=
os
.
environ
.
get
(
'
MAILMAN_CORE_URI
'
,
'
http://mailman-core:8001/3.1
'
)
CORE_USER
=
os
.
environ
.
get
(
'
MAILMAN_REST_USER
'
,
'
restadmin
'
)
CORE_PASS
=
os
.
environ
.
get
(
'
MAILMAN_REST_PASSWORD
'
,
'
restpass
'
)
LIST_NAME
=
'
apachesvn@lists.med.stanford.edu
'
# just a tesing default
# user invoked variables
parser
.
add_argument
(
'
--list_fqdn
'
,
default
=
LIST_NAME
)
parser
.
add_argument
(
'
-r
'
,
'
--restore
'
)
# Add arguments for env variables
parser
.
add_argument
(
'
--core-uri
'
,
dest
=
'
core_uri
'
,
default
=
CORE_URI
)
parser
.
add_argument
(
'
--rest-user
'
,
dest
=
'
core_user
'
,
default
=
CORE_USER
)
parser
.
add_argument
(
'
--rest-password
'
,
dest
=
'
core_password
'
,
default
=
CORE_PASS
)
# Default Email list
LIST_NAME
=
'
apachesvn@lists.med.stanford.edu
'
# Parse out the command line arguments
args
=
parser
.
parse_args
()
...
...
@@ -41,37 +43,43 @@ if __name__ == '__main__':
client
=
Client
(
args
.
core_uri
,
args
.
core_user
,
args
.
core_password
)
# append the mail lists to an array from client
email_list
s
=
[]
ml_fqdn
s
=
[]
for
mlist
in
client
.
lists
:
email_list
s
.
append
(
mlist
.
fqdn_listname
)
ml_fqdn
s
.
append
(
mlist
.
fqdn_listname
)
# lists members of a list
if
args
.
list_fqdn
:
# used to store members
members_hash
=
{}
# obtain email list from argument
email_list
=
args
.
list_fqdn
ml_fqdn
=
args
.
list_fqdn
# get lists
if
email_list
in
email_list
s
:
#member_list = client.get_list(LIST_NAME)
if
ml_fqdn
in
ml_fqdn
s
:
# Get members from email list
member_list
=
client
.
get_list
(
email_list
)
member_list
=
client
.
get_list
(
ml_fqdn
)
members_hash
=
{}
# Get json data from each member
for
member
in
member_list
.
members
:
# members_hash['user']=member.user
# members_hash['user']=member.user
#members_hash['address']= member.address
#members_hash['list_id']= member.list_id
#members_hash['email']= member.email
members_hash
[
'
address
'
]
=
member
.
address
.
rest_data
members_hash
[
'
list_fqdn
'
]
=
args
.
list_fqdn
members_hash
[
'
email
'
]
=
member
.
email
members_hash
[
'
display_name
'
]
=
member
.
user
.
display_name
#held_data[held.request_id] = held.rest_data
#members_hash['preferences']= member.preferences
#print "S###########################"
#print json.dumps(member.rest_data, indent=2)
#print json.dumps(member.user.rest_data, indent=2)
print
json
.
dumps
(
members_hash
,
indent
=
2
)
# Get all the member
elif
email_list
.
upper
()
==
'
ALL
'
:
print
"
I couldn
'
t get this to finsih!!!.
"
#print "E###########################"
#print("debug"+str(member))
# Get all the members
elif
ml_fqdn
.
upper
()
==
'
ALL
'
:
members_hash
=
{}
# grabs users per page
page
=
client
.
get_user_page
(
count
=
100
,
page
=
1
)
...
...
@@ -81,15 +89,13 @@ if __name__ == '__main__':
for
member
in
page
:
print
json
.
dumps
(
member
.
addresses
.
rest_data
,
indent
=
2
)
time
.
sleep
(.
100
)
#pause between pages
page
=
page
.
next
# # Get json data from each member
# for member in client.members:
# members_hash['email']= member.email
# print json.dumps(members_hash, indent=2)
else
:
sys
.
exit
(
'
Error: Email list
"'
+
email_list
+
'"
does not exist in domain
'
+
args
.
core_uri
+
"
\n
See List
\n
"
+
get_email_lists
(
email_lists
))
sys
.
exit
(
'
Error: Email list
"'
+
ml_fqdn
+
'"
does not exist in domain
'
+
args
.
core_uri
+
"
\n
See List
\n
"
+
get_ml_fqdns
(
ml_fqdns
))
elif
args
.
restore
:
if
args
.
list
==
'
-
'
:
list_file
=
sys
.
stdin
else
:
list_file
=
open
(
args
.
list
,
'
r
'
)
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