summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@wlan-5-141.nay.redhat.com>2011-07-15 15:07:52 +0800
committerroot <root@wlan-5-141.nay.redhat.com>2011-07-15 15:07:52 +0800
commit7edde074de69f6d65677cc24f37234dd1ab1ebe4 (patch)
tree47a640ff8f69fabf7ecf6b62404d0c267b7f0e88
parenta69dc47796390b0238fb105686b4a587bc25ce8e (diff)
downloadrepo-7edde074de69f6d65677cc24f37234dd1ab1ebe4.tar.gz
repo-7edde074de69f6d65677cc24f37234dd1ab1ebe4.tar.xz
repo-7edde074de69f6d65677cc24f37234dd1ab1ebe4.zip
support generating more than one tag and support converting all the test cases in a given page to a nitrate xml fileHEADmaster
-rwxr-xr-xwiki_to_nitrate_xml.py48
1 files changed, 39 insertions, 9 deletions
diff --git a/wiki_to_nitrate_xml.py b/wiki_to_nitrate_xml.py
index b9d36d1..81c9b3a 100755
--- a/wiki_to_nitrate_xml.py
+++ b/wiki_to_nitrate_xml.py
@@ -26,24 +26,31 @@ def parse_args():
parser.add_option('--url', action='store', default='https://fedoraproject.org/w/api.php',
help='API URL')
- #general
+ # general
optgrp = optparse.OptionGroup(parser, "General options")
optgrp.add_option('-l', '--limit', action='store', default=5, type="int",
help='Limit recursion depth (%default)')
parser.add_option_group(optgrp)
- # list_categorymembers
+ # categorymembers(test cases) migration
optgrp = optparse.OptionGroup(parser, "Options for 'categorymembers' command:")
optgrp.add_option('-c', '--category', dest="categories",
default=[], action="append",
- help='Wiki category name to covert all its members to Nitrate xml file')
+ help='Wiki category name to covert all its members(test cases) to Nitrate xml file')
parser.add_option_group(optgrp)
- # migration
+ # single test case migration
optgrp = optparse.OptionGroup(parser, "Options for 'migration':")
optgrp.add_option('-t', '--title',
default='', action='store',
- help='Page title to convert the test case to Nitrate xml file')
+ help='Page title to convert this test case to Nitrate xml file')
+ parser.add_option_group(optgrp)
+
+ # page links(test cases) migration
+ optgrp = optparse.OptionGroup(parser, "Options for 'pagelinks':")
+ optgrp.add_option('-p', '--page',
+ default='', action='store',
+ help='Page name to convert all its links(test cases) to Nitrate xml file')
parser.add_option_group(optgrp)
(opts, args) = parser.parse_args()
@@ -60,6 +67,9 @@ def parse_args():
elif action == 'migration':
if opts.title == '':
parser.error("Must specify a page (-t|--title)")
+ elif action == 'pagelinks':
+ if opts.page == '':
+ parser.error("Must specify a page (-p|--page)")
return (opts, action)
@@ -73,6 +83,20 @@ def parse(wiki, page):
if opts.debug: print response
return response.get('parse',{})
+
+def return_links(wiki, page, limit=200):
+ '''Return all links with 'QA:' namespace from the given page'''
+ query = dict(action='query',
+ titles=page,
+ prop='links',
+ pllimit=limit,
+ plnamespace=104)
+ if opts.debug: print query
+ response = wiki.call(query)
+ for page in response.get('query',{}).get('pages',{}):
+ links = [entry.get('title') for entry in response.get('query',{}).get('pages',{}).get(page,{}).get('links',{}) if entry.has_key('title')]
+ return links
+
def list_categorymembers(wiki, cat_page, limit=5):
'''Return a list of pages belonging to category page'''
# Add 'Category:' prefix if not given
@@ -85,7 +109,6 @@ def list_categorymembers(wiki, cat_page, limit=5):
cmtitle=cat_page)
if opts.debug: print query
response = wiki.call(query)
-
members = [entry.get('title') for entry in response.get('query',{}).get('categorymembers',{}) if entry.has_key('title')]
# Determine whether we need to recurse
@@ -156,8 +179,9 @@ def nitrate_xml(table):
title = ET.SubElement(head, "setup")
title.text = str(table['setup'])
title = ET.SubElement(head, "breakdown")
- title = ET.SubElement(head, "tag")
- title.text = str(table['tag'][0])
+ for tag in table['tag']:
+ title = ET.SubElement(head, "tag")
+ title.text = str(tag)
return head
def write_to_file(xmlcases):
@@ -186,7 +210,10 @@ if __name__ == "__main__":
print "\n".join(pages)
else:
print "No data found for '%s'" % cat_page
- sys.exit(1)
+ sys.exit(1)
+
+ elif action == 'pagelinks':
+ pages = return_links(wiki, opts.page)
elif action == 'migration':
pages = []
@@ -200,6 +227,9 @@ if __name__ == "__main__":
pagesxml = []
for pagetitle in pages:
+ if pagetitle.lower().find('testcase') == -1:
+ print "The page '%s' is not a test case" % pagetitle
+ continue
pagestring = parse(wiki, pagetitle)
pagetable = extract_to_dict(pagestring, pagetitle)
pagesxml.append(nitrate_xml(pagetable))