示例#1
0
    def __init__(self, bugzilla_url, username=None, password=None):
        """Initalises bugzilla_url, username and password variables and opens bugzilla page.

        Args:
            bugzilla_url: Bugzilla url to open
            username: Username to use. Ie. [email protected]
            password: Bugzilla password.
        """
        log.debug("Initialising Bugzilla class")

        # define constants class so that we do not mess up the code with lots of "self.bugzilla_url + "/show_bug.cgi?id=123456".
        self.constants = Constants(bugzilla_url)

        self.bugzilla_url = bugzilla_url
        self.username = username
        self.password = password

        self.browser = Browser()
        self.browser.addheaders = [("User-Agent", self.constants.USER_AGENT)]
        # disable robots txt. Pardus.org.tr has it and we cannot open any page if it is enabled. Also, kim takar yalova kaymakamını? :)
        self.browser.set_handle_robots(False)

        # handle cookies in a file. this will allow us to login once.
        self.cookiejar = LWPCookieJar(self.constants.COOKIE_FILE)
        self.browser.set_cookiejar(self.cookiejar)
        if self._has_cookie_file():
            log.debug("Loading cookies..")
            self._load_cookies()

        # if username and password is supplied, it means we are expected to login.
        self.is_auth_needed = bool(username and password)

        self.is_logged_in = False

        self._check_cookies()
        log.debug("Bugzilla class initialised")
示例#2
0
username = "******"
password = "******"
bug_id = "15012"
comment = u'author: fatih.arslan (fatih arslan)\nrepository: pardus\ncommit: 125476\n\nchanged files:\nu   playground/fatih.arslan/bugcomment_script\n\ncommit message:\nbug:comment:15012\n\nsee the changes at:\n  http://websvn.pardus.org.tr/pardus?view=revision&revision=125476\n'

constants = Constants(bugzillaUrl)

browser = Browser(factory=DefaultFactory(i_want_broken_xhtml_support=True))

#browser.addheaders = [("User-Agent", constants.USER_AGENT)]
browser.addheaders = [
    ("User-Agent",
     "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0")
]
browser.set_handle_robots(False)
cookiejar = LWPCookieJar(constants.COOKIE_FILE)
browser.set_cookiejar(cookiejar)

### Login
browser.open(bugzillaUrl)

print "## Open website"
print "## Show forms"
print ""
for f in browser.forms():
    print f

browser.select_form(nr=1)
browser["Bugzilla_login"] = username
browser["Bugzilla_password"] = password
response = browser.submit()