|
a/scripts/allura_import.py |
|
b/scripts/allura_import.py |
|
... |
|
... |
8 |
import json
|
8 |
import json
|
9 |
from optparse import OptionParser
|
9 |
from optparse import OptionParser
|
10 |
from pprint import pprint
|
10 |
from pprint import pprint
|
11 |
from datetime import datetime
|
11 |
from datetime import datetime
|
12 |
|
12 |
|
|
|
13 |
import os.path
|
|
|
14 |
scriptDir=os.path.dirname(__file__)
|
|
|
15 |
sys.path.append(os.path.join(scriptDir, '..', 'Allura'))
|
13 |
from allura.lib.import_api import AlluraImportApiClient
|
16 |
from allura.lib.import_api import AlluraImportApiClient
|
14 |
|
17 |
|
15 |
|
18 |
|
16 |
def main():
|
19 |
def main():
|
17 |
optparser, options, args = parse_options()
|
20 |
optparser, options, args = parse_options()
|
|
... |
|
... |
44 |
cli = AlluraImportApiClient(options.base_url, options.api_key, options.secret_key, options.verbose)
|
47 |
cli = AlluraImportApiClient(options.base_url, options.api_key, options.secret_key, options.verbose)
|
45 |
doc_txt = open(args[0]).read()
|
48 |
doc_txt = open(args[0]).read()
|
46 |
|
49 |
|
47 |
# import the tracker (if any)
|
50 |
# import the tracker (if any)
|
48 |
if options.tracker:
|
51 |
if options.tracker:
|
49 |
import_tracker(cli, options.project, options.tracker, import_options, doc_txt,
|
52 |
import_tracker(cli, options.project, options.tracker, import_options, options, doc_txt,
|
50 |
validate=options.validate,
|
53 |
validate=options.validate,
|
51 |
verbose=options.verbose)
|
54 |
verbose=options.verbose)
|
52 |
elif options.forum:
|
55 |
elif options.forum:
|
53 |
import_forum(cli, options.project, options.forum, user_map, doc_txt, validate=options.validate)
|
56 |
import_forum(cli, options.project, options.forum, user_map, doc_txt, validate=options.validate)
|
54 |
|
57 |
|
55 |
def import_tracker(cli, project, tool, import_options, doc_txt, validate=True, verbose=False):
|
58 |
def import_tracker(cli, project, tool, import_options, options, doc_txt, validate=True, verbose=False):
|
56 |
url = '/rest/p/' + project + '/' + tool
|
59 |
url = '/rest/p/' + project + '/' + tool
|
57 |
if validate:
|
60 |
if validate:
|
58 |
url += '/validate_import'
|
61 |
url += '/validate_import'
|
59 |
else:
|
62 |
else:
|
60 |
url += '/perform_import'
|
63 |
url += '/perform_import'
|
|
... |
|
... |
106 |
optparser.add_option('-u', '--base-url', dest='base_url', default='https://sourceforge.net', help='Base Allura URL (%default)')
|
109 |
optparser.add_option('-u', '--base-url', dest='base_url', default='https://sourceforge.net', help='Base Allura URL (%default)')
|
107 |
optparser.add_option('-o', dest='import_opts', default=[], action='append', help='Specify import option(s)', metavar='opt=val')
|
110 |
optparser.add_option('-o', dest='import_opts', default=[], action='append', help='Specify import option(s)', metavar='opt=val')
|
108 |
optparser.add_option('--user-map', dest='user_map_file', help='Map original users to SF.net users', metavar='JSON_FILE')
|
111 |
optparser.add_option('--user-map', dest='user_map_file', help='Map original users to SF.net users', metavar='JSON_FILE')
|
109 |
optparser.add_option('--validate', dest='validate', action='store_true', help='Validate import data')
|
112 |
optparser.add_option('--validate', dest='validate', action='store_true', help='Validate import data')
|
110 |
optparser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose operation')
|
113 |
optparser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose operation')
|
|
|
114 |
optparser.add_option('-c', '--continue', dest='cont', action='store_true', help='Continue import into existing tracker')
|
111 |
options, args = optparser.parse_args()
|
115 |
options, args = optparser.parse_args()
|
112 |
if len(args) != 1:
|
116 |
if len(args) != 1:
|
113 |
optparser.error("Wrong number of arguments")
|
117 |
optparser.error("Wrong number of arguments")
|
114 |
if not options.api_key or not options.secret_key:
|
118 |
if not options.api_key or not options.secret_key:
|
115 |
optparser.error("Keys are required")
|
119 |
optparser.error("Keys are required")
|
|
... |
|
... |
118 |
return optparser, options, args
|
122 |
return optparser, options, args
|
119 |
|
123 |
|
120 |
|
124 |
|
121 |
if __name__ == '__main__':
|
125 |
if __name__ == '__main__':
|
122 |
main()
|
126 |
main()
|
|
|
127 |
|