Skip to content

Commit

Permalink
update version v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MayankFawkes committed Apr 29, 2021
1 parent cd1a5d2 commit abe90a3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
12 changes: 8 additions & 4 deletions transfer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests, re
from time import time
from transfer.request import MakeRequest
from transfer.exceptions import FileTooLarge
from transfer.exceptions import FileTooLarge, PrepareError
from random import choices
from string import digits, ascii_uppercase, ascii_lowercase

Expand All @@ -16,15 +16,19 @@ class Upload(MakeRequest):
:param str file: name of the file of full location
:param **kwargs: Optional arguments that :class:`MakeRequest <MakeRequest>` class takes.
'''
def __init__(self, file:str, verbose:bool=False, cli:bool=False,**kwargs):
def __init__(self, file:str, verbose:bool=False, force:bool=False, cli:bool=False,**kwargs):
super().__init__(file=file, **kwargs)

start = time()
self.verbose = verbose
if self.verbose:
print("Preparing upload file...")

self.prepare()
if not force:
try:
self.prepare()
except:
raise PrepareError()

response = self._send(**self.kwargs)

Expand Down Expand Up @@ -60,7 +64,7 @@ def prepare(self):
self._max_file_limit = int(nsize)*size[type]

if self._max_file_limit < self._len:
FileTooLarge(self._max_file_limit)
raise FileTooLarge(self._max_file_limit)

def _gen_hash(self) -> str:
return "".join([
Expand Down
20 changes: 15 additions & 5 deletions transfer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import List
from json import loads, dumps
from tempfile import gettempdir
from transfer.exceptions import FileTooLarge, PrepareError


class ActionCheck(object):
Expand Down Expand Up @@ -103,10 +104,17 @@ def __init__(self):
self._remove(args)

def _upload(self, namespace:argparse.Namespace) -> None:
namespace = vars(namespace)
namespace.__setitem__("file", namespace.pop("type").get("value"))
res = Upload(cli=True,**namespace)
self._add_log(res.data)
try:
namespace = vars(namespace)
namespace.__setitem__("file", namespace.pop("type").get("value"))
res = Upload(cli=True,**namespace)
self._add_log(res.data)
except FileTooLarge as e:
print(f"Error: {e.msg}")

except PrepareError as e:
print(f"Error: {e.msg}")


def _remove(self, namespace:argparse.Namespace):
try:
Expand Down Expand Up @@ -161,7 +169,9 @@ def get_args(self) -> argparse.Namespace:

c2.add_argument("-v", "--verbose", required=False, action="store_true", help="Enable Verbose mode for extra logs.")
c2.add_argument("-np", "--no-process-bar", required=False, action="store_true", help="Disable process bar.")
c2.add_argument("-s", "--url", required=False, help="Third-party transfer.sh servers.")
c2.add_argument("-u", "--url", required=False, help="Third-party transfer.sh servers.")
c2.add_argument("-f", "--force", required=False,action="store_true",
help="Force to skip some verification tests and upload directly.")

c3 = sub_parser.add_parser("list", aliases=["l"], help="List all uploaded files.")
c3.add_argument("-s", "--show", action="store_const", required=True, const=dict(type="list"), dest="type")
Expand Down
13 changes: 12 additions & 1 deletion transfer/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __str__(self):


class FileTooLarge(TransferError):
"""Base video unavailable error."""
def __init__(self, limit: int):
"""
:param int limit:
Expand All @@ -32,3 +31,15 @@ def error_message(self):
@property
def limit(self):
return str(round(self._limit/(1024*1024*1024), 2))+'GB' if len(str(self._limit//(1024*1024))) >= 4 else str(round(self._limit/(1024*1024), 2))+'MB'

class PrepareError(TransferError):
def __init__(self):
"""
:param int limit:
Max uploading size.
"""
super().__init__(self.error_message)

@property
def error_message(self):
return f'Unable to fetch prepare data from site try --force.'
6 changes: 5 additions & 1 deletion transfer/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ def _progress_bar(self,
size=None,
progress=None,
in_second=None,
loading_sign:str="█",
loading_sign:str="█",
width:int=50,
end="\r"
) -> None:
if not size:
size = 1
progress = 1
in_second = 0
percentage = (progress*width) // size
print(f"Upload: |{loading_sign * percentage:{'-'}<{width}}| {percentage*(100//width):>3}%",
f"{str(round(in_second/(1024*1024), 2))+'MB/s' if len(str(in_second//1024)) >= 4 else str(in_second//1024)+'Kb/s':>4}",
Expand Down
4 changes: 2 additions & 2 deletions transfer/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__version__ = "1.1.1"
__version__ = "1.1.2"


if __name__ == '__main__':
print(__version__)
print(__version__)

0 comments on commit abe90a3

Please sign in to comment.