From 6c257fda70dab24d378ba9b6d61327ac481bd7de Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Fri, 1 May 2020 12:10:14 +0530 Subject: [PATCH] Bumped Airshare to version 0.1.1 * Removed python-magic dependency * Added print to indicate clipboard copy for `-cr` * Improved static files download.html and text.html * Added text copy button for text.html --- airshare/cli.py | 1 + airshare/sender.py | 8 +++----- airshare/static/download.html | 3 ++- airshare/static/text.html | 23 ++++++++++++++++++++--- airshare/utils.py | 14 ++++++++------ docs/requirements.txt | 2 -- docs/source/conf.py | 2 +- setup.py | 5 ++--- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/airshare/cli.py b/airshare/cli.py index 1002199..809d35b 100644 --- a/airshare/cli.py +++ b/airshare/cli.py @@ -58,6 +58,7 @@ def main(code, port, text, upload, clip_send, clip_receive, file_path, files): if is_file_copyable(content): with open(content, "r") as f: pyperclip.copy(f.read()) + print("File copied to clipboard!") else: print("This file cannot be copied to the clipboard!") else: diff --git a/airshare/sender.py b/airshare/sender.py index b179c11..42c1d21 100644 --- a/airshare/sender.py +++ b/airshare/sender.py @@ -4,7 +4,6 @@ from aiohttp import web import asyncio import humanize -import magic from multiprocessing import Process import os import pkgutil @@ -68,8 +67,7 @@ async def _file_stream_sender(request): file_name = request.app["file_name"] file_size = str(request.app["file_size"]) header = "attachment; filename={}; size={}".format(file_name, file_size) - response.headers["content-type"] = magic.Magic(mime=True) \ - .from_file(file_path) + response.headers["content-type"] = "application/octet-stream" response.headers["content-length"] = str(request.app["file_size"]) response.headers["content-disposition"] = header await response.prepare(request) @@ -203,7 +201,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80): app["file_path"] = os.path.realpath(content) app["file_name"] = name or app["file_path"].split(os.path.sep)[-1] app["file_size"] = os.stat(app["file_path"]).st_size - file_size = " (" + humanize.naturalsize(app["file_size"]) + ") " + file_size = " (" + humanize.naturalsize(app["file_size"]) + ")" content = app["file_name"] app.router.add_get(path="/", handler=_download_page) app.router.add_get(path="/airshare", handler=_is_airshare_file_sender) @@ -216,7 +214,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80): if port != 80: url_port = ":" + str(port) ip = socket.inet_ntoa(addresses[0]) + url_port - print("`" + content + "`" + file_size + "available at " + ip + print("`" + content + "`" + file_size + " available at " + ip + " and `http://" + code + ".local" + url_port + "`, press CtrlC" + " to stop sharing...") if platform.system() != "Windows": diff --git a/airshare/static/download.html b/airshare/static/download.html index bfaf9a2..6546c9c 100644 --- a/airshare/static/download.html +++ b/airshare/static/download.html @@ -32,6 +32,7 @@ backface-visibility: hidden; text-decoration: none; color: var(--text); + cursor: pointer; } .rocket-button:before { content: ''; @@ -463,7 +464,7 @@

Airshare

- + diff --git a/airshare/static/text.html b/airshare/static/text.html index 68193bb..e79d31a 100644 --- a/airshare/static/text.html +++ b/airshare/static/text.html @@ -56,14 +56,20 @@

Airshare

- +
-
- diff --git a/airshare/utils.py b/airshare/utils.py index 3421d17..6962f62 100644 --- a/airshare/utils.py +++ b/airshare/utils.py @@ -1,7 +1,7 @@ """Utility functions for Airshare.""" -import magic +import mimetypes import os import pyperclip import re @@ -191,9 +191,11 @@ def is_file_copyable(file_path): copyable : boolean True if the file can be copied to the clipboard, False otherwise. """ - file_type = magic.Magic(mime=True).from_file(file_path) - if (re.findall("text|json", file_type, re.IGNORECASE)): - copyable = True - else: - copyable = False + file_type = mimetypes.guess_type(file_path)[0] + copyable = False + if file_type is not None: + if (re.findall("text|json", file_type, re.IGNORECASE)): + copyable = True + else: + copyable = False return copyable diff --git a/docs/requirements.txt b/docs/requirements.txt index b14ed1b..e1e2ed6 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,11 +4,9 @@ click==7.0 humanize==0.5.1 pyperclip==1.8.0 pyqrcode==1.2.1 -python-magic==0.4.15 requests==2.20.0 requests-toolbelt==0.9.1 tqdm==4.36.1 zeroconf==0.25.0 -python-magic-bin==0.4.14 ; sys_platform=='win32' or sys_platform=='darwin' sphinxcontrib-fulltoc==1.2.0 python-docs-theme==2020.1 diff --git a/docs/source/conf.py b/docs/source/conf.py index d0a9b82..718dbc0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -23,7 +23,7 @@ author = 'Kandavel A, Mohanasundar M, Nanda H Krishna' # The full version, including alpha/beta/rc tags -release = '0.1.0' +release = '0.1.1' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 6f55153..ef715e0 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="Airshare", - version="0.1.0", + version="0.1.1", author="Kandavel A, Mohanasundar M, Nanda H Krishna", author_email="kurolabs.org+airshare@gmail.com", description="An easy way to share content in a local network.", @@ -37,11 +37,10 @@ "humanize >= 0.5.1", "pyperclip >= 1.8.0", "pyqrcode >= 1.2.1", - "python-magic == 0.4.15", "requests >= 2.20.0", "requests-toolbelt >= 0.9.1", "tqdm >= 4.36.1", "zeroconf >= 0.25.0", - ] + ["python-magic-bin == 0.4.14"] if "win" in sys.platform else [], + ], python_requires=">=3.6", )