Autoformat

This commit is contained in:
hhh
2024-05-27 17:12:21 +03:00
parent 0afca0dd67
commit 918d5af851
25 changed files with 358 additions and 378 deletions

View File

@@ -1,6 +1,3 @@
from .common import cli
__all__ = [
'cli'
]
__all__ = ["cli"]

View File

@@ -2,34 +2,34 @@ import os
import click
from dragonion_server.utils.config import db
from dragonion_server.common import console
from dragonion_server.utils.config import db
class ServiceRemoveCommand(click.Command):
def __init__(self):
super().__init__(
name='remove',
name="remove",
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
("--name", "-n"),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
help="Name of service to write to",
)
]
],
)
@staticmethod
def callback(name: str):
try:
del db.services[name]
if os.path.isfile(f'{name}.auth'):
os.remove(f'{name}.auth')
print(f'Removed service {name}')
if os.path.isfile(f"{name}.auth"):
os.remove(f"{name}.auth")
print(f"Removed service {name}")
except KeyError:
print(f'Service "{name}" does not exist in this storage')
except Exception as e:

View File

@@ -1,60 +1,63 @@
import sys
import click
from dragonion_server.modules.server import run, run_without_onion, integrate_onion
from dragonion_server.common import console
from dragonion_server.modules.server import integrate_onion, run, run_without_onion
class ServiceRunCommand(click.Command):
def __init__(self):
super().__init__(
name='run',
name="run",
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
("--name", "-n"),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
help="Name of service to write to",
),
click.Option(
('--port', '-p'),
("--port", "-p"),
required=False,
prompt=True,
prompt_required=False,
type=int,
help='Port to start service on'
help="Port to start service on",
),
click.Option(
('--without-tor', '-wt'),
("--without-tor", "-wt"),
is_flag=True,
help='Run service without tor'
help="Run service without tor",
),
click.Option(
('--only-tor', '-ot'),
("--only-tor", "-ot"),
is_flag=True,
help='Run only tor proxy to service'
)
]
help="Run only tor proxy to service",
),
],
)
@staticmethod
def callback(name: str, port: int | None, without_tor: bool, only_tor: bool):
try:
if without_tor and only_tor:
print('Cannot run only tor without tor, exiting')
print("Cannot run only tor without tor, exiting")
sys.exit(1)
elif without_tor:
run_without_onion(name, port)
elif only_tor:
if port is None:
print('For this mode, you need to specify port, '
'to which requests will be redirected. Cannot start '
'tor service, exiting')
print(
"For this mode, you need to specify port, "
"to which requests will be redirected. Cannot start "
"tor service, exiting"
)
sys.exit(1)
onion = integrate_onion(port, name)
input('Press Enter to stop onion and service...')
input("Press Enter to stop onion and service...")
onion.cleanup()
else:
run(name, port)

View File

@@ -1,14 +1,13 @@
from ...utils import ModuleGroup
from .write import ServiceWriteCommand
from .run import ServiceRunCommand
from .remove import ServiceRemoveCommand
from .run import ServiceRunCommand
from .write import ServiceWriteCommand
service_group = ModuleGroup(
name='service',
name="service",
commands={
'write': ServiceWriteCommand(),
'run': ServiceRunCommand(),
'remove': ServiceRemoveCommand()
}
"write": ServiceWriteCommand(),
"run": ServiceRunCommand(),
"remove": ServiceRemoveCommand(),
},
)

View File

@@ -1,30 +1,30 @@
import click
from dragonion_server.utils.onion import Onion
from dragonion_server.common import console
from dragonion_server.utils.onion import Onion
class ServiceWriteCommand(click.Command):
def __init__(self):
super().__init__(
name='write',
name="write",
callback=self.callback,
params=[
click.Option(
('--name', '-n'),
("--name", "-n"),
required=True,
prompt=True,
type=str,
help='Name of service to write to'
help="Name of service to write to",
),
click.Option(
('--port', '-p'),
("--port", "-p"),
required=True,
prompt=True,
type=int,
help='Port to start service on'
)
]
help="Port to start service on",
),
],
)
@staticmethod

View File

@@ -1,10 +1,5 @@
import click
from .cmd.service.service import service_group
cli = click.CommandCollection(
name='dragonion-server',
sources=[
service_group()
]
)
cli = click.CommandCollection(name="dragonion-server", sources=[service_group()])

View File

@@ -1,6 +1,3 @@
from .groups import ModuleGroup
__all__ = [
'ModuleGroup'
]
__all__ = ["ModuleGroup"]

View File

@@ -1,6 +1,7 @@
import click
import typing as t
import click
class ModuleGroup(click.Group):
def __init__(
@@ -13,6 +14,6 @@ class ModuleGroup(click.Group):
) -> None:
new_commands = dict()
for command_key in commands.keys():
new_commands[f'{name}-{command_key}'] = commands[command_key]
new_commands[f"{name}-{command_key}"] = commands[command_key]
super().__init__(name, new_commands, **attrs)