From 24e4f01a3e28c2c735c68f079f5726d200f78a3b Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 5 Jul 2019 16:59:45 -0300 Subject: [PATCH] initial commit for zig project --- build.zig | 14 ++++++++ scritcher/__init__.py | 2 -- scritcher/error.py | 2 -- scritcher/executer.py | 78 ------------------------------------------- scritcher/image.py | 17 ---------- scritcher/main.py | 32 ------------------ scritcher/utils.py | 16 --------- setup.py | 14 -------- src/main.zig | 5 +++ 9 files changed, 19 insertions(+), 161 deletions(-) create mode 100644 build.zig delete mode 100644 scritcher/__init__.py delete mode 100644 scritcher/error.py delete mode 100644 scritcher/executer.py delete mode 100644 scritcher/image.py delete mode 100644 scritcher/main.py delete mode 100644 scritcher/utils.py delete mode 100644 setup.py create mode 100644 src/main.zig diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..43fcae3 --- /dev/null +++ b/build.zig @@ -0,0 +1,14 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + const exe = b.addExecutable("scritcher", "src/main.zig"); + exe.setBuildMode(mode); + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/scritcher/__init__.py b/scritcher/__init__.py deleted file mode 100644 index e4c2998..0000000 --- a/scritcher/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .main import main -__all__ = ['main'] diff --git a/scritcher/error.py b/scritcher/error.py deleted file mode 100644 index 52507c6..0000000 --- a/scritcher/error.py +++ /dev/null @@ -1,2 +0,0 @@ -class InterpreterError(Exception): - pass diff --git a/scritcher/executer.py b/scritcher/executer.py deleted file mode 100644 index 2b3a8a1..0000000 --- a/scritcher/executer.py +++ /dev/null @@ -1,78 +0,0 @@ -import os -import shlex -import tempfile -import shutil - -from pathlib import Path -from PIL import Image - -from .utils import load_file_path -from .error import InterpreterError -from .image import GlitchImage - - -class Interpreter: - """Interpreter for scritcher instructions/statements.""" - def __init__(self): - self.orig_path = None - self.img = None - - def _cmd_noop(self): - pass - - def _cmd_load(self, loadpath: str): - source_path = load_file_path(loadpath) - self.orig_path = source_path - - # create a temporary file to hold bmp data - handle, bmp_path = tempfile.mkstemp('.bmp') - os.close(handle) - - self.img = GlitchImage(source_path, Path(bmp_path)) - self.img.load() - - def _cmd_quicksave(self): - suffix = self.img.original.suffix - name = self.img.original.name.replace(suffix, '') - parent_folder = self.orig_path.parents[0] - - # we need to search all files that match the pattern NAME_g* - # then we save on the one _g suffix above it. - - # e.g if the original path is "miya.png", we want to search for - # files named "miya_g1.raw", "miya_g2.raw", and then we want to write - # on "miya_g3.raw". - index = 0 - for glitched_out in parent_folder.glob(f'{name}_g*'): - try: - idx = int(glitched_out.name.strip(name + '_g')[0]) - - # glob() doesnt seem to show a stable order. anyways, we can - # just only update our index when its the maximum found - if idx > index: - index = idx - except (IndexError, ValueError): - continue - - # create our next glitched path - out_path = shutil.copyfile( - self.img.path, parent_folder / f'{name}_g{index + 1}.raw') - print('saved to', out_path) - - - def run(self, line: str): - """Run a single line.""" - print(f'running {line!r}') - - args = shlex.split(line) - command = args[0] - - if command != 'load' and self.img is None: - print('warn: no file loaded.') - - try: - method = getattr(self, f'_cmd_{command}') - except AttributeError: - raise InterpreterError(f'Command {command!r} not found') - - method(*args[1:]) diff --git a/scritcher/image.py b/scritcher/image.py deleted file mode 100644 index 8a16764..0000000 --- a/scritcher/image.py +++ /dev/null @@ -1,17 +0,0 @@ -import logging -from PIL import Image - -log = logging.getLogger(__name__) - -class GlitchImage: - """A wrapper class around PIL.Image""" - def __init__(self, orig_path, target_path): - self.original = orig_path - self.path = target_path - - def load(self): - """Load the given image, convert it to BMP, and write it on the - given target path.""" - log.info('opening %r into %r', self.original, self.path) - img = Image.open(self.original) - img.save(self.path, 'BMP') diff --git a/scritcher/main.py b/scritcher/main.py deleted file mode 100644 index 572c068..0000000 --- a/scritcher/main.py +++ /dev/null @@ -1,32 +0,0 @@ -import sys -import logging -from pathlib import Path - -from .executer import Interpreter -from .error import InterpreterError - -logging.basicConfig(level=logging.DEBUG) - -def main(): - try: - scri_path = Path(sys.argv[1]).resolve() - except IndexError: - print(f'usage: {sys.argv[0]} path/to/file.scri') - return - - full_text = scri_path.read_text() - full_text = full_text.replace('\n', '') - stmts = full_text.split(';') - - interp = Interpreter() - - try: - for stmt in stmts: - if not stmt: - continue - - interp.run(stmt) - - print('OK') - except InterpreterError as err: - print(f'Interpreter error. {err.args[0]!r}') diff --git a/scritcher/utils.py b/scritcher/utils.py deleted file mode 100644 index fe5d775..0000000 --- a/scritcher/utils.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys -from pathlib import Path - -from .error import InterpreterError - -def load_file_path(arg: str) -> Path: - """load given argument.""" - - try: - index = int(arg.split(':')[1]) - except ValueError: - raise InterpreterError('Invalid argument index') - except IndexError: - return Path(arg).resolve() - - return Path(sys.argv[2 + index]) diff --git a/setup.py b/setup.py deleted file mode 100644 index 852efa9..0000000 --- a/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -from setuptools import setup - -setup( - name='scritcher', - version='0.1', - py_modules=['scritcher'], - install_requires=[ - 'Pillow==6.0.0', - ], - entry_points=''' - [console_scripts] - scritcher=scritcher:main - ''', -) diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..128820d --- /dev/null +++ b/src/main.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() anyerror!void { + std.debug.warn("All your base are belong to us.\n"); +}