From 0534771401e9c72c997a46267543693d3fe6ce89 Mon Sep 17 00:00:00 2001 From: jan6 Date: Wed, 26 Jun 2019 21:51:59 +0300 Subject: [PATCH] added stuff --- cli.py | 85 ++++++++++++++++++++++++++++++++++++++ dire/file | 0 dire/subdir/yetanotherfile | 0 3 files changed, 85 insertions(+) create mode 100755 cli.py create mode 100644 dire/file create mode 100644 dire/subdir/yetanotherfile diff --git a/cli.py b/cli.py new file mode 100755 index 0000000..e2d8ead --- /dev/null +++ b/cli.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import cmd +import pkg_resources as pkg +__name__="cli" + +print() +#init the array only if needed +try:listed=listed +except NameError:listed=[] +init=True + +def ls(where=""): + where=where.lstrip("/") + #doesn't appear to have effect practically, but still better to have it than not, might be needed when script used in a directory + + #just fancy bars to visually make clear where script output is +# if where != "": print("\n","─"*5+"separator"+"─"*5,"\n") + + #just fancy bars to visually make clear where script output is + if where != "": print("\n","─"*5+(where if where != "" else "/")+"─"*5,"\n") + +# print("listing",where if where != "" else "/","\n") + global listed + try: + if pkg.resource_isdir(__name__,where): + for i in pkg.resource_listdir(__name__,where): + if i != "": + if pkg.resource_isdir(__name__, where+"/"+i): + if i != "": print("DIR : ",i+"/") + else: print("FILE: ",where+"/"+i if where != "" else i) + else: + print("not a dir") #should only be called when trying to ls(file), which should not happen unless called manually + + + except RecursionError: print("\nTOO MUCH RECURSION!\n") #better than the bunch of ugly traceback python does by default + +class test_cli(cmd.Cmd): + def __init__(self, intro="Self-Resource CLI\n© jan6 & Co. 2020-3030\n", + prompt="(self/DIR) "): + cmd.Cmd.__init__(self) + self.intro=intro + self.prompt=prompt + self.doc_header="Test Cli (type 'help '):" + def emptyline(self): pass + def do_end(self, arg): + """ +just +end it... +""" + return True + #def help_end(arg): +# print("End session") + do_EOF = do_eof = do_quit = do_end + def do_quit(self, args): + if args: print(args) + return True + def precmd(self, line): + global init + newline=line.strip() + #is_cmt=newline.startswith('#') + if newline.startswith('#'): + return ('') + elif newline.startswith('/'): + if init: return 'EOF' + else: return 'quit bye' + elif newline=='': + return 'echo null' + init=False + return (line) + def do_echo(self, args): print(args) + def do_ls(self, args): + print("arguments:",args) + if not args: args="" + args=str(args) + #print("my name is "+__name__) + ls(args) + #args=str(args) + #if pkg.resource_isdir(__name__,args): pkg.resource_listdir(__name__,args) + #else: print(args) + +if True: + cli=test_cli() + cli.cmdloop() + diff --git a/dire/file b/dire/file new file mode 100644 index 0000000..e69de29 diff --git a/dire/subdir/yetanotherfile b/dire/subdir/yetanotherfile new file mode 100644 index 0000000..e69de29