summaryrefslogtreecommitdiff
path: root/wasp/shell.py
blob: ace9513d449427260b4dcfa46642ba1300da066b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson

# SPDX-License-Identifier: MIT
# Copyright (c) 2020 Daniel Thompson
# Copyright (c) 2016 Paul Sokolovsky

import sys
import os

class LS:
    def __repr__(self):
        self.__call__()
        return ""

    def __call__(self, path="."):
        l = os.listdir(path)
        l.sort()
        for f in l:
            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))

class PWD:
    def __repr__(self):
        return os.getcwd()

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

class CLEAR:
    def __repr__(self):
        return "\x1b[2J\x1b[H"

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


pwd = PWD()
ls = LS()
clear = CLEAR()

cd = os.chdir
mkdir = os.mkdir
mv = os.rename
rm = os.remove
rmdir = os.rmdir

def head(f, n=10):
    with open(f) as f:
        for i in range(n):
            l = f.readline()
            if not l: break
            print(l, end='')

def cat(f):
    head(f, 1 << 30)

def download(path):
    head(f, 1 << 30)

def upload(path):
    print("upload mode; Ctrl-C to cancel, Ctrl-D to finish")
    with open(path, "w") as f:
        while 1:
            print('=== ', end='')
            try:
                l = input()
            except EOFError:
                break
            f.write(l)
            f.write("\n")