Ejemplo n.º 1
0
    def load_from_xml(self):
        """Loads download objects from the xml file."""
        self.download_file_path = os.path.join(self.config.base_dir,
                DOWNLOADS_FILE)
        if not os.path.exists(self.download_file_path):
            self.__create_xml()
        else:
            self.tree = ET.parse(self.download_file_path)
            downloads_element = self.tree.getroot()
            for download_element in list(downloads_element):
                uri = download_element.findtext("uri")
                path = download_element.findtext("path")
                file_name = download_element.findtext("filename")
                total_size = download_element.findtext("size")
                status = download_element.findtext("status")
                date_started = download_element.findtext("date_started")
                date_completed = download_element.findtext("date_completed")

                download = Download(uri, path, date_started, date_completed)
                download.file_name = file_name
                if total_size:
                    download.total_size = int(total_size)
                if status:
                    download.status = int(status)
                if download.status == COMPLETED:
                    download.percent_complete = 100
                else:
                    if download.total_size != 0:
                        download.percent_complete = 100 * download.current_size / download.total_size
                    else:
                        download.percent_complete = 0
                self.__append_download(download)
Ejemplo n.º 2
0
    def load_from_xml(self):
        """Loads download objects from the xml file."""
        self.download_file_path = os.path.join(self.config.base_dir,
                                               DOWNLOADS_FILE)
        if not os.path.exists(self.download_file_path):
            self.__create_xml()
        else:
            self.tree = ET.parse(self.download_file_path)
            downloads_element = self.tree.getroot()
            for download_element in list(downloads_element):
                uri = download_element.findtext("uri")
                path = download_element.findtext("path")
                file_name = download_element.findtext("filename")
                total_size = download_element.findtext("size")
                status = download_element.findtext("status")
                date_started = download_element.findtext("date_started")
                date_completed = download_element.findtext("date_completed")

                download = Download(uri, path, date_started, date_completed)
                download.file_name = file_name
                if total_size:
                    download.total_size = int(total_size)
                if status:
                    download.status = int(status)
                if download.status == COMPLETED:
                    download.percent_complete = 100
                else:
                    if download.total_size != 0:
                        download.percent_complete = 100 * download.current_size / download.total_size
                    else:
                        download.percent_complete = 0
                self.__append_download(download)