|
|
@@ -8,21 +8,31 @@ import os
|
|
|
|
|
|
def main():
|
|
|
args = _parser()
|
|
|
+
|
|
|
+ print("Arguments: ", args) if args.debug else None
|
|
|
+
|
|
|
if "func" in args:
|
|
|
- return args.func()
|
|
|
+ return args.func(args)
|
|
|
|
|
|
def _parser():
|
|
|
import argparse as ap
|
|
|
parser = ap.ArgumentParser()
|
|
|
parser.set_defaults(func=parser.print_help)
|
|
|
parser.add_argument("-d", "--debug", action="count", default=0)
|
|
|
+
|
|
|
subp = parser.add_subparsers()
|
|
|
subp_sc = subp.add_parser("shellscript")
|
|
|
subp_sc.set_defaults(func=_shellscript_command)
|
|
|
+
|
|
|
subp_sc = subp.add_parser("cronjob")
|
|
|
subp_sc.set_defaults(func=lambda:print(Cronjob(command="asdf")))
|
|
|
+
|
|
|
subp_sc = subp.add_parser("install")
|
|
|
subp_sc.set_defaults(func=_install_command)
|
|
|
+
|
|
|
+ subp_sc = subp.add_parser("test")
|
|
|
+ subp_sc.set_defaults(func=_test_command)
|
|
|
+
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def _shellscript_command(args):
|
|
|
@@ -31,6 +41,11 @@ def _shellscript_command(args):
|
|
|
def _install_command(args):
|
|
|
return bash(SHELLSCRIPT).returncode
|
|
|
|
|
|
+def _test_command(args):
|
|
|
+ proc = tarxz(".", "/dev/null", debug=args.debug)
|
|
|
+ proc.wait()
|
|
|
+ return proc.returncode
|
|
|
+
|
|
|
def bash(script="", args=[], encoding="utf-8"):
|
|
|
import subprocess as sub
|
|
|
proc = sub.Popen(["bash"], stdin=sub.PIPE)
|
|
|
@@ -39,8 +54,32 @@ def bash(script="", args=[], encoding="utf-8"):
|
|
|
proc.wait()
|
|
|
return proc
|
|
|
|
|
|
-def tarxz():
|
|
|
- pass
|
|
|
+def checkmount(mountpoints):
|
|
|
+ if type(mountpoints) == str:
|
|
|
+ mountpoints = [mountpoints]
|
|
|
+ mounts = [a.split() for a in open("/proc/mounts").readlines()]
|
|
|
+ for mp in mountpoints:
|
|
|
+ pass
|
|
|
+
|
|
|
+def tarxz(infiles, tarxzfile, relative_root="/", parallel=0, debug=0):
|
|
|
+ import subprocess as sub
|
|
|
+ if type(infiles) == str:
|
|
|
+ infiles = [infiles]
|
|
|
+ infiles = [
|
|
|
+ os.path.relpath(f, start=relative_root)
|
|
|
+ for f in infiles
|
|
|
+ ]
|
|
|
+ env = os.environ.copy()
|
|
|
+ env.update({
|
|
|
+ "XZ_OPT": "-4e -T {parallel}".format(parallel=parallel),
|
|
|
+ })
|
|
|
+ CMD = ["tar", "-c", "-J", "-C", relative_root, "-f", tarxzfile] + infiles
|
|
|
+
|
|
|
+ print("tarxz env:",env) if debug>1 else None
|
|
|
+ print("tarxz CMD:",CMD) if debug else None
|
|
|
+ proc = sub.Popen(CMD, env=env)
|
|
|
+ return proc
|
|
|
+
|
|
|
|
|
|
class Cronjob:
|
|
|
_minute = "*"
|