Subversion

helios_wp3

[/] [trunk/] [python/] [npmdebbugs.py] - Rev 7 Go to most recent revision

Compare with Previous - Blame


#!/usr/bin/python

import sys
import traceback
#import urllib2

# import these bits from btsutils (Debian package 'python-btsutils')
#from btsutils.debbugs import debbugs
#from btsutils.bug import Bug
from debbugsloc import debbugsloc

# Import bits from bts-link
from btslinkutils import BTSLConfig as Cnf
import btslinkbts
bts = btslinkbts

BUG_STEP=50

bugtrackers = [
#        ("mandriva", "https://qa.mandriva.com/show_bug.cgi?ctype=xml&excludefield=attachment&%s", 0, 46200),
#        ("kde", "http://bugs.kde.org/show_bug.cgi?ctype=xml&excludefield=attachment&%s", 0, 177000),
#        ("kernel", "http://bugzilla.kernel.org/show_bug.cgi?ctype=xml&excludefield=attachment&%s", 0, 12200),
    ("debian", "debbugs", "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s",500000,500010),
        ]

TEMPLATE_DIR="TEMPLATES"
templates = {}
for t in ["header", "bug-debian", "reporter", "package", "sys", "comment", "resolution"]:
    templates[t] = open("%s/%s" % (TEMPLATE_DIR, t)).read()


# character escaping
def escapechars(s, chars=[ '\"', '\'', '\\' ]):
    """Converts invalid characters to corresponding html"""
    return "".join(['\\%s' % c if c in chars else c for c in s])

def parse_bugs(spoolbts, id, output=sys.stdout):
    """Parses bugzilla bugs and outputs valid turtle format"""

    bug = spoolbts.get(str(id))
    if not bug :
        return
#    print bug
#    return

#     data = open(file).read()

#     try:
#         res = ET.fromstring(data)
#     except SyntaxError:
#         # looks like we found an invalid character
#         print >>sys.stderr, "Invalid characters found, stripping..",
#         # this is slow, but it is the best we can do right now..
#         for match in regex.finditer(data):
#             data = data[:match.start()] + "?" + data[match.end():]
#         res = ET.fromstring(data)

#     baseurl = res.get("urlbase")
    baseurl="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug="
    print >>output, templates["header"]
#     for bug in res:
#         # Check if bug is valid
#         if bug.get("error"):
#             # there is some error with this bug
#             # TODO: do we actually need the information about this error?
#             # usually the error fields means that this bug does not exists.
#             continue
#         # XPATH
    params = {}
#         # process bug parameters
#         bug_id = bug.findtext("./bug_id")
    bug_id=bug.getBug()
#         url = "%s/%s" % (baseurl, bug_id)
    url = "%s%s" % (baseurl, bug_id)
#         bugzilla_url = "%s/show_bug.cgi?id=%s" % (baseurl, bug_id)
    params["bug_id"] = bug_id
    params["url"] = url
#         params["bugzilla_url"] = bugzilla_url
    params["bugzilla_url"] = url
#         short_desc = bug.findtext("./short_desc", "Bug %s (no short description)" % bug_id)
    short_desc = bug.getSummary()
    params["short_desc"] = escapechars(short_desc.encode("utf-8"))
#         params["creation_ts"] = parse_ts(bug.findtext("./creation_ts"))
    params["creation_ts"] = ''
#         product = bug.findtext("./product", "Bug %s (no product)" % bug_id)
#         params["product"] = quote_plus(product)
    params["product"] = ''
#         params["sys"] = bug.findtext("./sys")
    params["sys"] = ''
#         params["bug_status"] = bug.findtext("./bug_status").capitalize()
    params["bug_status"] = bug.getStatus()
#         bug_priority = bug.findtext("./priority")
#         if bug_priority == "release_critical":
#             priority = 1
#         elif bug_priority == "high":
#             priority = 2
#         elif bug_priority == "normal":
#             priority = 3
#         elif bug_priority == "low":
#             priority = 4
#         else:
#             priority = 5
#         params["priority"] = priority
    params["priority"] = 5
#         # TODO: severity!
#         severity = bug.findtext("./severity")
#         if severity:
#             params["severity"] = severity.capitalize()
#         else:
#             params["severity"] = "Normal"
    params["severity"] = bug.getSeverity()
#         description = bug.findtext("./long_desc/thetext", "")
#         params["description"] = escapechars(description.encode("utf-8"))
    params["description"] = ''
#    print params
    print >>output, templates["bug-debian"] % params

#         # reporter
#         reporter = bug.findtext("./reporter")
#         quoted_email = reporter.replace(" ", "+")
#         print >>output, templates["reporter"] % {
#                             "url": url,
#                             "email": reporter,
#                             "quoted_email": quoted_email
#                         }

#         # resolution
#         resolution = bug.findtext("./resolution")
#         if resolution:
#             # convert resolution
#             resolution = resolution.upper()
#             if resolution == "WONTFIX":
#                 resolution_s = "WontFix"
#             elif resolution == "WORKSFORME":
#                 resolution_s = "WorksForMe"
#             elif resolution == "THIRDPARTY":
#                 resolution_s = "ThirdParty"
#             else:
#                 resolution_s = resolution.capitalize()

#             print >>output, templates["resolution"] % {
#                             "url": url,
#                             "resolution": resolution_s
#                             }

#         # now let's look at comments
#         comment_id = 0
#         for comment in bug.findall("./long_desc"):
#             who = comment.find("./who")
#             nick = quote_plus(who.get("name").encode('utf-8'))
#             email = who.text
#             quoted_email = email.replace(" ", "+") # remove blank spaces from emails
#             comment_ts = parse_ts(comment.findtext("./bug_when"))
#             description = escapechars(comment.findtext("./thetext").encode("utf-8"))
#             print >>output, templates["comment"] % {
#                             "url": url,
#                             "comment_id": comment_id,
#                             "email": email,
#                             "quoted_email": quoted_email,
#                             "nick": nick,
#                             "description": description,
#                             "comment_ts": comment_ts
#                             }
#             comment_id += 1


if __name__ == "__main__":
#     if len(sys.argv) < 2:
#         print "Usage: %s <bugs dir> [output file]" % sys.argv[0]
#         sys.exit(1)

    btsi = bts.BtsInterface(Cnf)

    # Instantiate our btsutils.debbugs compliant interface
    spoolbts = debbugsloc(btsi,False)

    for name, type, url, start, end in bugtrackers:
#        for id in range(start, end, BUG_STEP):
        for id in range(start, end):
#            print "Getting [%s] %d - %d.." % (name, id, id+BUG_STEP)

            print >>sys.stderr, "Processing bug %d.." % id,
            try:
                parse_bugs(spoolbts, id)
                print >>sys.stderr, "ok"
#            os.unlink(file)
            except:
                traceback.print_exc()
                print >>sys.stderr, "error processing %d: %s" % (id, sys.exc_value)
                sys.exit(1)
        
#         bugs = "&id=".join(str(x) for x in range(id, id+BUG_STEP))
#         fd = open("%s_%d_%d.xml" % (name, id, id+BUG_STEP), "w")
#         #data = urllib2.urlopen("http://bugs.kde.org/show_bug.cgi?ctype=xml&%s" % bugs).read() # kde bugs
#         data = urllib2.urlopen(url % bugs).read() # mandriva bugs
#         fd.write(data)
#         fd.close()
    sys.exit(0)


#print data

Powered by WebSVN v1.61