コード例 #1
0
ファイル: test_reuse.py プロジェクト: cdgriffith/Reusables
    def test_archive(self):
        p1 = reusables.archive("data", overwrite=True)
        assert p1.endswith("archive.zip")
        assert os.path.exists(p1)
        try:
            p1 = reusables.archive("data")
        except OSError:
            pass
        else:
            raise AssertionError("Should complain about overwrite")
        finally:
            os.unlink(p1)

        p2 = reusables.archive("__init__.py", name="archive.tar")
        assert p2.endswith("archive.tar")
        assert os.path.exists(p2)
        os.unlink(p2)
        p3 = reusables.archive("__init__.py", name="archive.gz")
        assert p3.endswith("archive.gz")
        assert os.path.exists(p3)
        os.unlink(p3)
        p4 = reusables.archive("__init__.py", name="archive.bz2")
        assert p4.endswith("archive.bz2")
        assert os.path.exists(p4)
        os.unlink(p4)
コード例 #2
0
    def test_archive(self):
        p1 = reusables.archive("data", overwrite=True)
        assert p1.endswith("archive.zip")
        assert os.path.exists(p1)
        try:
            p1 = reusables.archive("data")
        except OSError:
            pass
        else:
            raise AssertionError("Should complain about overwrite")
        finally:
            os.unlink(p1)

        p2 = reusables.archive("__init__.py", name="archive.tar")
        assert p2.endswith("archive.tar")
        assert os.path.exists(p2)
        os.unlink(p2)
        p3 = reusables.archive("__init__.py", name="archive.gz")
        assert p3.endswith("archive.gz")
        assert os.path.exists(p3)
        os.unlink(p3)
        p4 = reusables.archive("__init__.py", name="archive.bz2")
        assert p4.endswith("archive.bz2")
        assert os.path.exists(p4)
        os.unlink(p4)
コード例 #3
0
def clean_logs(signal, app, **_):
    compress = []
    total_files = len(list(app.fastflix.log_path.iterdir()))
    for i, file in enumerate(app.fastflix.log_path.iterdir()):
        signal.emit(int((i / total_files) * 75))
        app.processEvents()
        if not file.name.endswith(".log"):
            continue
        try:
            is_old = (datetime.now() - datetime.fromisoformat(
                file.stem[-19:].replace(".", ":"))) > timedelta(days=14)
        except ValueError:
            is_old = True
        if file.name.startswith("flix_gui"):
            if is_old:
                logger.debug(f"Deleting {file.name}")
                file.unlink(missing_ok=True)
        if file.name.startswith("flix_conversion") or file.name.startswith(
                "flix_2"):
            original = file.read_text(encoding="utf-8", errors="ignore")
            try:
                condensed = "\n".join(
                    (line for line in original.splitlines()
                     if "Skipping NAL unit" not in line
                     and "Last message repeated" not in line))
            except UnicodeDecodeError:
                pass
            else:
                if (len(condensed) + 100) < len(original):
                    logger.debug(
                        f"Compressed {file.name} from {len(original)} characters to {len(condensed)}"
                    )
                    file.write_text(condensed, encoding="utf-8")
            if is_old:
                logger.debug(f"Adding {file.name} to be compress")
                compress.append(file)
    if compress:
        reusables.pushd(app.fastflix.log_path)
        try:
            reusables.archive(
                [str(name.name) for name in compress],
                name=str(app.fastflix.log_path /
                         f"flix_conversion_logs_{file_date()}.zip"),
            )
        finally:
            reusables.popd()
        signal.emit(95)
        for file in compress:
            file.unlink(missing_ok=True)
    signal.emit(100)
コード例 #4
0
ファイル: test_reuse.py プロジェクト: cdgriffith/Reusables
    def test_bad_archive_type(self):
        try:
            reusables.archive("__init__.py", archive_type="rar")
        except ValueError:
            pass
        else:
            raise AssertionError("Should raise value error about archive_type")

        try:
            reusables.archive("__init__.py", "asdf.gah")
        except ValueError:
            pass
        else:
            raise AssertionError("You cant figure out that archive type ")
コード例 #5
0
    def test_bad_archive_type(self):
        try:
            reusables.archive("__init__.py", archive_type="rar")
        except ValueError:
            pass
        else:
            raise AssertionError("Should raise value error about archive_type")

        try:
            reusables.archive("__init__.py", "asdf.gah")
        except ValueError:
            pass
        else:
            raise AssertionError("You cant figure out that archive type ")