# HG changeset patch # User Paul Boddie # Date 1374169819 -7200 # Node ID 0e81518285db56888a9eea51cbb28955fbab26aa # Parent db03adb5f2e3c4066606a1da5c0e0a81f5d8c681 Split the profile retrieval and user creation activities into separate programs. diff -r db03adb5f2e3 -r 0e81518285db README.txt --- a/README.txt Thu Jul 18 19:24:46 2013 +0200 +++ b/README.txt Thu Jul 18 19:50:19 2013 +0200 @@ -147,19 +147,37 @@ tools/users.sh COM DEV DOC SEC -This output can be edited and then passed to a special user administration -program as follows: +This output can be edited and then passed to a program which fetches other +profile details as follows: tools/users.sh COM DEV DOC SEC > users.txt # for editing -cat users.txt | tools/addusers.py wiki http://wiki.list.org/ +cat users.txt | tools/get_profiles.py http://wiki.list.org/ If no users are to be removed in migration, the following command could be issued: -tools/users.sh COM DEV DOC SEC | tools/addusers.py wiki http://wiki.list.org/ +tools/users.sh COM DEV DOC SEC | tools/get_profiles.py http://wiki.list.org/ + +The get_profiles.py program needs to be told the URL of the original +Confluence site. Note that it accesses the site at a default rate of around +one request per second; a different delay between requests can be specified +using an additional argument. + +The output of the get_profiles.py program can be passed to another program +which adds users to MoinMoin, and so the following commands can be used: + + cat users.txt \ +| tools/get_profiles.py http://wiki.list.org/ \ +| tools/addusers.py wiki + +And using one single command: + + tools/users.sh COM DEV DOC SEC \ +| tools/get_profiles.py http://wiki.list.org/ \ +| tools/addusers.py wiki The addusers.py program needs to be told the directory containing the wiki -configuration as well as the URL of the original Confluence site. +configuration. Output Structure ---------------- diff -r db03adb5f2e3 -r 0e81518285db tools/addusers.py --- a/tools/addusers.py Thu Jul 18 19:24:46 2013 +0200 +++ b/tools/addusers.py Thu Jul 18 19:50:19 2013 +0200 @@ -1,8 +1,12 @@ #!/usr/bin/env python """ -Add users to a MoinMoin wiki, fetching the profile of each user from a -Confluence site in order to obtain name and e-mail details. +Add users to a MoinMoin wiki. + +User details are read from standard input as a tab-separated sequence using the +following format: + +USERNAME FULLNAME EMAIL IMAGE-URL User details are written to standard output in a tab-separated sequence using the following format: @@ -10,17 +14,11 @@ USERNAME FULLNAME EMAIL IMAGE-URL PASSWORD """ -from time import sleep from os.path import split from subprocess import call import random, string import sys -this_dir = split(sys.argv[0])[0] -sys.path.append(this_dir) - -from get_profile import get_profile - def randompass(): return "".join(random.sample(string.ascii_letters, 10)) @@ -37,23 +35,19 @@ try: wiki = sys.argv[1] - url = sys.argv[2] - delay = int((sys.argv[3:4] or ["1"])[0]) except (IndexError, ValueError): - print >>sys.stderr, "%s [ ]" % progname + print >>sys.stderr, "%s " % progname print >>sys.stderr - print >>sys.stderr, "Example: %s wiki http://wiki.list.org/" % progname + print >>sys.stderr, "Example: %s wiki" % progname sys.exit(1) line = sys.stdin.readline() while line: - username = line.strip() - username, fullname, email, image = get_profile(url, username) + username, fullname, email, image = line.strip("\n ").split("\t") password = randompass() add_user(wiki, username, fullname, email, password) print "\t".join([username, fullname, email, image, password]) - sleep(delay) line = sys.stdin.readline() if __name__ == "__main__": diff -r db03adb5f2e3 -r 0e81518285db tools/get_profiles.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/get_profiles.py Thu Jul 18 19:50:19 2013 +0200 @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +""" +Fetching the profile of each user from a Confluence site in order to obtain +name and e-mail details. + +User details are written to standard output in a tab-separated sequence using +the following format: + +USERNAME FULLNAME EMAIL IMAGE-URL +""" + +from time import sleep +from os.path import split +import sys + +this_dir = split(sys.argv[0])[0] +sys.path.append(this_dir) + +from get_profile import get_profile + +def main(): + progname = split(sys.argv[0])[-1] + + try: + url = sys.argv[1] + delay = int((sys.argv[2:3] or ["1"])[0]) + except (IndexError, ValueError): + print >>sys.stderr, "%s [ ]" % progname + print >>sys.stderr + print >>sys.stderr, "Example: %s http://wiki.list.org/" % progname + sys.exit(1) + + line = sys.stdin.readline() + while line: + username = line.strip() + print "\t".join(get_profile(url, username)) + + sleep(delay) + line = sys.stdin.readline() + +if __name__ == "__main__": + main() + +# vim: tabstop=4 expandtab shiftwidth=4