help solve error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbphydb
    New Member
    • Apr 2010
    • 22

    help solve error

    Hi,
    The below code is doing the following
    1. Reading the branch name and the destination from a txt file
    2. Parsing thru HTML pages

    Basically, i want to deploy the build of the branch (supplied thru txt file) on a test environment (supplied thru txt file)
    The branch_dest file looks like this
    Branch: ltm_7.4
    Destination: Test 5

    Code:
    URL = "http://11.12.13.27:8080/cruisecontrol"
    
    from urllib2 import urlopen
    from HTMLParser import HTMLParser
    
    import re
    
    # Fetching links using HTMLParser
    def get_links(url):
        parser = MyHTMLParser()
        parser.feed(urlopen(url).read())
        parser.close()
        return parser.links
    
    # Build url for Deploy page
    def get_deploy_url():
        lines = [x.split(None, 1) 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
        for link in get_links(url):
            print "hello1"
            if link["href"].startswith("Deploy"):
                return "%s/%s" % (URL, link["href"])
            print link["href"]
    
    # Build url for Destination page
    def get_destination_url():
        url = get_deploy_url()
        print url
        print destination
        destination_re = re.compile(r"%s") % destination
        for link in get_links(url):
            if destination_re.search(link["href"]):
                return "http://11.12.13.27:8080/cruisecontrol/" + link["href"]
    
    # Deploying the build
    #def deploy(url):
        
    
    # 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
    
    if __name__ == "__main__":
        final_url = get_destination_url()
        if final_url is None:
            print "Could not find a destination to deploy"
        else:
            print final_url
            #deploy(final_url)
    I am getting the below error
    Code:
    Traceback (most recent call last):
      File "C:\deploy_input.py", line 71, in <module>
        final_url = get_destination_url()
      File "C:\deploy_input.py", line 35, in get_destination_url
        url = get_deploy_url()
      File "C:\deploy_input.py", line 27, in get_deploy_url
        for link in get_links(url):
      File "C:\deploy_input.py", line 13, in get_links
        parser.feed(urlopen(url).read())
      File "C:\Python26\lib\urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "C:\Python26\lib\urllib2.py", line 389, in open
        req = meth(req)
      File "C:\Python26\lib\urllib2.py", line 1067, in do_request_
        raise URLError('no host given')
    URLError: <urlopen error no host given>
Working...