def get_filename(self, fullname): basename = fullname.replace('.', '/') for import_path in sys.path: if not import_path.startswith('qrc:'): continue for candidate in ('{}/{}.py', '{}/{}/__init__.py'): filename = candidate.format(import_path, basename) if pyotherside.qrc_is_file(filename[len('qrc:'):]): return filename
def get_filename(self, fullname): basename = fullname.replace('.', '/') for import_path in sys.path: if not import_path.startswith('qrc:'): continue for candidate in ('{}/{}.py', '{}/{}/__init__.py'): filename = candidate.format(import_path, basename) if pyotherside.qrc_is_file(filename[len('qrc:'):]): return filename
def _get_qrc_version(): from core import paths if pyotherside.qrc_is_file(paths.VERSION_INFO_FILENAME): try: return pyotherside.qrc_get_file_contents(paths.VERSION_INFO_FILENAME).decode("utf-8").rstrip() except Exception: log.exception("reading modRana version from qrc file failed") return None else: log.warning("modRana version qrc file not found (development version ?)") return None
def internal_isfile(path): """Internal isfile function that works on both normal files and files bundled in qrc. :param str path: path to the file to check :returns: True if path is file, False if not :rtype: bool """ if qrc.is_qrc: return pyotherside.qrc_is_file(path) else: return os.path.isfile(path)
def internal_isfile(path): """Internal isfile function that works on both normal files and files bundled in qrc. :param str path: path to the file to check :returns: True if path is file, False if not :rtype: bool """ if qrc.is_qrc: return pyotherside.qrc_is_file(path) else: return os.path.isfile(path)
def _get_qrc_version(): from core import paths if pyotherside.qrc_is_file(paths.VERSION_INFO_FILENAME): try: return pyotherside.qrc_get_file_contents( paths.VERSION_INFO_FILENAME).decode("utf-8").rstrip() except Exception: log.exception("reading modRana version from qrc file failed") return None else: log.warning( "modRana version qrc file not found (development version ?)") return None
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))