def reload(file_name=DEFAULT_TRANSLATION_FILE): global _initialized global _lang_db global _en_db global _lang global _locale global _file_name _file_name = file_name _lang = ENGLISH_LANG_ID if Config.language is None or Config.language == "en" else Config.language Print.debug(f"translation file is '{_file_name}'") Print.debug(f"_lang is '{_lang}'") try: with open(_file_name, encoding='utf-8') as json_file: data = json.load(json_file) _en_db = data[ENGLISH_LANG_ID] if _lang != ENGLISH_LANG_ID: _lang_db = data[_lang] _initialized = True except (FileNotFoundError, ValueError): Print.warning( f"missing translation file '{_file_name}' or it's not a JSON-file") _initialized = False Print.debug(f"_initialized is '{_initialized}'") return _initialized
def close(self): if self.isOpen(): try: self.tqdm.close() except BaseException as e: Print.warning('status exception: ' + str(e)) self.tqdm = None self.size = None # lock.release() else: #Print.debug('status not open') pass
def downloadAll(wait=True): initTitles() initFiles() global activeDownloads global status i = 0 Print.info('Downloading All') try: for k, t in Titles.items(): i = i + 1 if not t.isActive(): continue if t.isUpdateAvailable(): if not t.id or t.id == '0' * 16: Print.warning('no valid id? id: %s version: %s' % (str(t.id), str(t.lastestVersion()))) continue Titles.queue.add(t.id) Print.info("%d titles scanned, downloading %d" % (i, Titles.queue.size())) if Titles.queue.size() > 0: Titles.save() #status = Status.create(Titles.queue.size(), 'Total Download') if Config.threads <= 1: activeDownloads.append(1) downloadThread(0) else: startDownloadThreads() while wait and (not Titles.queue.empty() or sum(activeDownloads) > 0): time.sleep(1) Print.info( '%d downloads, is empty %d' % (sum(activeDownloads), int(Titles.queue.empty()))) except KeyboardInterrupt: pass except BaseException as e: Print.error(str(e)) Print.info('Downloads finished') #if status: # status.close() Print.info('DownloadAll finished')
def _load_nsp_filesize(json_title, nsp): if 'fileSize' in json_title: nsp.fileSize = json_title['fileSize'] if nsp.fileSize is None: _path = json_title['path'] Print.warning( f"Missing file size for `{_path}`. Trying to get size again...") _file_size = nsp.getFileSize() if _file_size is None: return False return True
def downloadAll(wait=True): initTitles() initFiles() global activeDownloads global status i = 0 Print.info('Downloading All') try: for k, t in Titles.items(): i = i + 1 if not t.isActive(): continue if t.isUpdateAvailable(): if not t.id or t.id == '0' * 16 or ( t.isUpdate and t.lastestVersion() in [None]): Print.warning('no valid id? id: %s version: %s' % (str(t.id), str(t.lastestVersion()))) continue if t.lastestVersion() is None: Print.info('Could not get version for ' + str(t.name) + ' [' + str(t.id) + ']') continue Titles.queue.add(t.id) Print.info("%d titles scanned, downloading %d" % (i, Titles.queue.size())) Titles.save() status = Status.create(Titles.queue.size(), 'Total Download') startDownloadThreads() while wait and (not Titles.queue.empty() or sum(activeDownloads) > 0): time.sleep(1) except KeyboardInterrupt: pass except BaseException as e: Print.error(str(e)) if status: status.close()
def tr(str_): global _initialized global _lang_db global _lang global _lang global _locale global _file_name if not _initialized: if not reload(): return str_ try: translated = _lang_db[str_] except: # pylint: disable=bare-except try: translated = _en_db[str_] except: # pylint: disable=bare-except Print.warning(f"missing translation for '{str_}' key") translated = str_ return translated
def delete_source_file(source_file_path): if os.path.exists(source_file_path): Print.info("Deleting source file {0}".format(source_file_path)) os.remove(source_file_path) else: Print.warning("{0} was already removed.".format(source_file_path))