update readme and cli help
This commit is contained in:
parent
910a44ea1f
commit
cc038e9887
2 changed files with 47 additions and 22 deletions
33
README.md
33
README.md
|
@ -4,20 +4,39 @@
|
||||||
|
|
||||||
`aioupnp` is a python 3 library and command line tool to interact with UPnP gateways using asyncio. `aioupnp` requires the `netifaces` module.
|
`aioupnp` is a python 3 library and command line tool to interact with UPnP gateways using asyncio. `aioupnp` requires the `netifaces` module.
|
||||||
|
|
||||||
|
## Supported devices
|
||||||
|
DD-WRT
|
||||||
|
miniupnpd
|
||||||
|
Actiontec GT784WN
|
||||||
|
D-Link DIR-890L
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
For normal usage
|
||||||
```
|
```
|
||||||
pip install --upgrade aioupnp
|
pip install aioupnp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For development
|
||||||
|
```
|
||||||
|
git clone https://github.com/lbryio/aioupnp.git
|
||||||
|
cd aioupnp
|
||||||
|
pip install -e .
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
aioupnp [-h] [--debug_logging=<debug_logging>] [--interface=<interface>]
|
aioupnp [-h] [--debug_logging] [--interface=<interface>] [--gateway_address=<gateway_address>]
|
||||||
[--gateway_address=<gateway_address>]
|
|
||||||
[--lan_address=<lan_address>] [--timeout=<timeout>]
|
[--lan_address=<lan_address>] [--timeout=<timeout>]
|
||||||
[--service=<service>]
|
[(--<case sensitive m-search header>=<value>)...]
|
||||||
command [--<arg name>=<arg>]...
|
command [--<arg name>=<arg>]...
|
||||||
|
|
||||||
|
If m-search headers are provided as keyword arguments all of the headers to be used must be provided,
|
||||||
|
in the order they are to be used. For example:
|
||||||
|
|
||||||
|
aioupnp --HOST=239.255.255.250:1900 --MAN=\"ssdp:discover\" --MX=1 --ST=upnp:rootdevice m_search
|
||||||
```
|
```
|
||||||
|
|
||||||
### Commands
|
### Commands
|
||||||
|
@ -36,15 +55,15 @@ To list the active port mappings on the gateway
|
||||||
|
|
||||||
To debug the default gateway
|
To debug the default gateway
|
||||||
|
|
||||||
aioupnp --debug_logging=1 m_search
|
aioupnp --debug_logging m_search
|
||||||
|
|
||||||
To debug a gateway on a non default network interface
|
To debug a gateway on a non default network interface
|
||||||
|
|
||||||
aioupnp --interface=vmnet1 --debug_logging=1 m_search
|
aioupnp --interface=vmnet1 --debug_logging m_search
|
||||||
|
|
||||||
To debug a gateway on a non default network interface that isn't the router
|
To debug a gateway on a non default network interface that isn't the router
|
||||||
|
|
||||||
aioupnp --interface=vmnet1 --gateway_address=192.168.1.106 --debug_logging=1 m_search
|
aioupnp --interface=vmnet1 --gateway_address=192.168.1.106 --debug_logging m_search
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import textwrap
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from aioupnp.upnp import UPnP
|
from aioupnp.upnp import UPnP
|
||||||
from aioupnp.constants import UPNP_ORG_IGD, SSDP_DISCOVER, SSDP_HOST
|
|
||||||
|
|
||||||
log = logging.getLogger("aioupnp")
|
log = logging.getLogger("aioupnp")
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
|
@ -10,29 +10,35 @@ handler.setFormatter(logging.Formatter('%(asctime)-15s-%(filename)s:%(lineno)s->
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
log.setLevel(logging.WARNING)
|
log.setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
base_usage = "\n".join(textwrap.wrap(
|
||||||
|
"aioupnp [-h] [--debug_logging] [--interface=<interface>] [--gateway_address=<gateway_address>]"
|
||||||
|
" [--lan_address=<lan_address>] [--timeout=<timeout>] [(--<header_key>=<value>)...]",
|
||||||
|
100, subsequent_indent=' ', break_long_words=False)) + "\n"
|
||||||
|
|
||||||
|
|
||||||
def get_help(command):
|
def get_help(command):
|
||||||
fn = getattr(UPnP, command)
|
fn = getattr(UPnP, command)
|
||||||
params = command + " " + " ".join(["[--%s=<%s>]" % (k, k) for k in fn.__annotations__ if k != 'return'])
|
params = command + " " + " ".join(["[--%s=<%s>]" % (k, k) for k in fn.__annotations__ if k != 'return'])
|
||||||
return \
|
return base_usage + "\n".join(
|
||||||
"usage: aioupnp [--debug_logging=<debug_logging>] [--interface=<interface>]\n" \
|
textwrap.wrap(params, 100, initial_indent=' ', subsequent_indent=' ', break_long_words=False)
|
||||||
" [--gateway_address=<gateway_address>]\n" \
|
)
|
||||||
" [--lan_address=<lan_address>] [--timeout=<timeout>]\n" \
|
|
||||||
" [--service=<service>]\n" \
|
|
||||||
" %s\n" % params
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
commands = [n for n in dir(UPnP) if hasattr(getattr(UPnP, n, None), "_cli")]
|
commands = [n for n in dir(UPnP) if hasattr(getattr(UPnP, n, None), "_cli")]
|
||||||
help_str = " | ".join(commands)
|
help_str = "\n".join(textwrap.wrap(
|
||||||
|
" | ".join(commands), 100, initial_indent=' ', subsequent_indent=' ', break_long_words=False
|
||||||
|
))
|
||||||
|
|
||||||
usage = \
|
usage = \
|
||||||
"usage: aioupnp [-h] [--debug_logging=<debug_logging>] [--interface=<interface>]\n" \
|
"\n%s\n" \
|
||||||
" [--gateway_address=<gateway_address>]\n" \
|
"If m-search headers are provided as keyword arguments all of the headers to be used must be provided,\n" \
|
||||||
" [--lan_address=<lan_address>] [--timeout=<timeout>]\n" \
|
"in the order they are to be used. For example:\n" \
|
||||||
" [--service=<service>]\n" \
|
" aioupnp --HOST=239.255.255.250:1900 --MAN=\"ssdp:discover\" --MX=1 --ST=upnp:rootdevice m_search\n\n" \
|
||||||
" command [--<arg name>=<arg>]...\n" \
|
"Commands:\n" \
|
||||||
"\n" \
|
"%s\n\n" \
|
||||||
"commands: %s\n\nfor help with a specific command: aioupnp help <command>" % help_str
|
"For help with a specific command:" \
|
||||||
|
" aioupnp help <command>\n" % (base_usage, help_str)
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if args[0] in ['help', '-h', '--help']:
|
if args[0] in ['help', '-h', '--help']:
|
||||||
|
|
Loading…
Reference in a new issue