Compare commits
	
		
			No commits in common. "472296621a0ea3f12b60456e1c1e070b99a9aeb1" and "60d9636896d6983b120728a3aa1c05c3d9cd817f" have entirely different histories.
		
	
	
		
			472296621a
			...
			60d9636896
		
	
		
					 3 changed files with 8 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -3,10 +3,9 @@
 | 
			
		|||
from setuptools import setup
 | 
			
		||||
 | 
			
		||||
setup(name='transbeam-cli',
 | 
			
		||||
      version='0.2',
 | 
			
		||||
      version='0.1',
 | 
			
		||||
      scripts=['transbeam-cli'],
 | 
			
		||||
      install_requires=[
 | 
			
		||||
          'aiofiles',
 | 
			
		||||
          'tqdm',
 | 
			
		||||
          'websockets',
 | 
			
		||||
      ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,24 +7,17 @@ import json
 | 
			
		|||
import math
 | 
			
		||||
import pathlib
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
import aiofiles
 | 
			
		||||
from tqdm import tqdm
 | 
			
		||||
from websockets import connect
 | 
			
		||||
 | 
			
		||||
FILE_CHUNK_SIZE = 16384
 | 
			
		||||
 | 
			
		||||
async def file_loader(files):
 | 
			
		||||
def file_loader(files):
 | 
			
		||||
    with tqdm(desc="Total", total=sum(size for (path, size) in files), unit='B', unit_scale=True, leave=True, position=1) as total_progress:
 | 
			
		||||
        for (path, size) in files:
 | 
			
		||||
            with tqdm(desc=path.name, total=size, unit='B', unit_scale=True, leave=True, position=0) as file_progress:
 | 
			
		||||
                async with aiofiles.open(path, mode='rb') as f:
 | 
			
		||||
                    while True:
 | 
			
		||||
                        pos = await f.tell()
 | 
			
		||||
                        if pos >= size:
 | 
			
		||||
                            break
 | 
			
		||||
                        data = await f.read(min(FILE_CHUNK_SIZE, size - pos))
 | 
			
		||||
                        if data == b'':
 | 
			
		||||
                with path.open("rb") as f:
 | 
			
		||||
                    while f.tell() < size:
 | 
			
		||||
                        data = f.read(min(16384, size - f.tell()))
 | 
			
		||||
                        if data == "":
 | 
			
		||||
                            tqdm.write("file ended early!")
 | 
			
		||||
                            exit(1)
 | 
			
		||||
                        total_progress.update(len(data))
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +49,7 @@ async def send(paths, host, password, lifetime, collection_name=None):
 | 
			
		|||
            exit(1)
 | 
			
		||||
        print("Download: https://{}/download?code={}".format(host, resp["code"]))
 | 
			
		||||
        loader = file_loader([(paths[i], fileMetadata[i]["size"]) for i in range(len(paths))])
 | 
			
		||||
        async for data in loader:
 | 
			
		||||
        for data in loader:
 | 
			
		||||
            await ws.send(data)
 | 
			
		||||
 | 
			
		||||
parser = argparse.ArgumentParser(description="Upload files to transbeam")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,9 +47,8 @@
 | 
			
		|||
 | 
			
		||||
          packages."${name}-cli" = with pkgs.python3Packages; buildPythonApplication {
 | 
			
		||||
            pname = "${name}-cli";
 | 
			
		||||
            version = "0.2";
 | 
			
		||||
            version = "0.1";
 | 
			
		||||
            propagatedBuildInputs = [
 | 
			
		||||
              aiofiles
 | 
			
		||||
              tqdm
 | 
			
		||||
              websockets
 | 
			
		||||
            ];
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +70,6 @@
 | 
			
		|||
              cargo-audit
 | 
			
		||||
              cargo-flamegraph
 | 
			
		||||
              (python3.withPackages (p: with p; [
 | 
			
		||||
                aiofiles
 | 
			
		||||
                tqdm
 | 
			
		||||
                websockets
 | 
			
		||||
              ]))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue