Queer European MD passionate about IT
Procházet zdrojové kódy

Organize as package

Davte před 5 roky
rodič
revize
5f0ed1295f
7 změnil soubory, kde provedl 121 přidání a 6 odebrání
  1. 1 1
      README.md
  2. 18 0
      filebridging/__init__.py
  3. 13 3
      filebridging/client.py
  4. 13 1
      filebridging/server.py
  5. 1 1
      filebridging/utilities.py
  6. 75 0
      setup.py
  7. 0 0
      src/__init__.py

+ 1 - 1
README.md

@@ -1,3 +1,3 @@
 # filebridging
 
-Share files via a bridge server.
+Share files via a bridge server using TCP over SSL and aes-256-cbc encryption.

+ 18 - 0
filebridging/__init__.py

@@ -0,0 +1,18 @@
+"""General information about this package.
+
+Python 3.8+ is needed to use this package.
+```python3.8+
+from filebridging.client import Client
+from filebridging.server import Server
+help(Client)
+help(Server)
+```
+"""
+
+__author__ = "Davide Testa"
+__email__ = "davide@davte.it"
+__credits__ = []
+__license__ = "GNU General Public License v3.0"
+__version__ = "0.0.1"
+__maintainer__ = "Davide Testa"
+__contact__ = "t.me/davte"

+ 13 - 3
src/client.py → filebridging/client.py

@@ -1,3 +1,5 @@
+"""Receiver and sender client class."""
+
 import argparse
 import asyncio
 import collections
@@ -8,7 +10,7 @@ import ssl
 import string
 import sys
 
-import utilities
+from . import utilities
 
 
 class Client:
@@ -313,6 +315,9 @@ def get_action(action):
 
 def get_file_path(path, action='receive'):
     """Check that file `path` is correct and return it."""
+    path = os.path.abspath(
+        os.path.expanduser(path)
+    )
     if (
             isinstance(path, str)
             and action == 'send'
@@ -322,7 +327,7 @@ def get_file_path(path, action='receive'):
     elif (
             isinstance(path, str)
             and action == 'receive'
-            and os.access(os.path.dirname(os.path.abspath(path)), os.W_OK)
+            and os.access(os.path.dirname(path), os.W_OK)
     ):
         return path
     elif path is not None:
@@ -525,7 +530,12 @@ def main():
         _ssl_context.load_verify_locations(certificate)
         client.set_ssl_context(_ssl_context)
     except ImportError:
-        logging.warning("Please consider using SSL.")
+        logging.warning(
+            "Please consider using SSL. To do so, add in `config.py` or "
+            "provide via Command Line Interface the path to a valid SSL "
+            "certificate. Example:\n\n"
+            "certificate = 'path/to/certificate.crt'"
+        )
         # noinspection PyUnusedLocal
         certificate = None
     logging.info("Starting client...")

+ 13 - 1
src/server.py → filebridging/server.py

@@ -1,3 +1,8 @@
+"""Server class.
+
+May be a local server or a publicly reachable server.
+"""
+
 import argparse
 import asyncio
 import collections
@@ -216,6 +221,7 @@ class Server:
             port=self.port,
         )
         async with self.server:
+            logging.info("Running at `{s.host}:{s.port}`".format(s=self))
             await self.server.serve_forever()
 
     @staticmethod
@@ -297,7 +303,13 @@ def main():
         _ssl_context.load_cert_chain(certificate, key)
         server.set_ssl_context(_ssl_context)
     except ImportError:
-        logging.warning("Please consider using SSL.")
+        logging.warning(
+            "Please consider using SSL. To do so, add in `config.py` or "
+            "provide via Command Line Interface the path to a valid SSL "
+            "key and certificate. Example:\n\n"
+            "key = 'path/to/secret.key'\n"
+            "certificate = 'path/to/certificate.crt'"
+        )
     server.run()
 
 

+ 1 - 1
src/utilities.py → filebridging/utilities.py

@@ -1,4 +1,5 @@
 """Useful functions."""
+
 import logging
 import signal
 
@@ -26,4 +27,3 @@ def timed_input(message: str = None,
         logging.info("Timeout!")
     signal.alarm(0)
     return given_input
-

+ 75 - 0
setup.py

@@ -0,0 +1,75 @@
+"""Setup."""
+
+import codecs
+import os
+import re
+import setuptools
+import sys
+
+if sys.version_info < (3, 8):
+    raise RuntimeError("Python3.8+ is needed to use this library")
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+
+def read(*parts):
+    """Read file in `part.part.part.part.ext`.
+
+    Start from `here` and follow the path given by `*parts`
+    """
+    with codecs.open(os.path.join(here, *parts), 'r') as fp:
+        return fp.read()
+
+
+def find_information(info, *file_path_parts):
+    """Read information in file."""
+    version_file = read(*file_path_parts)
+    version_match = re.search(
+        r"^__{info}__ = ['\"]([^'\"]*)['\"]".format(
+            info=info
+        ),
+        version_file,
+        re.M
+    )
+    if version_match:
+        return version_match.group(1)
+    raise RuntimeError("Unable to find version string.")
+
+
+with open("README.md", "r") as readme_file:
+    long_description = readme_file.read()
+
+setuptools.setup(
+    name='filebridging',
+    version=find_information("version", "filebridging", "__init__.py"),
+    author=find_information("author", "filebridging", "__init__.py"),
+    author_email=find_information("email", "filebridging", "__init__.py"),
+    description=(
+        "Share files via a bridge server using TCP over SSL and aes-256-cbc "
+        "encryption."
+    ),
+    license=find_information("license", "filebridging", "__init__.py"),
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="https://gogs.davte.it/davte/filebridging",
+    packages=setuptools.find_packages(),
+    platforms=['any'],
+    install_requires=[],
+    classifiers=[
+        "Development Status :: 5 - Production/Stable",
+        "Environment :: Console",
+        "Framework :: AsyncIO",
+        "Intended Audience :: End Users/Desktop",
+        "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
+        "Natural Language :: English",
+        "Operating System :: OS Independent",
+        "Programming Language :: Python :: 3 :: Only",
+        "Topic :: Communications :: File Sharing",
+    ],
+    keywords=(
+        'file share '
+        'tcp ssl tls end-to-end encryption '
+        'python asyncio async'
+    ),
+    include_package_data=True,
+)

+ 0 - 0
src/__init__.py