Sbeam working
This commit is contained in:
parent
3dc8ec72f0
commit
4ef0cdede9
|
@ -16,10 +16,6 @@ from SuperBeam.RequestHandlers import (
|
|||
)
|
||||
|
||||
|
||||
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||
pass
|
||||
|
||||
|
||||
class SuperBeamServer(BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
|
@ -70,24 +66,19 @@ def get_primary_ip():
|
|||
return IP
|
||||
|
||||
|
||||
def show_qrcode():
|
||||
def get_qrcode():
|
||||
primary_ip = get_primary_ip()
|
||||
octets = [1]
|
||||
octets.extend([int(_) for _ in primary_ip.split('.')[::-1]])
|
||||
url = 'http://superbe.am/q?' + base64.b64encode(
|
||||
struct.pack('BBBBB', *octets)
|
||||
).decode('utf-8')
|
||||
qrcode = pyqrcode.create(url)
|
||||
print('\033[1;37;37m████████' + '██'*(len(qrcode.code[0])))
|
||||
for row in qrcode.code:
|
||||
print('\033[1;37;37m████', end='')
|
||||
for block in row:
|
||||
if block == 1:
|
||||
print('\033[1;30;30m ', end='')
|
||||
else:
|
||||
print('\033[1;37;37m██', end='')
|
||||
print('\033[1;37;37m████')
|
||||
print('\033[1;37;37m████████' + '██'*(len(qrcode.code[0])))
|
||||
return pyqrcode.create(url)
|
||||
|
||||
|
||||
def show_qrcode():
|
||||
qrcode = get_qrcode()
|
||||
print(qrcode.terminal())
|
||||
|
||||
|
||||
def build_filelist(paths, recursive=True):
|
||||
|
|
31
sbeam.py
31
sbeam.py
|
@ -41,6 +41,10 @@ def cli():
|
|||
help='Recurse into sub directories')
|
||||
@click.argument('filename', nargs=-1, type=click.Path(exists=True))
|
||||
def serve(recursive, filename):
|
||||
"""Start a SuperBeam serve to serve FILENAME [FILENAME ...].
|
||||
|
||||
FILENAME can be one or more files or directories.
|
||||
"""
|
||||
filelist = SuperBeam.build_filelist(filename, recursive)
|
||||
SuperBeam.serve_forever(filelist)
|
||||
|
||||
|
@ -48,6 +52,10 @@ def serve(recursive, filename):
|
|||
@cli.command()
|
||||
@click.argument('host', default='127.0.0.1')
|
||||
def superlist(host):
|
||||
"""Fetch superlist from HOST running SupberBeam.
|
||||
|
||||
HOST is the IP of the SuperBeam server.
|
||||
"""
|
||||
with requests.get(f'http://{host}:8080/superlist',
|
||||
headers={'User-Agent': 'sbeam'}) as response:
|
||||
assert response.status_code == 200
|
||||
|
@ -56,8 +64,14 @@ def superlist(host):
|
|||
|
||||
@cli.command()
|
||||
@click.argument('host', default='127.0.0.1')
|
||||
@click.argument('filename', default='received.bin', type=click.File('w'))
|
||||
@click.argument('filename', default='received.bin')
|
||||
def receive(host, filename):
|
||||
"""Download a SuperBeam stream from HOST and save as FILENAME.
|
||||
|
||||
HOST is the IP of the SuperBeam server. The SuperBeam stream will be saved
|
||||
as FILENAME. To split the files into individual files, the `split-stream`
|
||||
command with the Superlist from the `superlist` command has to be used.
|
||||
"""
|
||||
with requests.get(f'http://{host}:8080/getstream', stream=True,
|
||||
headers={'User-Agent': 'sbeam'}) as response:
|
||||
assert response.status_code == 200
|
||||
|
@ -70,8 +84,14 @@ def receive(host, filename):
|
|||
@click.argument('filename', default='received.bin', type=click.File('r'))
|
||||
@click.argument('superlist', default='superlist', type=click.File('r'))
|
||||
@click.argument('directory', default='received', type=click.File('w'))
|
||||
def split_stream(data, superlist, directory):
|
||||
with open(data, 'rb') as blob:
|
||||
def split_stream(filename, superlist, directory):
|
||||
"""Split FILENAME with SUPERLIST into single files.
|
||||
|
||||
The SuperBeam stream FILENAME from the `receive` command is split into
|
||||
individual files as described by SUPERLIST. The SUPERLIST can be downloaded
|
||||
with the `superlist` command. The individual files are stored in DIRECTORY.
|
||||
"""
|
||||
with open(filename, 'rb') as blob:
|
||||
for item in superlist:
|
||||
if not item:
|
||||
break
|
||||
|
@ -83,6 +103,11 @@ def split_stream(data, superlist, directory):
|
|||
handle.write(blob.read(int(filesize)))
|
||||
|
||||
|
||||
@cli.command()
|
||||
def tui():
|
||||
SuperBeam.tui.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
||||
# to_download = 0
|
||||
|
|
Loading…
Reference in New Issue