Skip to content

upysh: Added rm, rmdir, clear and simplified help #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 46 additions & 17 deletions upysh/upysh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import os
from time import localtime

class LS:

Expand All @@ -12,27 +13,65 @@ def __call__(self, path="."):
l.sort()
for f in l:
st = os.stat("%s/%s" % (path, f))
tm = localtime(st[7])
if st[0] & 0x4000: # stat.S_IFDIR
print(" <dir> %s" % f)
print("%04d-%02d-%02d %02d:%02d <dir> %s" % (tm[0], tm[1], tm[2], tm[3], tm[4], f))
else:
print("% 8d %s" % (st[6], f))
print("%04d-%02d-%02d %02d:%02d %8d %s" % (tm[0], tm[1], tm[2], tm[3], tm[4], st[6], f))

class PWD:

def __repr__(self):
return os.getcwd()
res = os.getcwd()
if res == "": # TLD on esp8266
res = "/"
return res

def __call__(self):
return self.__repr__()

pwd = PWD()
ls = LS()
class CLEAR:

def cd(path):
os.chdir(path)
def __repr__(self):
return "\x1b[2J\x1b[H"

def __call__(self):
return self.__repr__()

class MAN:

def __repr__(self):
return ("""
This is the 'upysh' command list:

cat(file)
clear
cd(new_dir)
ls
ls(object)
head(file [, #_of_lines])
man
mkdir(newdir)
mv(from, to)
newfile(file)
pwd
rm(file)
rmdir(empty_dir)
""")

def __call__(self):
return self.__repr__()


pwd = PWD()
ls = LS()
clear = CLEAR()
man = MAN()
cd = os.chdir
mkdir = os.mkdir
mv = os.rename
rm = os.remove
rmdir = os.remove

def head(f, n=10):
with open(f) as f:
Expand All @@ -55,13 +94,3 @@ def newfile(path):
f.write(l)
f.write("\n")

def help():
print("""
This is 'upysh' help, for builtin Python help run:
import builtins
builtins.help()

upysh commands:
pwd, cd("new_dir"), ls, ls(...), head(...), cat(...)
mkdir(...), newfile(...)
""")