Пример #1
0
def select_url(source, depsdict):
    '''
    TBD
    '''
    depsdict[source + "_addr_list"] = []

    depsdict[source + "_addr"] = False

    if source == "repo":
        _element = "package repository"
    else:
        _element = "python pip repository"

    print '\n'
    _msg = "Selecting " + _element + " address...."
    cbinfo(_msg)

    for _key in sorted(depsdict.keys()):
        if _key.count(source + "-addr"):
            _index = int(_key.replace(source + "-addr", ''))
            depsdict[source + "_addr_list"].insert(_index, depsdict[_key])

    for _repo_addr in depsdict[source + "_addr_list"]:
        if check_url("http://" + _repo_addr, "ARCH", depsdict["carch"]):
            depsdict[source + "_addr"] = _repo_addr

    if len(depsdict[source + "_addr_list"]):
        if depsdict[source + "_addr"]:
            _msg = "A " + _element + " in \"" + depsdict[
                source + "_addr"] + "\" seems to be up"
            depsdict[source +
                     "_dropbox"] = "http://" + depsdict[source +
                                                        "_addr"] + "/dropbox"
            depsdict[source + "_credentials_url"] = "http://" + depsdict[
                source + "_addr"] + "/dropbox/ssh_keys"
            cbinfo(_msg)
        else:
            _msg = "##### None of the indicated " + _element + " was available. ".replace(
                "repository", "repositories")
            if source == "repo":
                _msg += "Will ignore any repository URL that has the keyword REPO_ADDR..."
            cbwarn(_msg)
    else:
        _msg = "##### No " + _element + " specified. ".replace(
            "repository", "repositories")
        if source == "repo":
            _msg += "Will ignore any repository URL that has the keyword REPO_ADDR..."
        cbwarn(_msg)

    return True
Пример #2
0
def select_url(source, depsdict) :
    '''
    TBD
    '''
    depsdict[source + "_addr_list"] = []

    depsdict[source + "_addr"] = False

    if source == "repo" :
        _element = "package repository"
    else :
        _element = "python pip repository"

    print '\n'
    _msg = "Selecting " + _element + " address...." 
    cbinfo(_msg)
    
    for _key in sorted(depsdict.keys()) :
        if _key.count(source + "-addr") :
            _index = int(_key.replace(source + "-addr",''))
            depsdict[source + "_addr_list"].insert(_index, depsdict[_key])

    for _repo_addr in depsdict[source + "_addr_list"] :
        if check_url("http://" + _repo_addr, "ARCH", depsdict["carch"]) :
            depsdict[source + "_addr"] = _repo_addr
    
    if len(depsdict[source + "_addr_list"]) :
        if depsdict[source + "_addr"] :
            _msg = "A " + _element + " in \"" + depsdict[source + "_addr"] + "\" seems to be up"
            depsdict[source + "_dropbox"] = "http://" + depsdict[source + "_addr"] + "/dropbox"
            depsdict[source + "_credentials_url"] = "http://" + depsdict[source + "_addr"] + "/dropbox/ssh_keys"
            cbinfo(_msg)
        else :
            _msg = "##### None of the indicated " + _element + " was available. ".replace("repository","repositories")
            if source == "repo" :
                _msg += "Will ignore any repository URL that has the keyword REPO_ADDR..."
            cbwarn(_msg)
    else :
        _msg = "##### No " + _element + " specified. ".replace("repository","repositories")
        if source == "repo" :
            _msg += "Will ignore any repository URL that has the keyword REPO_ADDR..."
        cbwarn(_msg)
    
    return True
Пример #3
0
def build_repository_file_contents(depsdict, repo_name) :
    '''
    TBD
    '''
    _msg = "Configuring repository \"" + repo_name +"\"..."
    cbinfo(_msg)
    
    _file_contents = ""

    if "local-url" in depsdict["repo_contents"][repo_name] :
        
        if len(depsdict["repo_contents"][repo_name]["local-url"]) :
            
            if not depsdict["repo_addr"] and \
            depsdict["repo_contents"][repo_name]["local-url"].count("REPO_ADDR") :

                _actual_url = depsdict["repo_contents"][repo_name]["original-url"]

            else :

                _actual_url = depsdict["repo_contents"][repo_name]["local-url"]
    else :
        _actual_url = depsdict["repo_contents"][repo_name]["original-url"]

    if depsdict["repo_addr"] :
        _actual_url = _actual_url.replace("REPO_ADDR", depsdict["repo_addr"])
        _actual_url = _actual_url.replace("REPO_RELEASE", depsdict["cdistver"])
        _actual_url = _actual_url.replace("REPO_MAJOR_RELEASE", depsdict["cdistmajorver"])
        _actual_url = _actual_url.replace("REPO_ARCH", depsdict["carch"])
        
    if not check_url(_actual_url, "ARCH", depsdict["carch"]) :
        _tested_urls = _actual_url

        _actual_url = depsdict["repo_contents"][repo_name]["original-url"]

        if not check_url(_actual_url, "ARCH", depsdict["carch"]) :
            if not _tested_urls.count(_actual_url) :
                _tested_urls += ',' + _actual_url
            _actual_url = False

    if _actual_url :            
        _msg = "Valid URL found: " + _actual_url + "."
        cbinfo(_msg)
    else :
        _msg = "No URLs available for repository \"" + repo_name 
        _msg += "\" (" + _tested_urls + ")." + " Will ignore this repository"
        _msg += ", but this might cause installation errors due to a lacking on certain dependencies"        
        cbwarn(_msg)
        return False

    if depsdict["cdistkind"] == "ubuntu" :
        for _dist in depsdict["repo_contents"][repo_name]["dists"].split(',') :
            for _component in depsdict["repo_contents"][repo_name]["components"].split(',') :
                _file_contents += "deb " + _actual_url + ' ' + _dist + ' ' + _component + "\n"
    else :
        _file_contents += "[" + repo_name + "]\n"
        _file_contents += "name = " + repo_name + "\n"        
        _file_contents += "baseurl = " + _actual_url + "\n"

        for _attr in [ "enabled", "skip_if_unavailable", "priority", "gpgcheck" ] :
            _file_contents += _attr + " = " + depsdict["repo_contents"][repo_name][_attr] + "\n"

        if  depsdict["repo_contents"][repo_name]["gpgcheck"] == "0" :
            True
        else :
            _file_contents += "gpgkey = " + depsdict["repo_contents"][repo_name]["gpgkey"] + "\n"


    return _file_contents
Пример #4
0
def get_cmdline(depkey, depsdict, operation, process_manager = False, exception_if_no_url = False) :
    ''' 
    TBD
    '''

    if operation != "configure" :
        if depsdict[depkey + '-' + operation] == "man" :

            _urls_key = depsdict["cdistnam"] + '-' + depkey + '-' + depsdict["carch"] + "-urls-" + depsdict[depkey + '-' + operation]            

            if _urls_key not in depsdict :
                _urls_key = depsdict["cdistkind"] + '-' + depkey + '-' + depsdict["carch"] + "-urls-" + depsdict[depkey + '-' + operation]

                if _urls_key not in depsdict :            
                    _urls_key = "common-" + depkey + '-' + depsdict["carch"] + "-urls-" + depsdict[depkey + '-' + operation]
                            
                    if _urls_key not in depsdict :
                        _urls_key = False
        else :

            _urls_key = depsdict["cdistnam"] + '-' + depkey + "-urls-" + depsdict[depkey + '-' + operation]            

            if _urls_key not in depsdict :            
                _urls_key = depsdict["cdistkind"] + '-' + depkey + "-urls-" + depsdict[depkey + '-' + operation]            

                if _urls_key not in depsdict :               
                    _urls_key = "common-" + depkey + "-urls-" + depsdict[depkey + '-' + operation]

                    if _urls_key not in depsdict :
                        _urls_key = False                

    else :
        _urls_key = False
    
    if _urls_key :
        if len(depsdict[_urls_key]) > 7 :
            _tested_urls = ''
            _actual_url = False
            for _url in depsdict[_urls_key].split(',') :
    
                if depsdict["repo_addr"] :
                    _url = _url.replace("REPO_ADDR", depsdict["repo_addr"])
    
                _url = _url.replace("REPO_RELEASE", depsdict["cdistver"])
                _url = _url.replace("REPO_MAJOR_RELEASE", depsdict["cdistmajorver"])                
                _url = _url.replace("REPO_ARCH", depsdict["carch"])            
                _url = _url.replace("ARCH", depsdict["carch"].strip())
                _url = _url.replace("DISTRO", depsdict["cdistkind"].strip())
                _url = _url.replace("USERNAME", depsdict["username"].strip())
                
                if check_url(_url, "ARCH", depsdict["carch"]) :
                    _actual_url = _url
                    break
                else :
                    if not _tested_urls.count(_url) :
                        _tested_urls += _url + ','
    
            if not _actual_url :
                _msg = "##### None of the urls indicated to install \"" + depkey + "\" (" 
                _msg += _tested_urls + ") seem to be functional."

                if exception_if_no_url :
                    raise Exception(_msg)
                else :
                    cbwarn(_msg)
        else :
            _actual_url = False                
    else :
        _actual_url = False

    _actual_cmdline = ""
    _actual_cmdline_keys = ''
    
    if operation == "install" :
        for _sub_step in [ "preinstall", "install", "postinstall"] :

            _commandline_keys = []

            _commandline_keys.append(depsdict["cdistnam"] + '-' + depkey + '-' + _sub_step + '-' + depsdict[depkey + '-' + operation])
            _commandline_keys.append(depsdict["cdistkind"] + '-' + depkey + '-' + _sub_step + '-' + depsdict[depkey + '-' + operation])
            _commandline_keys.append("common-" + depkey + '-' + _sub_step + '-' + depsdict[depkey + '-' + operation])

            _x, _y = get_actual_cmdline(_commandline_keys, depsdict, _actual_url)

            _actual_cmdline_keys += _x + ','
            
            _actual_cmdline += _y + ';'

    else :
        _commandline_keys = [ depkey + '-' + operation ]
        
        _x, _y = get_actual_cmdline(_commandline_keys, depsdict, _actual_url)

        _actual_cmdline_keys += _x + ','
        _actual_cmdline += _y + ';'

    if _actual_cmdline_keys[0] == ',' :
        _actual_cmdline_keys = _actual_cmdline_keys[1:]
        
    if _actual_cmdline_keys[-1] == ',' :
        _actual_commandline_keys = _actual_cmdline_keys[0:-1]
        
    if _actual_cmdline[0] == ';' :
        _actual_cmdline = _actual_cmdline[1:]

    if _actual_cmdline[-1] == ';' :
        _actual_cmdline = _actual_cmdline[0:-1]

    _actual_cmdline = expand_command(_actual_cmdline, depsdict, process_manager)

    _actual_cmdline_keys = _actual_cmdline_keys.replace(",,",',')
    _actual_cmdline_keys = _actual_cmdline_keys.replace(",,",',')    
    _actual_cmdline_keys = _actual_cmdline_keys.replace("_equal_",'=')

    _actual_cmdline = _actual_cmdline.replace(";;",';')
    _actual_cmdline = _actual_cmdline.replace(";;",';')
    _actual_cmdline = _actual_cmdline.replace(";;",';')    
    _actual_cmdline = _actual_cmdline.replace("_equal_",'=')
    
    return _actual_commandline_keys, _actual_cmdline
Пример #5
0
def build_repository_file_contents(depsdict, repo_name):
    '''
    TBD
    '''
    _msg = "Configuring repository \"" + repo_name + "\"..."
    cbinfo(_msg)

    _file_contents = ""

    if "local-url" in depsdict["repo_contents"][repo_name]:

        if len(depsdict["repo_contents"][repo_name]["local-url"]):

            if not depsdict["repo_addr"] and \
            depsdict["repo_contents"][repo_name]["local-url"].count("REPO_ADDR") :

                _actual_url = depsdict["repo_contents"][repo_name][
                    "original-url"]

            else:

                _actual_url = depsdict["repo_contents"][repo_name]["local-url"]
    else:
        _actual_url = depsdict["repo_contents"][repo_name]["original-url"]

    if depsdict["repo_addr"]:
        _actual_url = _actual_url.replace("REPO_ADDR", depsdict["repo_addr"])
        _actual_url = _actual_url.replace("REPO_RELEASE", depsdict["cdistver"])
        _actual_url = _actual_url.replace("REPO_MAJOR_RELEASE",
                                          depsdict["cdistmajorver"])
        _actual_url = _actual_url.replace("REPO_ARCH", depsdict["carch"])

    if not check_url(_actual_url, "ARCH", depsdict["carch"]):
        _tested_urls = _actual_url

        _actual_url = depsdict["repo_contents"][repo_name]["original-url"]

        if not check_url(_actual_url, "ARCH", depsdict["carch"]):
            if not _tested_urls.count(_actual_url):
                _tested_urls += ',' + _actual_url
            _actual_url = False

    if _actual_url:
        _msg = "Valid URL found: " + _actual_url + "."
        cbinfo(_msg)
    else:
        _msg = "No URLs available for repository \"" + repo_name
        _msg += "\" (" + _tested_urls + ")." + " Will ignore this repository"
        _msg += ", but this might cause installation errors due to a lacking on certain dependencies"
        cbwarn(_msg)
        return False

    if depsdict["cdistkind"] == "ubuntu":
        for _dist in depsdict["repo_contents"][repo_name]["dists"].split(','):
            for _component in depsdict["repo_contents"][repo_name][
                    "components"].split(','):
                _file_contents += "deb " + _actual_url + ' ' + _dist + ' ' + _component + "\n"
    else:
        _file_contents += "[" + repo_name + "]\n"
        _file_contents += "name = " + repo_name + "\n"
        _file_contents += "baseurl = " + _actual_url + "\n"

        for _attr in [
                "enabled", "skip_if_unavailable", "priority", "gpgcheck"
        ]:
            _file_contents += _attr + " = " + depsdict["repo_contents"][
                repo_name][_attr] + "\n"

        if depsdict["repo_contents"][repo_name]["gpgcheck"] == "0":
            True
        else:
            _file_contents += "gpgkey = " + depsdict["repo_contents"][
                repo_name]["gpgkey"] + "\n"

    return _file_contents
Пример #6
0
def get_cmdline(depkey,
                depsdict,
                operation,
                process_manager=False,
                exception_if_no_url=False):
    ''' 
    TBD
    '''

    if operation != "configure":
        if depsdict[depkey + '-' + operation] == "man":

            _urls_key = depsdict["cdistnam"] + '-' + depkey + '-' + depsdict[
                "carch"] + "-urls-" + depsdict[depkey + '-' + operation]

            if _urls_key not in depsdict:
                _urls_key = depsdict[
                    "cdistkind"] + '-' + depkey + '-' + depsdict[
                        "carch"] + "-urls-" + depsdict[depkey + '-' +
                                                       operation]

                if _urls_key not in depsdict:
                    _urls_key = "common-" + depkey + '-' + depsdict[
                        "carch"] + "-urls-" + depsdict[depkey + '-' +
                                                       operation]

                    if _urls_key not in depsdict:
                        _urls_key = False
        else:

            _urls_key = depsdict[
                "cdistnam"] + '-' + depkey + "-urls-" + depsdict[depkey + '-' +
                                                                 operation]

            if _urls_key not in depsdict:
                _urls_key = depsdict[
                    "cdistkind"] + '-' + depkey + "-urls-" + depsdict[
                        depkey + '-' + operation]

                if _urls_key not in depsdict:
                    _urls_key = "common-" + depkey + "-urls-" + depsdict[
                        depkey + '-' + operation]

                    if _urls_key not in depsdict:
                        _urls_key = False

    else:
        _urls_key = False

    if _urls_key:
        if len(depsdict[_urls_key]) > 7:
            _tested_urls = ''
            _actual_url = False
            for _url in depsdict[_urls_key].split(','):

                if depsdict["repo_addr"]:
                    _url = _url.replace("REPO_ADDR", depsdict["repo_addr"])

                _url = _url.replace("REPO_RELEASE", depsdict["cdistver"])
                _url = _url.replace("REPO_MAJOR_RELEASE",
                                    depsdict["cdistmajorver"])
                _url = _url.replace("REPO_ARCH", depsdict["carch"])
                _url = _url.replace("ARCH", depsdict["carch"].strip())
                _url = _url.replace("DISTRO", depsdict["cdistkind"].strip())
                _url = _url.replace("USERNAME", depsdict["username"].strip())

                if check_url(_url, "ARCH", depsdict["carch"]):
                    _actual_url = _url
                    break
                else:
                    if not _tested_urls.count(_url):
                        _tested_urls += _url + ','

            if not _actual_url:
                _msg = "##### None of the urls indicated to install \"" + depkey + "\" ("
                _msg += _tested_urls + ") seem to be functional."

                if exception_if_no_url:
                    raise Exception(_msg)
                else:
                    cbwarn(_msg)
        else:
            _actual_url = False
    else:
        _actual_url = False

    _actual_cmdline = ""
    _actual_cmdline_keys = ''

    if operation == "install":
        for _sub_step in ["preinstall", "install", "postinstall"]:

            _commandline_keys = []

            _commandline_keys.append(depsdict["cdistnam"] + '-' + depkey +
                                     '-' + _sub_step + '-' +
                                     depsdict[depkey + '-' + operation])
            _commandline_keys.append(depsdict["cdistkind"] + '-' + depkey +
                                     '-' + _sub_step + '-' +
                                     depsdict[depkey + '-' + operation])
            _commandline_keys.append("common-" + depkey + '-' + _sub_step +
                                     '-' + depsdict[depkey + '-' + operation])

            _x, _y = get_actual_cmdline(_commandline_keys, depsdict,
                                        _actual_url)

            _actual_cmdline_keys += _x + ','

            _actual_cmdline += _y + ';'

    else:
        _commandline_keys = [depkey + '-' + operation]

        _x, _y = get_actual_cmdline(_commandline_keys, depsdict, _actual_url)

        _actual_cmdline_keys += _x + ','
        _actual_cmdline += _y + ';'

    if _actual_cmdline_keys[0] == ',':
        _actual_cmdline_keys = _actual_cmdline_keys[1:]

    if _actual_cmdline_keys[-1] == ',':
        _actual_commandline_keys = _actual_cmdline_keys[0:-1]

    if _actual_cmdline[0] == ';':
        _actual_cmdline = _actual_cmdline[1:]

    if _actual_cmdline[-1] == ';':
        _actual_cmdline = _actual_cmdline[0:-1]

    _actual_cmdline = expand_command(_actual_cmdline, depsdict,
                                     process_manager)

    _actual_cmdline_keys = _actual_cmdline_keys.replace(",,", ',')
    _actual_cmdline_keys = _actual_cmdline_keys.replace(",,", ',')
    _actual_cmdline_keys = _actual_cmdline_keys.replace("_equal_", '=')

    _actual_cmdline = _actual_cmdline.replace(";;", ';')
    _actual_cmdline = _actual_cmdline.replace(";;", ';')
    _actual_cmdline = _actual_cmdline.replace(";;", ';')
    _actual_cmdline = _actual_cmdline.replace("_equal_", '=')

    return _actual_commandline_keys, _actual_cmdline