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')
Beispiel #2
0
    async def default_data(self) -> str:
        path = f"src/themes/{self.filename}"

        try:
            byte_content = pyotherside.qrc_get_file_contents(path)
        except ValueError:
            # App was compiled without QRC
            async with aiofiles.open(path) as file:
                return await file.read()
        else:
            return byte_content.decode()
Beispiel #3
0
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
Beispiel #4
0
    def from_file(
        cls, path: Union[str, Path], builtins: Union[str, Path] = BUILTINS_DIR,
    ) -> "Section":

        path = Path(re.sub(r"^qrc:/", "", str(path)))

        try:
            content = pyotherside.qrc_get_file_contents(str(path)).decode()
        except ValueError:  # App was compiled without QRC
            content = path.read_text()

        return Section.from_source_code(content, path, Path(builtins))
Beispiel #5
0
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
Beispiel #6
0
    def default_data(self) -> str:
        if self.filename in ("Midnight.qpl", "Glass.qpl"):
            path = f"src/themes/{self.filename}"
        else:
            path = "src/themes/Midnight.qpl"

        try:
            byte_content = pyotherside.qrc_get_file_contents(path)
        except ValueError:
            # App was compiled without QRC
            return convert_to_qml(Path(path).read_text())
        else:
            return convert_to_qml(byte_content.decode())
Beispiel #7
0
def internal_get_file_contents(path):
    """Internal function for getting file content as bytearray,
    works both on normal files and files bundled in qrc.

    :param str path: path to the file to fetch
    :returns: file contents as bytearray
    :rtype: bytearray
    """

    if qrc.is_qrc:
        return pyotherside.qrc_get_file_contents(path)
    else:
        with open(path, 'rb') as f:
            return bytearray(f.read())
Beispiel #8
0
def internal_get_file_contents(path):
    """Internal function for getting file content as bytearray,
    works both on normal files and files bundled in qrc.

    :param str path: path to the file to fetch
    :returns: file contents as bytearray
    :rtype: bytearray
    """

    if qrc.is_qrc:
        return pyotherside.qrc_get_file_contents(path)
    else:
        with open(path, 'rb') as f:
            return bytearray(f.read())
Beispiel #9
0
    async def sound_notify(self) -> None:
        path = self.settings.Notifications.default_sound
        path = str(Path(path).expanduser())

        if path == "default.wav":
            path = "src/sounds/default.wav"

        try:
            content = pyotherside.qrc_get_file_contents(path)
        except ValueError:
            sa = simpleaudio.WaveObject.from_wave_file(path)
        else:
            wave_read = wave.open(io.BytesIO(content))
            sa        = simpleaudio.WaveObject.from_wave_read(wave_read)

        try:
            sa.play()
            self.audio_working = True
        except Exception as e:  # noqa
            if self.audio_working:
                trace = traceback.format_exc().rstrip()
                log.error("Playing audio failed\n%s", trace)
                self.audio_working = False
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
 def get_data(self, path):
     return pyotherside.qrc_get_file_contents(path[len('qrc:'):])
 def get_data(self, path):
     return pyotherside.qrc_get_file_contents(path[len('qrc:'):])
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))
except Exception as e:
    print('got exception (as expected):', e)

try:
    print('dir entries with invalid', pyotherside.qrc_list_dir('/nonexistent'))
except Exception as e: