Hi Tony,
Sorry i am unable to understand you :(
Below is what i have now

URL = "http://10.47.42.27:8080/cruisecontrol"

from urllib2 import urlopen
from HTMLParser import HTMLParser

import re

# Parsing HTML pages 
class MyHTMLParser(HTMLParser):
    def __init__(self, *args, **kwd):
        HTMLParser.__init__(self, *args, **kwd)
        self.links = []

    def handle_starttag(self, tag, attrs):
        if tag == "a":
            attrs = dict(attrs)
            if "href" in attrs:
                self.links.append(dict(attrs))

    def handle_endtag(self, tag):
        pass


# Fetching links using HTMLParser
def get_links(url):
    parser = MyHTMLParser()
    parser.feed(urlopen(url).read())
    parser.close()
    return parser.links

# To find all text in the HTML table
class DataParser():
    def __init__(self):
        self.find = "COMPLETE"
        self.found = False
        self.data = urlopen(url).read()
        if self.data:   
            if self.find in self.data:
                self.found=True
                print "FOUND"
            else:
                print "NOT FOUND"
        else: print "NO DATA"

def build_check():
    parser = DataParser()
    return parser.found

# Build url for Deploy page
def get_deploy_url():
    url = URL + "/buildresults/Poker-TTM_%s_nightly_build" % branch
    print url
    if build_check():
        print "BUILD COMPLETE found"
        for link in get_links(url):
            if link["href"].startswith("Deploy"):
                return "%s/%s" % (URL, link["href"])

# Build url for Destination page
def get_destination_url():
    url = get_deploy_url()
    print "Deploy URL is: %s" % url
    destination_re = re.compile(r"%s" % destination)
    for link in get_links(url):
        if destination_re.search(link["href"]):
            return "http://10.47.42.27:8080/cruisecontrol/" + link["href"]
                  
if __name__ == "__main__":
    # Read the branch name and the test destination to deploy on
    lines = [x.split(':') for x in open("branch_dest.txt")]
    print lines
    branch = "%s" % lines[0][1].strip()
    print branch
    destination = "%s" % lines[1][1].strip()
    print destination
    
    final_url = get_destination_url()
    if final_url is None:
        print "Could not find a destination to deploy"
    else:
        print "Destination URL is: %s" % final_url

Is it giving results you expect? And the negative case results also?

Yeah, i tested it against a branch whose build had failed and didnt have the text 'BUILD COMPLETE' on the webpage. So the result it gave me was 'Could not find a destination to deploy'. Otherwise for a branch whose build was complete it gave me the value of final_url.

Thanks. I'll put in the rest of the code and let you know.

Hi,
Check below:

## Includes a check if the latest build has failed

from urllib2 import urlopen
from HTMLParser import HTMLParser

import re
import ClientForm
import urllib2

URL = "http://10.47.42.27:8080/cruisecontrol"

# Parsing HTML pages 
class MyHTMLParser(HTMLParser):
    def __init__(self, *args, **kwd):
        HTMLParser.__init__(self, *args, **kwd)
        self.links = []

    def handle_starttag(self, tag, attrs):
        if tag == "a":
            attrs = dict(attrs)
            if "href" in attrs:
                self.links.append(dict(attrs))

    def handle_endtag(self, tag):
        pass

# Fetching links using HTMLParser
def get_links(url):
    parser = MyHTMLParser()
    parser.feed(urlopen(url).read())
    parser.close()
    return parser.links

# Checking if the latest build is a success        
def build_check(url):
    find = "BUILD COMPLETE"
    print url
    if find in urlopen(url).read().strip():
        for link in get_links(url):
            if link["href"].startswith("Deploy"):
                return  "%s/%s" % (URL, link["href"])
    else:
        print "Build has failed"  [B]##### If build has failed i do no want further execution.. How do i do this?? #####[/B]

# Build url for Destination page
def get_destination_url():
    print "hello"
    destination_re = re.compile(r"%s" % destination)
    for link in get_links(deploy_url):
        if destination_re.search(link["href"]):
            return "http://10.47.42.27:8080/cruisecontrol/" + link["href"]
        print link["href"]
    
if __name__ == "__main__":
    # Read the branch name and the test destination to deploy on
    lines = [x.split(':') for x in open("branch_dest.txt")]
    print lines
    branch = "%s" % lines[0][1].strip()
    print branch
    destination = "%s" % lines[1][1].strip()
    print destination

    url = URL + "/buildresults/Poker-TTM_%s_nightly_build" % branch
    print url
    
    deploy_url = build_check(url)
    print deploy_url
    if deploy_url is None:
        final_url = None
        print "Cannot deploy here"
    else:
        final_url = get_destination_url()
        print final_url
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.