def walk(root): for entry in pyotherside.qrc_list_dir(root): name = os.path.join(root, entry) if pyotherside.qrc_is_dir(name): walk(name) else: print(name, '=', len(pyotherside.qrc_get_file_contents(name)), 'bytes')
def internal_isdir(path): """Internal isdir function that works on both normal files and files bundled in qrc. :param str path: path to the folder to check :returns: True if path is file, False if not :rtype: bool """ if qrc.is_qrc: return pyotherside.qrc_is_dir(path) else: return os.path.isdir(path)
def export_from_qrc(root, target): """Recursively export a given qrc subtree as given by root to the target folder. """ #log.debug("exporting %s from qrc", root) try: file_counter = 0 folder_counter = 0 for entry in pyotherside.qrc_list_dir(root): name = os.path.join(root, entry) if pyotherside.qrc_is_dir(name): #log.debug('Creating directory: %s', name) os.makedirs(os.path.join(target, name)) folder_counter += 1 export_from_qrc(name, os.path.join(target, name)) else: data = pyotherside.qrc_get_file_contents(name) #log.debug('Creating file: %s (%d bytes)', name, len(data)) with open(name, "wb") as f: f.write(data) file_counter += 1 #log.debug("%d files and %d folders exported from %s", file_counter, folder_counter, root) except Exception: log.exception("qrc export from %s to %s failed", root, target)
import pyotherside import os.path import sys print('Hello from module!') print(sys.path) print('file exists?', pyotherside.qrc_is_file('qrc_example.qml')) print('file exists?', pyotherside.qrc_is_file('qrc_example.qml.nonexistent')) print('dir exists?', pyotherside.qrc_is_dir('/')) print('dir exists?', pyotherside.qrc_is_dir('/nonexistent')) print('='*30) def walk(root): for entry in pyotherside.qrc_list_dir(root): name = os.path.join(root, entry) if pyotherside.qrc_is_dir(name): walk(name) else: print(name, '=', len(pyotherside.qrc_get_file_contents(name)), 'bytes') walk('/') print('='*30) print(pyotherside.qrc_get_file_contents('qrc_example.py').decode('utf-8')) print('='*30) try: print('dir exists with number', pyotherside.qrc_is_dir(123)) except Exception as e: print('got exception (as expected):', e) try: print('file exists with none', pyotherside.qrc_is_file(None))