From 5ff1700b942f69ef901fc5b05fa23ab9ef744154 Mon Sep 17 00:00:00 2001 From: Henry Corse Date: Sun, 11 Dec 2022 19:31:09 -0500 Subject: [PATCH] Adding latest work --- mineserve | 0 rdify | 58 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 13 deletions(-) create mode 100755 mineserve mode change 100644 => 100755 rdify diff --git a/mineserve b/mineserve new file mode 100755 index 0000000..e69de29 diff --git a/rdify b/rdify old mode 100644 new mode 100755 index a425f47..7a7273e --- a/rdify +++ b/rdify @@ -1,19 +1,51 @@ -#!/bin/bash - +#!/usr/bin/env python # Script to ramdiskify things -Init() -{ - if [[ -L $1 ]] && [[ -e $1 ]]; then - #statements - fi -} +import argparse +import shutil +import subprocess +import sys +from pathlib import Path -Sync() -{ +def eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) -} - -# TODO Optargs block +def init(target, persist): + ramdisk = Path("/dev/shm/ramdisk") + ramdisk.mkdir(parents=True, exist_ok=True) + target = Path(target) + persist = Path(persist) + persist.mkdir(parents=True, exist_ok=True) +def sync(target, persist): + pass + +def loop_sync(target, persist): + pass + +def cleanup(target, persist): + pass + + +def main(): + parser = argparse.ArgumentParser() + # Arguments to specify the action to take + action = parser.add_mutually_exclusive_group(required=True) + action.add_argument("-i", "--init", action="store_true", help="Initialize the target file/directory into ramdisk") + action.add_argument("-s", "--sync", action="store_true", help="Perform a single sync of the target from ramdisk to persistent storage") + action.add_argument("-l", "--loop-sync", type=int, help="Starts a repeating sync that loops every LOOP_SYNC seconds") + action.add_argument("-c", "--cleanup", action="store_true", help="clean up an existing ramdiskified target") + # Arguments to specify what to act on + parser.add_argument("target", help="The target file/directory to ramdiskify") + parser.add_argument("persist", nargs="?", default=".persist", help="The location to store the persistent copy while ramdiskified, defaults to '.persist'") + + args = parser.parse_args() + + if not Path(args.target).exists(): + eprint(f"Target: {args.target} doesn't exist!") + return + + +if __name__ == "__main__": + main()