5 Incheckningar db11a0be43 ... c934f85217

Upphovsman SHA1 Meddelande Datum
  Kapustlo c934f85217 exit > sys.exit 2 år sedan
  Kapustlo eaef045e93 Fixed socket permissions 2 år sedan
  Kapustlo 276e30f527 Simplified test app 2 år sedan
  Kapustlo 61519059e4 Fixed styling 2 år sedan
  Kapustlo e42ba11773 Updated version 2 år sedan
4 ändrade filer med 24 tillägg och 17 borttagningar
  1. 1 4
      bjcli/__init__.py
  2. 12 6
      bjcli/__main__.py
  3. 11 1
      bjcli/utils.py
  4. 0 6
      tests/test_project/app.py

+ 1 - 4
bjcli/__init__.py

@@ -3,7 +3,7 @@ from argparse import ArgumentParser
 
 __author__: str = 'Kapustlo'
 
-__version__: str = '1.0.1'
+__version__: str = '1.0.3'
 
 environ = os.environ
 
@@ -18,6 +18,3 @@ parser.add_argument("-w", dest='workers', required=False, type=int, default=int(
 parser.add_argument("-p", dest='port', default=environ.get('PORT'), type=int, required=False)
 
 parser.add_argument("-i", dest='host', required=False, default=environ.get('HOST', '127.0.0.1'))
-
-
-

+ 12 - 6
bjcli/__main__.py

@@ -4,7 +4,7 @@ import signal
 import ipaddress
 import importlib
 
-import bjoern # Does not work for Windows
+import bjoern  # Does not work for Windows
 
 from . import parser, utils
 
@@ -15,7 +15,7 @@ def main():
     args = parser.parse_args()
 
     if args.workers < 1:
-        raise AttributeError(f'Workers must not be less than 1')
+        raise AttributeError('Workers must not be less than 1')
 
     sys.path.insert(1, os.getcwd())
 
@@ -24,10 +24,13 @@ def main():
     try:
         module_path, attr = full_module_path.split(':')
     except ValueError:
-        raise AttributeError(f'No module attribute specified in "{full_module_path}"')
+        raise AttributeError(
+            f'No module attribute specified in "{full_module_path}"'
+        )
 
     if not attr:
-        raise AttributeError(f'Module attribute cannot be empty ({full_module_path})')
+        raise AttributeError(
+            f'Module attribute cannot be empty ({full_module_path})')
 
     module = importlib.import_module(module_path)
 
@@ -53,6 +56,9 @@ def main():
 
     print('Bjoern server has started')
 
+    if not port:
+        utils.set_socket_permissions(host)
+
     pids = utils.create_workers(workers)
 
     if not pids:
@@ -63,7 +69,7 @@ def main():
         except KeyboardInterrupt:
             pass
 
-        exit()
+        sys.exit()
 
     try:
         # Wait for the first worker to exit. They should never exit!
@@ -77,7 +83,7 @@ def main():
         for pid in pids:
             os.kill(pid, signal.SIGINT)
 
-            exit(1)
+            sys.exit(1)
 
 
 if __name__ == '__main__':

+ 11 - 1
bjcli/utils.py

@@ -1,4 +1,5 @@
 import os
+from pathlib import Path
 from typing import Union
 
 
@@ -20,5 +21,14 @@ def create_workers(workers: int) -> Union[set[int], None]:
             #  In worker
 
             return None
-    
+
     return pids
+
+
+def set_socket_permissions(path: str) -> None:
+    if path.startswith('unix:'):
+        path = path[5:]
+
+    spath = Path(path)
+
+    spath.chmod(0o777)

+ 0 - 6
tests/test_project/app.py

@@ -2,13 +2,7 @@ from flask import Flask
 
 app = Flask(__name__)
 
-from flask import Flask
-
-app = Flask(__name__)
 
 @app.route("/")
 def hello_world():
     return "<p>Hello, World!</p>"
-
-def get_wsgi_application():
-    return app