コード例 #1
0
ファイル: bugs.py プロジェクト: dhirajkhatiwada1/uludag
def main():
    log = logging.getLogger("bugzilla.BIN")

    parser = setup_parser()
    (global_opts, args) = parser.parse_args()

    global_opts = BugStruct(**global_opts.__dict__)

    # Get our action from these args
    if len(args) and args[0] in cmdlist:
        action = args.pop(0)
    else:
        parser.error("command must be one of: %s" % ','.join(cmdlist))

    action_parser = setup_action_parser(action)
    (opt, args) = action_parser.parse_args(args)
    opt = BugStruct(**opt.__dict__)

    # Helper functions
    def check_valid_resolutions():
        """Checks if valid resolution is given for --resolution and --close"""

        # make it upper-case for easy-of-use
        if opt.resolution:
            opt.resolution = opt.resolution.upper()
            if not opt.resolution in VALID_RESOLUTIONS:
                parser.error("resolution must be one of: %s" % ','.join(VALID_RESOLUTIONS))
                sys.exit(1)
        elif opt.close:
            opt.close = opt.close.upper()
            # --close is an alias for -s RESOLVED -r FIXED.
            # When --close is used, only resolution is appended. So control it.
            #
            # bugspy.py modify -b 12346 --close invalid
            #
            if not opt.close in VALID_RESOLUTIONS:
                parser.error("resolution must be one of: %s" % ','.join(VALID_RESOLUTIONS))
                sys.exit(1)

    def check_valid_statuses():
        # make it upper-case for easy-of-use
        opt.status = opt.status.upper()

        if not opt.status in VALID_STATUSES:
            parser.error("status must be one of: %s" % ','.join(VALID_STATUSES))

    def check_valid_keywords():
        # make it upper-case for easy-of-use
        opt.keywords = opt.keywords.upper()

        if not opt.keywords in VALID_KEYWORDS:
            parser.error("keyword must be one of: %s" % ','.join(VALID_KEYWORDS))

    if not os.path.exists(CONFIG_FILE) and action != "generate-config":
        log.error("Configuation file is not found, please generate it first")
        sys.exit(1)

    c = BugspyConfig()
    bugzilla = Bugzilla(c.bugzillaurl, c.username, c.password)

    if action == "generate-config":
        if os.path.exists(CONFIG_FILE):
            log.warning("Configuration file exists. Please edit ~/.bugspy.conf with your text editor. Exiting...")
            sys.exit(1)

        # check arguments
        if not (opt.user and opt.password and opt.bugzilla_url):
            parser.error("Missing argument! See --help")
            sys.exit(1)

        config_data = CONFIG_TEMPLATE % {"bugzilla": opt.bugzilla_url,
                                         "user": opt.user,
                                         "password": opt.password}

        log.info("Writing configuration file")
        open(CONFIG_FILE, "w+").write(config_data)
        log.info("Configuration file is written. You can edit ~/.bugspy.conf for later use")

    if action == "modify":
        modify = {}
        if not opt.bug_id:
            log.error("Bud id must be provided!")
            sys.exit(1)

        modify["bug_id"] = opt.bug_id

        if opt.comment:
            modify["comment"] = opt.comment

        if opt.status:
            check_valid_statuses()
            if opt.status == "RESOLVED" and not opt.resolution:
                parser.error("RESOLVED should be used along with RESOLUTION.")
                sys.exit(1)

            modify["status"] = opt.status

        if opt.resolution:
            check_valid_resolutions()

            # we cannot set resolution on NEW bugs
            bugzilla.login()
            bug_info = bugzilla.get(opt.bug_id)
            if bug_info.has("status") and bug_info.status == "NEW":
                log.error("You cannot change resolution on NEW bugs. Maybe you want to this?: --status RESOLVED --resolution %s" % opt.resolution)
                sys.exit(1)

            modify["resolution"] = opt.resolution

        if opt.close and not opt.resolution:
            check_valid_resolutions()
            modify["status"] = "RESOLVED"
            modify["resolution"] = opt.close

        if opt.title:
            modify["title"] = opt.title

        if opt.assigned_to:
            modify["assigned_to"] = opt.assigned_to

        if opt.security:
            modify["security"] = opt.security

        if opt.keywords:
            modify["keywords"] = opt.keywords

        if opt.blocks:
            modify["blocks"] = opt.blocks

        if opt.depends:
            modify["dependson"] = opt.depends

        if opt.cc:
            modify["cc"] = opt.cc

        if opt.version:
            if not opt.version in VALID_VERSIONS:
                parser.error("version must be one of: %s" % ', '.join(VALID_VERSIONS))

            modify["version"] = opt.version

        try:
            bugzilla.login()
            bugzilla.modify(**modify)
        except BugzillaError, e:
            log.error(e.msg)
コード例 #2
0
def main(filename):
    title, description = readFile(filename)

    c = BugspyConfig()
    bugzilla = Bugzilla(c.bugzillaurl, c.username, c.password)

    new_bug = {}
    new_bug["title"] = title
    new_bug["description"] = description
    new_bug["product"] = "Güvenlik / Security"

    print "Proessing bug: %s" % title
    print description

    component = "guvenlik/security"
    new_bug["component"] = component
    new_bug["version"]="---"
    print ''
    print "Which Pardus versions are affected?"
    print "1- Pardus 2009"
    print "2- Pardus Corporate2"
    print "3- Pardus 2011\n"

    affected_pardus_versions = []
    while 1:
        print "Append Pardus version [r=Revert, q=Quit]: ",
        answer = sys.stdin.readline()
        answer = answer[0]
        if answer == "q":
            if len(affected_pardus_versions) > 0:
                break
            else:
                print "You need to specify at least 1 version"
                continue

        if answer == "r":
            affected_pardus_versions = []
            continue

        if answer == "\n":
            print affected_pardus_versions
            continue

        if not answer in PARDUS_RELEASES.keys():
            print "Invalid entry"
        else:
            if PARDUS_RELEASES.get(answer) in affected_pardus_versions:
                print "This is already selected"
            else:
                affected_pardus_versions.append(PARDUS_RELEASES.get(answer))
                print affected_pardus_versions

    print ''
    print "Assign this bug to [Enter=default]: ",
    answer = sys.stdin.readline()
    if answer[0] != "\n":
        assigned_to = answer.replace("\n", "")
        print "Bug is assigned and CCed to: %s" % assigned_to
        new_bug["cc"] = assigned_to
    else:
        assigned_to = None
        print "Not assigning. Assignee is default."

    print ''
    print "Add CC [Enter=none]: ",
    answer = sys.stdin.readline()
    if answer[0] != "\n":
        cc_address = answer.replace("\n", "")
        print "Address CCed: %s" % cc_address
    else:
        cc_address = None

    print ''
    print "Make his bug private? [Y/n]: ",
    answer = sys.stdin.readline()
    if answer[0] == "y" or answer[0] == "\n":
        new_bug["security"] = 1
    elif answer[0] == "n":
        new_bug["security"] = 0

    print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print "Title     : %s" % title
    print "Component : %s" % component
    print "Affected  : %s" % ', '.join(affected_pardus_versions)
    print "Private?  : %s" % new_bug["security"]
    print "Assigned  : %s" % assigned_to
    print "CCed      : %s" % cc_address
    print description + "\n"

    print "\nWill file this bug [Y/n]: ",

    answer = sys.stdin.readline()
    if answer[0] == "y" or answer[0] == "Y" or answer[0] == "\n":
        print "Filing the bug..."

        bugzilla.login()
        bugno = bugzilla.new(**new_bug)

        if bugno:
            print "Success! http://bugs.pardus.org.tr/%s" % (bugno)
            print "   %s" % title

            # add each entry to files and file a bug
            for affected_version in affected_pardus_versions:
                bug_title = "%s - Pardus %s" % (title.replace("\n",""), affected_version)
                bug_desc = "Pardus %s is affected from bug #%s" % (affected_version, bugno)

                no = bugzilla.new(title=bug_title,
                                  description=bug_desc,
                                  security=1,
                                  component=component,
                                  status="ASSIGNED",
                                  assigned_to=assigned_to,
                                  cc=cc_address,
                                  version=affected_version,
                                  product="Güvenlik / Security",
                                  blocks=bugno)

                print "Success! http://bugs.pardus.org.tr/%s" % no
                print "   %s" % bug_title

                # FIXME: Add them to tracker file when we move to new tracker system
                #file = TRACKER_MAP.get(affected_version)
                #ini = SecurityINI(file)

                #Write the bug number to tracker
                package_name = bug_title.split(":")[0]
                enter_bug_to_tracker(str(affected_version), package_name, no)
コード例 #3
0
def main(author, msg, commit_no, changed, repo):
    changed = arrayTostring(changed)
    msg = arrayTostring(msg)

    repo_name = os.path.basename(repo)
    if repo_name == "pisi":
        repo_name = "pardus"

    author_name = " (%s)" % getAuthorName(author)
    if not author_name:
        author_name = ""

    thetext = BUG_COMMENT_TEMPLATE % {"author": author, "author_full": author_name, "repo": repo_name, "commit_no": commit_no, "changed": changed, "log": msg}

    # These shouldn't be needed anymore
    """
    thetext=thetext.replace("'", "\"")
    thetext=thetext.replace(")", "\\)")
    thetext=thetext.replace("(", "\\(")
    thetext=thetext.replace(";", "")
    """
    open(SVN_LOG_FILE, "w").write(thetext)

    c = BugspyConfig(BUGSPY_CONFIG_FILE)
    bugzilla = Bugzilla(c.bugzillaurl, c.username, c.password)
    bugzilla.login()

    def commentBUG(bug_id):
        log.info("Modifying bug...")
        bugzilla.modify(bug_id=bug_id,
                        comment=thetext)

    def fixBUG(bug_id):
        log.info("Fixing bug..")
        bugzilla.modify(bug_id=bug_id,
                        status="RESOLVED",
                        resolution="FIXED",
                        comment=thetext)

    def closeBUG(bug_id):
        log.info("Closing bug..")
        bugzilla.modify(bug_id=bug_id,
                        status="CLOSED",
                        comment=thetext)

    def addKEY(bug_id):
        log.info("Adding key..")
        bug_id, keyword = splitIDAndKEY(bug_id)
        bugzilla.modify(bug_id=bug_id,
                        keywords="%s" % keyword,
                        comment=thetext)

    for cmd, bug_id in checkLOG(msg.split('\n')):
        if cmd == "COMMENT":
            commentBUG(bug_id)
        elif cmd == "FIXED":
            fixBUG(bug_id)
        elif cmd == "CLOSED":
            closeBUG(bug_id)
        elif cmd == "KEY":
            addKEY(bug_id)
コード例 #4
0
def main(filename):
    title, description = readFile(filename)

    c = BugspyConfig()
    bugzilla = Bugzilla(c.bugzillaurl, c.username, c.password)

    new_bug = {}
    new_bug["title"] = title
    new_bug["description"] = description
    new_bug["product"] = "Güvenlik / Security"

    print "Proessing bug: %s" % title
    print description

    component = "guvenlik/security"
    new_bug["component"] = component
    new_bug["version"] = "---"
    print ''
    print "Which Pardus versions are affected?"
    print "1- Pardus 2009"
    print "2- Pardus Corporate2"
    print "3- Pardus 2011\n"

    affected_pardus_versions = []
    while 1:
        print "Append Pardus version [r=Revert, q=Quit]: ",
        answer = sys.stdin.readline()
        answer = answer[0]
        if answer == "q":
            if len(affected_pardus_versions) > 0:
                break
            else:
                print "You need to specify at least 1 version"
                continue

        if answer == "r":
            affected_pardus_versions = []
            continue

        if answer == "\n":
            print affected_pardus_versions
            continue

        if not answer in PARDUS_RELEASES.keys():
            print "Invalid entry"
        else:
            if PARDUS_RELEASES.get(answer) in affected_pardus_versions:
                print "This is already selected"
            else:
                affected_pardus_versions.append(PARDUS_RELEASES.get(answer))
                print affected_pardus_versions

    print ''
    print "Assign this bug to [Enter=default]: ",
    answer = sys.stdin.readline()
    if answer[0] != "\n":
        assigned_to = answer.replace("\n", "")
        print "Bug is assigned and CCed to: %s" % assigned_to
        new_bug["cc"] = assigned_to
    else:
        assigned_to = None
        print "Not assigning. Assignee is default."

    print ''
    print "Add CC [Enter=none]: ",
    answer = sys.stdin.readline()
    if answer[0] != "\n":
        cc_address = answer.replace("\n", "")
        print "Address CCed: %s" % cc_address
    else:
        cc_address = None

    print ''
    print "Make his bug private? [Y/n]: ",
    answer = sys.stdin.readline()
    if answer[0] == "y" or answer[0] == "\n":
        new_bug["security"] = 1
    elif answer[0] == "n":
        new_bug["security"] = 0

    print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print '!!!!!!!!!!!!!!!!!!!!!!!!!!!'
    print "Title     : %s" % title
    print "Component : %s" % component
    print "Affected  : %s" % ', '.join(affected_pardus_versions)
    print "Private?  : %s" % new_bug["security"]
    print "Assigned  : %s" % assigned_to
    print "CCed      : %s" % cc_address
    print description + "\n"

    print "\nWill file this bug [Y/n]: ",

    answer = sys.stdin.readline()
    if answer[0] == "y" or answer[0] == "Y" or answer[0] == "\n":
        print "Filing the bug..."

        bugzilla.login()
        bugno = bugzilla.new(**new_bug)

        if bugno:
            print "Success! http://bugs.pardus.org.tr/%s" % (bugno)
            print "   %s" % title

            # add each entry to files and file a bug
            for affected_version in affected_pardus_versions:
                bug_title = "%s - Pardus %s" % (title.replace(
                    "\n", ""), affected_version)
                bug_desc = "Pardus %s is affected from bug #%s" % (
                    affected_version, bugno)

                no = bugzilla.new(title=bug_title,
                                  description=bug_desc,
                                  security=1,
                                  component=component,
                                  status="ASSIGNED",
                                  assigned_to=assigned_to,
                                  cc=cc_address,
                                  version=affected_version,
                                  product="Güvenlik / Security",
                                  blocks=bugno)

                print "Success! http://bugs.pardus.org.tr/%s" % no
                print "   %s" % bug_title

                # FIXME: Add them to tracker file when we move to new tracker system
                #file = TRACKER_MAP.get(affected_version)
                #ini = SecurityINI(file)

                #Write the bug number to tracker
                package_name = bug_title.split(":")[0]
                enter_bug_to_tracker(str(affected_version), package_name, no)
コード例 #5
0
ファイル: bugs.py プロジェクト: pars-linux/uludag
def main():
    log = logging.getLogger("bugzilla.BIN")

    parser = setup_parser()
    (global_opts, args) = parser.parse_args()

    global_opts = BugStruct(**global_opts.__dict__)

    # Get our action from these args
    if len(args) and args[0] in cmdlist:
        action = args.pop(0)
    else:
        parser.error("command must be one of: %s" % ','.join(cmdlist))

    action_parser = setup_action_parser(action)
    (opt, args) = action_parser.parse_args(args)
    opt = BugStruct(**opt.__dict__)

    # Helper functions
    def check_valid_resolutions():
        """Checks if valid resolution is given for --resolution and --close"""

        # make it upper-case for easy-of-use
        if opt.resolution:
            opt.resolution = opt.resolution.upper()
            if not opt.resolution in VALID_RESOLUTIONS:
                parser.error("resolution must be one of: %s" %
                             ','.join(VALID_RESOLUTIONS))
                sys.exit(1)
        elif opt.close:
            opt.close = opt.close.upper()
            # --close is an alias for -s RESOLVED -r FIXED.
            # When --close is used, only resolution is appended. So control it.
            #
            # bugspy.py modify -b 12346 --close invalid
            #
            if not opt.close in VALID_RESOLUTIONS:
                parser.error("resolution must be one of: %s" %
                             ','.join(VALID_RESOLUTIONS))
                sys.exit(1)

    def check_valid_statuses():
        # make it upper-case for easy-of-use
        opt.status = opt.status.upper()

        if not opt.status in VALID_STATUSES:
            parser.error("status must be one of: %s" %
                         ','.join(VALID_STATUSES))

    def check_valid_keywords():
        # make it upper-case for easy-of-use
        opt.keywords = opt.keywords.upper()

        if not opt.keywords in VALID_KEYWORDS:
            parser.error("keyword must be one of: %s" %
                         ','.join(VALID_KEYWORDS))

    if not os.path.exists(CONFIG_FILE) and action != "generate-config":
        log.error("Configuation file is not found, please generate it first")
        sys.exit(1)

    c = BugspyConfig()
    bugzilla = Bugzilla(c.bugzillaurl, c.username, c.password)

    if action == "generate-config":
        if os.path.exists(CONFIG_FILE):
            log.warning(
                "Configuration file exists. Please edit ~/.bugspy.conf with your text editor. Exiting..."
            )
            sys.exit(1)

        # check arguments
        if not (opt.user and opt.password and opt.bugzilla_url):
            parser.error("Missing argument! See --help")
            sys.exit(1)

        config_data = CONFIG_TEMPLATE % {
            "bugzilla": opt.bugzilla_url,
            "user": opt.user,
            "password": opt.password
        }

        log.info("Writing configuration file")
        open(CONFIG_FILE, "w+").write(config_data)
        log.info(
            "Configuration file is written. You can edit ~/.bugspy.conf for later use"
        )

    if action == "modify":
        modify = {}
        if not opt.bug_id:
            log.error("Bud id must be provided!")
            sys.exit(1)

        modify["bug_id"] = opt.bug_id

        if opt.comment:
            modify["comment"] = opt.comment

        if opt.status:
            check_valid_statuses()
            if opt.status == "RESOLVED" and not opt.resolution:
                parser.error("RESOLVED should be used along with RESOLUTION.")
                sys.exit(1)

            modify["status"] = opt.status

        if opt.resolution:
            check_valid_resolutions()

            # we cannot set resolution on NEW bugs
            bugzilla.login()
            bug_info = bugzilla.get(opt.bug_id)
            if bug_info.has("status") and bug_info.status == "NEW":
                log.error(
                    "You cannot change resolution on NEW bugs. Maybe you want to this?: --status RESOLVED --resolution %s"
                    % opt.resolution)
                sys.exit(1)

            modify["resolution"] = opt.resolution

        if opt.close and not opt.resolution:
            check_valid_resolutions()
            modify["status"] = "RESOLVED"
            modify["resolution"] = opt.close

        if opt.title:
            modify["title"] = opt.title

        if opt.assigned_to:
            modify["assigned_to"] = opt.assigned_to

        if opt.security:
            modify["security"] = opt.security

        if opt.keywords:
            modify["keywords"] = opt.keywords

        if opt.blocks:
            modify["blocks"] = opt.blocks

        if opt.depends:
            modify["dependson"] = opt.depends

        if opt.cc:
            modify["cc"] = opt.cc

        if opt.version:
            if not opt.version in VALID_VERSIONS:
                parser.error("version must be one of: %s" %
                             ', '.join(VALID_VERSIONS))

            modify["version"] = opt.version

        try:
            bugzilla.login()
            bugzilla.modify(**modify)
        except BugzillaError, e:
            log.error(e.msg)