2016-05-28 22:06:29 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
class LS:
|
|
|
|
|
|
|
|
def __repr__(self):
|
2016-05-31 21:10:12 +00:00
|
|
|
self.__call__()
|
|
|
|
return ""
|
2016-05-28 22:06:29 +00:00
|
|
|
|
|
|
|
def __call__(self, path="."):
|
|
|
|
l = os.listdir(path)
|
|
|
|
l.sort()
|
|
|
|
for f in l:
|
2016-05-31 21:10:12 +00:00
|
|
|
st = os.stat("%s/%s" % (path, f))
|
|
|
|
if st[0] & 0x4000: # stat.S_IFDIR
|
|
|
|
print(" <dir> %s" % f)
|
|
|
|
else:
|
|
|
|
print("% 8d %s" % (st[6], f))
|
2016-05-28 22:06:29 +00:00
|
|
|
|
|
|
|
class PWD:
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return os.getcwd()
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
return self.__repr__()
|
|
|
|
|
2016-07-16 21:42:30 +00:00
|
|
|
class CLEAR:
|
|
|
|
def __repr__(self):
|
|
|
|
return "\x1b[2J\x1b[H"
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
return self.__repr__()
|
|
|
|
|
|
|
|
|
2016-05-28 22:06:29 +00:00
|
|
|
pwd = PWD()
|
|
|
|
ls = LS()
|
2016-07-16 21:42:30 +00:00
|
|
|
clear = CLEAR()
|
2016-05-28 22:06:29 +00:00
|
|
|
|
2016-06-12 15:57:14 +00:00
|
|
|
cd = os.chdir
|
2016-05-30 18:07:49 +00:00
|
|
|
mkdir = os.mkdir
|
2016-05-31 21:02:31 +00:00
|
|
|
mv = os.rename
|
2016-06-12 15:57:14 +00:00
|
|
|
rm = os.remove
|
|
|
|
rmdir = os.rmdir
|
2016-05-30 18:07:49 +00:00
|
|
|
|
2016-05-28 22:06:29 +00:00
|
|
|
def head(f, n=10):
|
|
|
|
with open(f) as f:
|
|
|
|
for i in range(n):
|
|
|
|
l = f.readline()
|
|
|
|
if not l: break
|
|
|
|
sys.stdout.write(l)
|
|
|
|
|
|
|
|
def cat(f):
|
|
|
|
head(f, 1 << 30)
|
|
|
|
|
2016-05-30 18:07:49 +00:00
|
|
|
def newfile(path):
|
|
|
|
print("Type file contents line by line, finish with EOF (Ctrl+D).")
|
|
|
|
with open(path, "w") as f:
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
l = input()
|
|
|
|
except EOFError:
|
|
|
|
break
|
|
|
|
f.write(l)
|
|
|
|
f.write("\n")
|
|
|
|
|
2016-07-03 12:50:46 +00:00
|
|
|
class Man():
|
2016-05-28 22:06:29 +00:00
|
|
|
|
2016-07-03 12:50:46 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return("""
|
2016-06-12 16:02:03 +00:00
|
|
|
upysh is intended to be imported using:
|
|
|
|
from upysh import *
|
|
|
|
|
2016-07-03 12:50:46 +00:00
|
|
|
To see this help text again, type "man".
|
|
|
|
|
2016-05-28 22:06:29 +00:00
|
|
|
upysh commands:
|
|
|
|
pwd, cd("new_dir"), ls, ls(...), head(...), cat(...)
|
2016-07-16 21:42:30 +00:00
|
|
|
newfile(...), rm(...), mkdir(...), rmdir(...),
|
|
|
|
clear
|
2016-05-28 22:06:29 +00:00
|
|
|
""")
|
2016-06-12 16:00:37 +00:00
|
|
|
|
2016-07-03 12:50:46 +00:00
|
|
|
man = Man()
|
|
|
|
|
|
|
|
print(man)
|