1.1 --- a/README.txt Thu Jul 18 19:24:46 2013 +0200
1.2 +++ b/README.txt Thu Jul 18 19:50:19 2013 +0200
1.3 @@ -147,19 +147,37 @@
1.4
1.5 tools/users.sh COM DEV DOC SEC
1.6
1.7 -This output can be edited and then passed to a special user administration
1.8 -program as follows:
1.9 +This output can be edited and then passed to a program which fetches other
1.10 +profile details as follows:
1.11
1.12 tools/users.sh COM DEV DOC SEC > users.txt # for editing
1.13 -cat users.txt | tools/addusers.py wiki http://wiki.list.org/
1.14 +cat users.txt | tools/get_profiles.py http://wiki.list.org/
1.15
1.16 If no users are to be removed in migration, the following command could be
1.17 issued:
1.18
1.19 -tools/users.sh COM DEV DOC SEC | tools/addusers.py wiki http://wiki.list.org/
1.20 +tools/users.sh COM DEV DOC SEC | tools/get_profiles.py http://wiki.list.org/
1.21 +
1.22 +The get_profiles.py program needs to be told the URL of the original
1.23 +Confluence site. Note that it accesses the site at a default rate of around
1.24 +one request per second; a different delay between requests can be specified
1.25 +using an additional argument.
1.26 +
1.27 +The output of the get_profiles.py program can be passed to another program
1.28 +which adds users to MoinMoin, and so the following commands can be used:
1.29 +
1.30 + cat users.txt \
1.31 +| tools/get_profiles.py http://wiki.list.org/ \
1.32 +| tools/addusers.py wiki
1.33 +
1.34 +And using one single command:
1.35 +
1.36 + tools/users.sh COM DEV DOC SEC \
1.37 +| tools/get_profiles.py http://wiki.list.org/ \
1.38 +| tools/addusers.py wiki
1.39
1.40 The addusers.py program needs to be told the directory containing the wiki
1.41 -configuration as well as the URL of the original Confluence site.
1.42 +configuration.
1.43
1.44 Output Structure
1.45 ----------------
2.1 --- a/tools/addusers.py Thu Jul 18 19:24:46 2013 +0200
2.2 +++ b/tools/addusers.py Thu Jul 18 19:50:19 2013 +0200
2.3 @@ -1,8 +1,12 @@
2.4 #!/usr/bin/env python
2.5
2.6 """
2.7 -Add users to a MoinMoin wiki, fetching the profile of each user from a
2.8 -Confluence site in order to obtain name and e-mail details.
2.9 +Add users to a MoinMoin wiki.
2.10 +
2.11 +User details are read from standard input as a tab-separated sequence using the
2.12 +following format:
2.13 +
2.14 +USERNAME FULLNAME EMAIL IMAGE-URL
2.15
2.16 User details are written to standard output in a tab-separated sequence using
2.17 the following format:
2.18 @@ -10,17 +14,11 @@
2.19 USERNAME FULLNAME EMAIL IMAGE-URL PASSWORD
2.20 """
2.21
2.22 -from time import sleep
2.23 from os.path import split
2.24 from subprocess import call
2.25 import random, string
2.26 import sys
2.27
2.28 -this_dir = split(sys.argv[0])[0]
2.29 -sys.path.append(this_dir)
2.30 -
2.31 -from get_profile import get_profile
2.32 -
2.33 def randompass():
2.34 return "".join(random.sample(string.ascii_letters, 10))
2.35
2.36 @@ -37,23 +35,19 @@
2.37
2.38 try:
2.39 wiki = sys.argv[1]
2.40 - url = sys.argv[2]
2.41 - delay = int((sys.argv[3:4] or ["1"])[0])
2.42 except (IndexError, ValueError):
2.43 - print >>sys.stderr, "%s <wiki configuration directory> <wiki URL> [ <retrieval delay> ]" % progname
2.44 + print >>sys.stderr, "%s <wiki configuration directory>" % progname
2.45 print >>sys.stderr
2.46 - print >>sys.stderr, "Example: %s wiki http://wiki.list.org/" % progname
2.47 + print >>sys.stderr, "Example: %s wiki" % progname
2.48 sys.exit(1)
2.49
2.50 line = sys.stdin.readline()
2.51 while line:
2.52 - username = line.strip()
2.53 - username, fullname, email, image = get_profile(url, username)
2.54 + username, fullname, email, image = line.strip("\n ").split("\t")
2.55 password = randompass()
2.56 add_user(wiki, username, fullname, email, password)
2.57 print "\t".join([username, fullname, email, image, password])
2.58
2.59 - sleep(delay)
2.60 line = sys.stdin.readline()
2.61
2.62 if __name__ == "__main__":
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tools/get_profiles.py Thu Jul 18 19:50:19 2013 +0200
3.3 @@ -0,0 +1,45 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +Fetching the profile of each user from a Confluence site in order to obtain
3.8 +name and e-mail details.
3.9 +
3.10 +User details are written to standard output in a tab-separated sequence using
3.11 +the following format:
3.12 +
3.13 +USERNAME FULLNAME EMAIL IMAGE-URL
3.14 +"""
3.15 +
3.16 +from time import sleep
3.17 +from os.path import split
3.18 +import sys
3.19 +
3.20 +this_dir = split(sys.argv[0])[0]
3.21 +sys.path.append(this_dir)
3.22 +
3.23 +from get_profile import get_profile
3.24 +
3.25 +def main():
3.26 + progname = split(sys.argv[0])[-1]
3.27 +
3.28 + try:
3.29 + url = sys.argv[1]
3.30 + delay = int((sys.argv[2:3] or ["1"])[0])
3.31 + except (IndexError, ValueError):
3.32 + print >>sys.stderr, "%s <wiki URL> [ <retrieval delay> ]" % progname
3.33 + print >>sys.stderr
3.34 + print >>sys.stderr, "Example: %s http://wiki.list.org/" % progname
3.35 + sys.exit(1)
3.36 +
3.37 + line = sys.stdin.readline()
3.38 + while line:
3.39 + username = line.strip()
3.40 + print "\t".join(get_profile(url, username))
3.41 +
3.42 + sleep(delay)
3.43 + line = sys.stdin.readline()
3.44 +
3.45 +if __name__ == "__main__":
3.46 + main()
3.47 +
3.48 +# vim: tabstop=4 expandtab shiftwidth=4