Beispiel #1
0
def download(mode, passwordObj):
    if not utils.check_network_connection():
        log.error("Internet connection not found.")
        return ERROR_NO_NETWORK, "", "", queryString(ERROR_NO_NETWORK)

    else:
        sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
        if sts is True:
            hplip_si_conf = ConfigBase(HPLIP_file)
            source = hplip_si_conf.get("SMART_INSTALL", "url", "")
            if not source:
                log.error("Failed to download %s." % HPLIP_INFO_SITE)
                return ERROR_FAILED_TO_DOWNLOAD_FILE, "", "", queryString(
                    ERROR_FAILED_TO_DOWNLOAD_FILE, 0, HPLIP_INFO_SITE)

        sts, smart_install_run = utils.download_from_network(source)
        if not sts:
            log.error("Failed to download %s." % source)
            return ERROR_FAILED_TO_DOWNLOAD_FILE, "", "", queryString(
                ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source)

        sts, smart_install_asc = utils.download_from_network(source + '.asc')
        if not sts:
            log.error("Failed to download %s." % (source + '.asc'))
            return ERROR_FAILED_TO_DOWNLOAD_FILE, "", "", queryString(
                ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source + ".asc")

        digsig_sts, smart_install_run, smart_install_asc, error_str = validate(
            mode, smart_install_run, smart_install_asc)

        return digsig_sts, smart_install_run, smart_install_asc, error_str
Beispiel #2
0
def download_hplip_installer(path_to_download, hplip_version):
    url = "%s/%s/hplip-%s.run" % (HPLIP_PACKAGE_SITE, hplip_version,
                                  hplip_version)
    hplip_package = "%s/hplip-%s.run" % (path_to_download, hplip_version)

    log.info("Downloading hplip-%s.run file..... Please wait. " %
             hplip_version)
    sts, download_file = utils.download_from_network(url, hplip_package, True)
    log.info("")

    if not os.path.exists(hplip_package):
        log.error("Failed to download %s file." % hplip_package)
        return '', ''

    log.info("Downloading hplip-%s.run.asc file..... Please wait. " %
             hplip_version)
    hplip_digsig = hplip_package + ".asc"
    url = url + ".asc"
    sts, download_file = utils.download_from_network(url, hplip_digsig)
    log.info("")

    if not os.path.exists(hplip_digsig):
        log.error("Failed to download %s file." % hplip_package)
        return hplip_package, ''

    return hplip_package, hplip_digsig
Beispiel #3
0
    def disable_smart_install(self):
        if not utils.check_network_connection():
            FailureUI(self, queryString(ERROR_NO_NETWORK))
        else:
            sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
            if sts == 0:
                hplip_si_conf = ConfigBase(HPLIP_file)
                source = hplip_si_conf.get("SMART_INSTALL","url","")
                if not source :
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, HPLIP_INFO_SITE))
                    return 

            response_file, smart_install_run = utils.download_from_network(source)
            response_asc, smart_install_asc = utils.download_from_network(source+'.asc')
            
            if response_file == 0   and response_asc == 0:

                gpg_obj = validation.GPG_Verification()
                digsig_sts, error_str = gpg_obj.validate(smart_install_run, smart_install_asc)

                if ERROR_SUCCESS == digsig_sts:
                    sts, out = utils.run("sh %s"%smart_install_run)
                else:
                
                    if QMessageBox.question(self, " ",
                        self.__tr("<b>%s</b><p>Without this, it is not possible to authenticate and validate this tool prior to installation.</p>Do you still want to run Smart Install disabler?" %error_str),
                        QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes:
                        # Disabling without verification.
                        sts, out = utils.run("sh %s"%smart_install_run)

            else:
                if response_asc:
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source + ".asc"))
                else:
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source))
Beispiel #4
0
def download(mode, passwordObj):
    if not utils.check_network_connection():
        log.error("Internet connection not found.")
        return ERROR_NO_NETWORK, "" , "" ,queryString(ERROR_NO_NETWORK)

    else:
        sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
        if sts is True:
            hplip_si_conf = ConfigBase(HPLIP_file)
            source = hplip_si_conf.get("SMART_INSTALL","url","")
            if not source:
                log.error("Failed to download %s."%HPLIP_INFO_SITE)
                return ERROR_FAILED_TO_DOWNLOAD_FILE, "" , "", queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, HPLIP_INFO_SITE)

        sts, smart_install_run = utils.download_from_network(source)
        if not sts:
            log.error("Failed to download %s."%source)
            return ERROR_FAILED_TO_DOWNLOAD_FILE, "" , "", queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source)

        sts, smart_install_asc = utils.download_from_network(source+'.asc')
        if not sts:
            log.error("Failed to download %s."%(source+'.asc'))
            return ERROR_FAILED_TO_DOWNLOAD_FILE, "" , "", queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source + ".asc")

        digsig_sts, smart_install_run, smart_install_asc, error_str = validate(mode, smart_install_run, smart_install_asc)

        return digsig_sts, smart_install_run, smart_install_asc, error_str
Beispiel #5
0
    def disable_smart_install(self):
        if not utils.check_network_connection():
            FailureUI(self, queryString(ERROR_NO_NETWORK))
        else:
            sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
            if sts == 0:
                hplip_si_conf = ConfigBase(HPLIP_file)
                source = hplip_si_conf.get("SMART_INSTALL","url","")
                if not source :
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, HPLIP_INFO_SITE))
                    return 

            response_file, smart_install_run = utils.download_from_network(source)
            response_asc, smart_install_asc = utils.download_from_network(source+'.asc')
            
            if response_file == 0   and response_asc == 0:

                gpg_obj = validation.GPG_Verification()
                digsig_sts, error_str = gpg_obj.validate(smart_install_run, smart_install_asc)

                if ERROR_SUCCESS == digsig_sts:
                    sts, out = utils.run("sh %s"%smart_install_run)
                else:
                
                    if QMessageBox.question(self, " ",
                        self.__tr("<b>%s</b><p>Without this, it is not possible to authenticate and validate this tool prior to installation.</p>Do you still want to run Smart Install disabler?" %error_str),
                                            QMessageBox.Yes | QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
                        # Disabling without verification.
                        sts, out = utils.run("sh %s"%smart_install_run)

            else:
                if response_asc:
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source + ".asc"))
                else:
                    FailureUI(self, queryString(ERROR_FAILED_TO_DOWNLOAD_FILE, 0, source))
Beispiel #6
0
    def __getPluginInformation(self, callback=None):
        status, url, check_sum = ERROR_NO_NETWORK, '', ''

        if self.__plugin_conf_file.startswith('http://'):
            if not utils.check_network_connection():
                log.error("Network connection not detected.")
                return ERROR_NO_NETWORK, '', 0

        local_conf_fp, local_conf = utils.make_temp_file()

        try:
            try:
                if self.__plugin_conf_file.startswith('file://'):
                    status, filename = utils.download_from_network(
                        self.__plugin_conf_file, local_conf, True)
                else:
                    wget = utils.which("wget", True)
                    if wget:
                        status, output = utils.run(
                            "%s --tries=3 --timeout=60 --output-document=%s %s --cache=off"
                            % (wget, local_conf, self.__plugin_conf_file))
                        if status:
                            log.error(
                                "Plugin download failed with error code = %d" %
                                status)
                            return status, url, check_sum
                    else:
                        log.error(
                            "Please install wget package to download the plugin."
                        )
                        return status, url, check_sum
            except IOError as e:
                log.error("I/O Error: %s" % e.strerror)
                return status, url, check_sum

            if not os.path.exists(local_conf):
                log.error("plugin.conf not found.")
                return status, url, check_sum

            try:
                plugin_conf_p = ConfigBase(local_conf)
                url = plugin_conf_p.get(self.__required_version, 'url', '')
                check_sum = plugin_conf_p.get(self.__required_version,
                                              'checksum')
                status = ERROR_SUCCESS
            except (KeyError, configparser.NoSectionError) as e:
                log.error(
                    "Error reading plugin.conf: Missing section [%s]  Error[%s]"
                    % (self.__required_version, e))
                return ERROR_FILE_NOT_FOUND, url, check_sum

            if url == '':
                return ERROR_FILE_NOT_FOUND, url, check_sum

        finally:
            os.close(local_conf_fp)
            os.remove(local_conf)

        return status, url, check_sum
Beispiel #7
0
def get_hplip_version_from_hplipopensource():
    HPLIP_latest_ver="0.0.0"
    pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
    if sts == 0:
        HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)
        os.unlink(HPLIP_Ver_file)

    return HPLIP_latest_ver
Beispiel #8
0
def get_hplip_version_from_hplipopensource():
    HPLIP_latest_ver="0.0.0"
    pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
    if sts == 0:
        HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)
        os.unlink(HPLIP_Ver_file)

    return HPLIP_latest_ver
Beispiel #9
0
def get_hplip_version_from_sourceforge():
    HPLIP_latest_ver="0.0.0"

    # get HPLIP version info from hplip_web.conf file
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SOURCEFORGE_SITE)
    if sts == 0:
        hplip_version_conf = ConfigBase(HPLIP_Ver_file)
        HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")
        os.unlink(HPLIP_Ver_file)

    return HPLIP_latest_ver
Beispiel #10
0
def get_hplip_version_from_sourceforge():
    HPLIP_latest_ver="0.0.0"

    # get HPLIP version info from hplip_web.conf file
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SOURCEFORGE_SITE)
    if sts == 0:
        hplip_version_conf = ConfigBase(HPLIP_Ver_file)
        HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")
        os.unlink(HPLIP_Ver_file)

    return HPLIP_latest_ver
Beispiel #11
0
def download_hplip_installer(path_to_download, hplip_version):
    url="%s/%s/hplip-%s.run" %(HPLIP_PACKAGE_SITE, hplip_version, hplip_version)
    hplip_package = "%s/hplip-%s.run" %(path_to_download, hplip_version)

    log.info("Downloading hplip-%s.run file..... Please wait. "%hplip_version )
    sts,download_file = utils.download_from_network(url, hplip_package, True)
    log.info("")

    if not os.path.exists(hplip_package):
        log.error("Failed to download %s file."%hplip_package)
        return '',''

    log.info("Downloading hplip-%s.run.asc file..... Please wait. "%hplip_version )
    hplip_digsig =  hplip_package+".asc"
    url = url +".asc"
    sts,download_file = utils.download_from_network(url, hplip_digsig)
    log.info("")

    if not os.path.exists(hplip_digsig):
        log.error("Failed to download %s file."%hplip_package)
        return hplip_package, ''

    return hplip_package, hplip_digsig
Beispiel #12
0
    def __getPluginInformation(self, callback=None):
        status, url, check_sum = ERROR_NO_NETWORK, '',''

        if self.__plugin_conf_file.startswith('http://'):
            if not utils.check_network_connection():
                log.error("Network connection not detected.")
                return ERROR_NO_NETWORK, '', 0

        local_conf_fp, local_conf = utils.make_temp_file()

        try:
            try:
                if self.__plugin_conf_file.startswith('file://'):
                    status, filename = utils.download_from_network(self.__plugin_conf_file, local_conf, True)
                else:
                    wget = utils.which("wget", True)
                    if wget:
                        status, output = utils.run("%s --timeout=60 --output-document=%s %s --cache=off" %(wget, local_conf, self.__plugin_conf_file))
                        if status:
                            log.error("Plugin download failed with error code = %d" %status)
                            return status, url, check_sum
                    else:
                        log.error("Please install wget package to download the plugin.")
                        return status, url, check_sum
            except IOError as e:
                log.error("I/O Error: %s" % e.strerror)
                return status, url, check_sum

            if not os.path.exists(local_conf):
                log.error("plugin.conf not found.")
                return status, url, check_sum

            try:
                plugin_conf_p = ConfigBase(local_conf)
                url = plugin_conf_p.get(self.__required_version, 'url','')
                check_sum  = plugin_conf_p.get(self.__required_version, 'checksum')
                status = ERROR_SUCCESS
            except (KeyError, configparser.NoSectionError) as e:
                log.error("Error reading plugin.conf: Missing section [%s]  Error[%s]" % (self.__required_version,e))
                return ERROR_FILE_NOT_FOUND, url, check_sum

            if url == '':
                return ERROR_FILE_NOT_FOUND, url, check_sum

        finally:
            os.close(local_conf_fp)
            os.remove(local_conf)

        return status, url, check_sum
Beispiel #13
0
def download(mode, passwordObj):
    if not utils.check_network_connection():
        log.error("Internet connection not found.")
        return SIH_FAILED_TO_DOWNLOAD, "", ""

    else:
        sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
        if sts is True:
            hplip_si_conf = ConfigBase(HPLIP_file)
            source = hplip_si_conf.get("SMART_INSTALL", "url", "")
            if not source:
                log.error("Failed to download %s." % HPLIP_INFO_SITE)
                return SIH_FAILED_TO_DOWNLOAD, "", ""

        sts, smart_install_run = utils.download_from_network(source)
        if not sts:
            log.error("Failed to download %s." % source)
            return SIH_FAILED_TO_DOWNLOAD, "", ""

        sts, smart_install_asc = utils.download_from_network(source + ".asc")
        if not sts:
            log.error("Failed to download %s." % (source + ".asc"))
            return SIH_FAILED_TO_VERIFY_DIG_SIGN, smart_install_run, ""

        if passwordObj == None:
            try:
                from base.password import Password
            except ImportError:
                return SIH_FAILED_TO_VERIFY_DIG_SIGN, smart_install_run, ""
            passwordObj = Password(mode)

        if utils.ERROR_NONE == utils.validateDownloadFile(smart_install_run, smart_install_asc, "", passwordObj):
            return SIH_VERIFIED_DIG_SIGN, smart_install_run, smart_install_asc
        else:
            log.error("GPG verification failed for %s ." % source)
            return SIH_FAILED_TO_VERIFY_DIG_SIGN, smart_install_run, smart_install_asc
Beispiel #14
0
def get_SmartInstall_tool_info():
    url, file_name = "", ""
    if not utils.check_network_connection():
        log.error("Internet connection not found.")
    else:
        sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
        if sts is True:
            hplip_si_conf = ConfigBase(HPLIP_file)
            url = hplip_si_conf.get("SMART_INSTALL","reference","")
            if url:
                file_name = 'SmartInstallDisable-Tool.run'
            else:
                log.error("Failed to download %s."%HPLIP_INFO_SITE)
        else:
            log.error("Failed to download %s."%HPLIP_INFO_SITE)

    return url, file_name
Beispiel #15
0
def get_SmartInstall_tool_info():
    url, file_name = "", ""
    if not utils.check_network_connection():
        log.error("Internet connection not found.")
    else:
        sts, HPLIP_file = utils.download_from_network(HPLIP_INFO_SITE)
        if sts is True:
            hplip_si_conf = ConfigBase(HPLIP_file)
            url = hplip_si_conf.get("SMART_INSTALL", "reference", "")
            if url:
                file_name = 'SmartInstallDisable-Tool.run'
            else:
                log.error("Failed to download %s." % HPLIP_INFO_SITE)
        else:
            log.error("Failed to download %s." % HPLIP_INFO_SITE)

    return url, file_name
Beispiel #16
0
try:
    change_spinner_state(False)
    core =  CoreInstall(MODE_CHECK)
#    core.init()
    if not core.check_network_connection():
        log.error("Either Internet is not working or Wget is not installed.")
        clean_exit(0)

    installed_version=sys_conf.get("hplip","version","0.0.0")
    log.debug("HPLIP previous installed version =%s." %installed_version)



    HPLIP_latest_ver="0.0.0"
    # get HPLIP version info from hplip_web.conf file
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SITE)    
    if sts is True:
        hplip_version_conf = ConfigBase(HPLIP_Ver_file)
        HPLIP_latest_ver = hplip_version_conf.get("HPLIP","Latest_version","0.0.0")

    # get HPLIP version info from hplip site
    if HPLIP_latest_ver == "0.0.0":	## if failed to connect the sourceforge site, then check HPLIP site.
        pat = re.compile(r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*""")
        sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
        if sts is True:
            HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)

    if HPLIP_latest_ver == "0.0.0":
        log.error("Failed to get latest version of HPLIP.")
        clean_exit(0)
Beispiel #17
0
    def download(self, pluginPath='',callback = None):

        core = core_install.CoreInstall()

        if pluginPath:#     and os.path.exists(pluginPath):
            src = pluginPath
            checksum = ""       # TBD: Local copy may have different checksum. So ignoring checksum
        else:
            sts, url, checksum = self.__getPluginInformation(callback)
            src = url
            if sts != ERROR_SUCCESS:
                return sts, "", queryString(ERROR_CHECKSUM_ERROR, 0, src)

        log.debug("Downloading %s plug-in file from '%s' to '%s'..." % (self.__required_version, src, self.__plugin_path))
        plugin_file = os.path.join(self.__plugin_path, self.__plugin_name)
        try:
            os.umask(0)
            if not os.path.exists(self.__plugin_path):
                os.makedirs(self.__plugin_path, 0o755)
            if os.path.exists(plugin_file):
                os.remove(plugin_file)
            if os.path.exists(plugin_file+'.asc'):
                os.remove(plugin_file+'.asc')

        except (OSError, IOError) as e:
            log.error("Failed in OS operations:%s "%e.strerror)
            return ERROR_DIRECTORY_NOT_FOUND, "", self.__plugin_path + queryString(102)

        try:
            if src.startswith('file://'):
                status, filename = utils.download_from_network(src, plugin_file, True)
            else:
                wget = utils.which("wget", True)
                if wget:
                    cmd = "%s --cache=off -P %s %s" % (wget,self.__plugin_path,src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)
                    log.debug("wget returned: %d" % status)

                #Check whether plugin is accessible in Openprinting.org website otherwise dowload plugin from alternate location.
                if status != 0 or os_utils.getFileSize(plugin_file) <= 0:
                    src = os.path.join(PLUGIN_FALLBACK_LOCATION, self.__plugin_name)
                    log.info("Plugin is not accessible. Trying to download it from fallback location: [%s]" % src)
                    cmd = "%s --cache=off -P %s %s" % (wget,self.__plugin_path,src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)


        except IOError as e:
            log.error("Plug-in download failed: %s" % e.strerror)
            return ERROR_FILE_NOT_FOUND, "", queryString(ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if status !=0 or os_utils.getFileSize(plugin_file) <= 0: 
            log.error("Plug-in download failed." ) 
            return ERROR_FILE_NOT_FOUND, "", queryString(ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if core.isErrorPage(open(plugin_file, 'r').read(1024)):
            log.debug("open(plugin_file, 'r').read(1024)")
            os.remove(plugin_file)
            return ERROR_FILE_NOT_FOUND, "", queryString(ERROR_FILE_NOT_FOUND, 0, plugin_file)

        # Try to download and check the GPG digital signature
        digsig_url = src + '.asc'
        digsig_file = plugin_file + '.asc'

        log.debug("Downloading %s plug-in digital signature file from '%s' to '%s'..." % (self.__required_version, digsig_url, digsig_file))

        try:
            if digsig_url.startswith('file://'):
                status, filename = utils.download_from_network(digsig_url, digsig_file, True)
            else:
                cmd = "%s --cache=off -P %s %s" % (wget,self.__plugin_path,digsig_url)
                log.debug(cmd)
                status, output = utils.run(cmd)
        except IOError as e:
            log.error("Plug-in GPG file [%s] download failed: %s" % (digsig_url,e.strerror))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if status !=0: 
            log.error("Plug-in GPG file [%s] download failed." % (digsig_url))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if core.isErrorPage(open(digsig_file, 'r').read(1024)):
            log.debug(open(digsig_file, 'r').read())
            os.remove(digsig_file)
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        sts, error_str = self.__validatePlugin(plugin_file, digsig_file, checksum)
        return sts, plugin_file, error_str
Beispiel #18
0
    change_spinner_state(False)
    core =  CoreInstall(MODE_CHECK)
#    core.init()
    if not core.check_network_connection():
        log.error("Either Internet is not working or Wget is not installed.")
        clean_exit(0)

    installed_version=sys_conf.get("hplip","version","0.0.0")
    log.debug("HPLIP previous installed version =%s." %installed_version)



    HPLIP_latest_ver="0.0.0"
    # get HPLIP version info from sourceforge
    pat = re.compile(r"""HPLIP (.*) Public Release""")
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_SOURCEFORGE_SITE)
    if sts is True:
        HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)

    # get HPLIP version info from hplip site
    if HPLIP_latest_ver == "0.0.0":	## if failed to connect the sourceforge site, then check HPLIP site.
        pat = re.compile(r"""The current version of the HPLIP solution is version (.*)\. \(.*""")
        sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
        if sts is True:
            HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)

    if HPLIP_latest_ver == "0.0.0":
        log.error("Failed to get latest version of HPLIP.")
        clean_exit(0)

            
Beispiel #19
0
    def download(self, pluginPath='', callback=None):

        core = core_install.CoreInstall()

        if pluginPath:  #     and os.path.exists(pluginPath):
            src = pluginPath
            checksum = ""  # TBD: Local copy may have different checksum. So ignoring checksum
        else:
            sts, url, checksum = self.__getPluginInformation(callback)
            src = url
            if sts != ERROR_SUCCESS:
                return sts, "", queryString(ERROR_CHECKSUM_ERROR, 0, src)

        log.debug("Downloading %s plug-in file from '%s' to '%s'..." %
                  (self.__required_version, src, self.__plugin_path))
        plugin_file = os.path.join(self.__plugin_path, self.__plugin_name)
        try:
            os.umask(0)
            if not os.path.exists(self.__plugin_path):
                os.makedirs(self.__plugin_path, 0o755)
            if os.path.exists(plugin_file):
                os.remove(plugin_file)
            if os.path.exists(plugin_file + '.asc'):
                os.remove(plugin_file + '.asc')

        except (OSError, IOError) as e:
            log.error("Failed in OS operations:%s " % e.strerror)
            return ERROR_DIRECTORY_NOT_FOUND, "", self.__plugin_path + queryString(
                102)

        try:
            if src.startswith('file://'):
                status, filename = utils.download_from_network(
                    src, plugin_file, True)
            else:
                wget = utils.which("wget", True)
                if wget:
                    cmd = "%s --cache=off -P %s %s" % (wget,
                                                       self.__plugin_path, src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)
                    log.debug("wget returned: %d" % status)

                #Check whether plugin is accessible in Openprinting.org website otherwise dowload plugin from alternate location.
                if status != 0 or os_utils.getFileSize(plugin_file) <= 0:
                    src = os.path.join(PLUGIN_FALLBACK_LOCATION,
                                       self.__plugin_name)
                    log.info(
                        "Plugin is not accessible. Trying to download it from fallback location: [%s]"
                        % src)
                    cmd = "%s --cache=off -P %s %s" % (wget,
                                                       self.__plugin_path, src)
                    log.debug(cmd)
                    status, output = utils.run(cmd)

        except IOError as e:
            log.error("Plug-in download failed: %s" % e.strerror)
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if status != 0 or os_utils.getFileSize(plugin_file) <= 0:
            log.error("Plug-in download failed.")
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        if core.isErrorPage(open(plugin_file, 'r').read(1024)):
            log.debug("open(plugin_file, 'r').read(1024)")
            os.remove(plugin_file)
            return ERROR_FILE_NOT_FOUND, "", queryString(
                ERROR_FILE_NOT_FOUND, 0, plugin_file)

        # Try to download and check the GPG digital signature
        digsig_url = src + '.asc'
        digsig_file = plugin_file + '.asc'

        log.debug(
            "Downloading %s plug-in digital signature file from '%s' to '%s'..."
            % (self.__required_version, digsig_url, digsig_file))

        try:
            if digsig_url.startswith('file://'):
                status, filename = utils.download_from_network(
                    digsig_url, digsig_file, True)
            else:
                cmd = "%s --cache=off -P %s %s" % (wget, self.__plugin_path,
                                                   digsig_url)
                log.debug(cmd)
                status, output = utils.run(cmd)
        except IOError as e:
            log.error("Plug-in GPG file [%s] download failed: %s" %
                      (digsig_url, e.strerror))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if status != 0:
            log.error("Plug-in GPG file [%s] download failed." % (digsig_url))
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        if core.isErrorPage(open(digsig_file, 'r').read(1024)):
            log.debug(open(digsig_file, 'r').read())
            os.remove(digsig_file)
            return ERROR_DIGITAL_SIGN_NOT_FOUND, plugin_file, queryString(
                ERROR_DIGITAL_SIGN_NOT_FOUND, 0, digsig_file)

        sts, error_str = self.__validatePlugin(plugin_file, digsig_file,
                                               checksum)
        return sts, plugin_file, error_str
Beispiel #20
0
log.debug("Upgrade log saved in: %s" % log.bold(log_file))
log.debug("")
try:
    change_spinner_state(False)
    core = CoreInstall(MODE_CHECK)
    #    core.init()
    if not core.check_network_connection():
        log.error("Either Internet is not working or Wget is not installed.")
        clean_exit(0)

    installed_version = sys_conf.get("hplip", "version", "0.0.0")
    log.debug("HPLIP previous installed version =%s." % installed_version)

    HPLIP_latest_ver = "0.0.0"
    # get HPLIP version info from hplip_web.conf file
    sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_VERSION_INFO_SITE)
    if sts is True:
        hplip_version_conf = ConfigBase(HPLIP_Ver_file)
        HPLIP_latest_ver = hplip_version_conf.get("HPLIP", "Latest_version",
                                                  "0.0.0")

    # get HPLIP version info from hplip site
    if HPLIP_latest_ver == "0.0.0":  ## if failed to connect the sourceforge site, then check HPLIP site.
        pat = re.compile(
            r"""The current version of the HPLIP solution is version (\d{1,}\.\d{1,}\.\d{1,}[a-z]{0,})\. \(.*"""
        )
        sts, HPLIP_Ver_file = utils.download_from_network(HPLIP_WEB_SITE)
        if sts is True:
            HPLIP_latest_ver = parse_HPLIP_version(HPLIP_Ver_file, pat)

    if HPLIP_latest_ver == "0.0.0":