Skip to content

Commit 40ebf9a

Browse files
committed
Version 0.4.0 release
2 parents be9e3d4 + a9011ea commit 40ebf9a

File tree

15 files changed

+247
-82
lines changed

15 files changed

+247
-82
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
This project uses [semantic versioning](https://semver.org/). Note that semver principles for this tool are only reflected on public part of it - `cli`. Code of this project may be changed in any **not backwards compatible** way without `MAJOR` version incrementation.
33

44

5+
## 0.4.0 : 2022.05.26
6+
### Added
7+
- Inbox SMS messages handling with new commands:
8+
- `list`
9+
- `view`
10+
- `count`
11+
- "Did you mean..." prompt on cli command misspelling
12+
13+
### Changed
14+
- Enhanced `auth login` visualization
15+
16+
517
## 0.3.1 : 2022.05.09
618
### Fixed
719
- Stated new features from `0.3.0` release in project `README`

README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,10 @@ $ hurocon --help
6666
Each command and subcommand in this tool has a special `--help` flag to display detailed information about it
6767

6868
### Authentication
69-
Foremost, you need to specify the authentication details so that this tool can access the device in the future. You do it in two ways.
70-
71-
- In interactive mode:
72-
``` bash
73-
$ hurocon auth login
74-
```
75-
76-
- Manually, by running:
77-
```bash
78-
# Initialize local configuration file
79-
$ hurocon config init
80-
81-
# Show path to local configuration file
82-
$ hurocon config path
83-
```
84-
85-
And then manually editing the `json` file with any text editor. It has a human-readable structure, so every part of it is exactly what you think it is.
69+
Foremost, you need to specify the authentication details so that this tool can access the device.
70+
``` bash
71+
$ hurocon auth login
72+
```
8673

8774
### Testing Connection
8875
After auth details successfully specified you can test your connection with router by running

hurocon/cli/auth.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from getpass import getpass
22

33
import click
4+
from click_didyoumean import DYMGroup
45
from huawei_lte_api.Client import Client
56

6-
from .. import core
77
from .root import cli
8+
from ..core.local_cfg import AuthConfig
9+
from ..core.connection import HRC_Connection
10+
from ..core.const import LOCAL_CONFIG_DEFAULT
811

912

10-
@cli.group()
13+
@cli.group(cls=DYMGroup)
1114
def auth():
1215
""" Router authentication """
1316
pass
@@ -18,18 +21,18 @@ def auth_login():
1821
""" Safely configure all authentication related details for further interactions """
1922
print('Authentication Configurator\n')
2023
con_ip = input(
21-
'(leave empty to use "{}")\n'
22-
'Full address to router: '
23-
.format(core.LOCAL_CONFIG_DEFAULT['connection_address'])
24+
' (leave empty to use "{}")\n'
25+
'Full address to router: '
26+
.format(LOCAL_CONFIG_DEFAULT['connection_address'])
2427
)
25-
uname = input('Username: ')
26-
passwd = getpass('Password: ')
28+
uname = input('Username: ')
29+
passwd = getpass('Password: ')
2730

28-
auth_cfg = core.AuthConfig()
31+
auth_cfg = AuthConfig()
2932
auth_cfg.username = uname
3033
auth_cfg.password = passwd
3134
auth_cfg.connection_address = con_ip if len(con_ip) > 0 else \
32-
core.LOCAL_CONFIG_DEFAULT['connection_address']
35+
LOCAL_CONFIG_DEFAULT['connection_address']
3336

3437
auth_cfg.commit()
3538

@@ -39,16 +42,16 @@ def auth_login():
3942
@auth.command('logout')
4043
def auth_logout():
4144
""" Remove all authentication details """
42-
core.AuthConfig().reset()
43-
core.AuthConfig().commit()
45+
AuthConfig().reset()
46+
AuthConfig().commit()
4447
print("All authentication details removed")
4548

4649

4750
@auth.command('test')
4851
def auth_test_connection():
4952
""" Test connection to router with current auth details """
5053
try:
51-
with core.HRC_Connection() as router_con:
54+
with HRC_Connection() as router_con:
5255
Client(router_con)
5356
except Exception as e:
5457
msg = 'Auth failed, reason: "{}"'.format(e)

hurocon/cli/config.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import click
2+
from click_didyoumean import DYMGroup
23

3-
from .. import core
4+
from ..core.local_cfg import LocalConfig
5+
from ..core.const import LOCAL_CONFIG_PATH
46
from .root import cli
57

68

7-
@cli.group()
9+
@cli.group(cls=DYMGroup)
810
def config():
911
""" CLI configuration """
1012

@@ -17,28 +19,28 @@ def config_init():
1719
File will only be generated if no configuration file already exists
1820
on default path.
1921
"""
20-
cfg = core.LocalConfig(auto_file_creation=False)
22+
cfg = LocalConfig(auto_file_creation=False)
2123

2224
if not cfg.file_exists():
2325
if cfg.create_file():
2426
click.echo('Configuration file successfully generated at "{}"'
25-
.format(core.LOCAL_CONFIG_PATH)
27+
.format(LOCAL_CONFIG_PATH)
2628
)
2729
else:
2830
click.echo('Can not generate configuration file at "{}"'
29-
.format(core.LOCAL_CONFIG_PATH)
31+
.format(LOCAL_CONFIG_PATH)
3032
)
3133
else:
3234
click.echo('Configuration file already exists on path: "{}"'
33-
.format(core.LOCAL_CONFIG_PATH)
35+
.format(LOCAL_CONFIG_PATH)
3436
)
3537

3638

3739
@config.command('remove')
3840
def config_remove():
3941
""" Erase local configuration """
4042

41-
if core.LocalConfig.erase_config() is True:
43+
if LocalConfig.erase_config() is True:
4244
click.echo("All local configuration files and dirs successfully erased")
4345
else:
4446
click.echo("No local configuration files detected")
@@ -53,13 +55,13 @@ def config_get_path():
5355
doesn't mean that this file actually exists at the time the command is
5456
called
5557
"""
56-
click.echo(core.LOCAL_CONFIG_PATH)
58+
click.echo(LOCAL_CONFIG_PATH)
5759

5860

5961
@config.command('exist')
6062
def config_exist():
6163
""" Check does the local configuration file exists """
62-
if core.LOCAL_CONFIG_PATH.exists() is True:
64+
if LOCAL_CONFIG_PATH.exists() is True:
6365
click.echo("Configuration file do exist")
6466
else:
6567
click.echo("Configuration file doesn't exist")

hurocon/cli/device.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from pprint import pformat
22

33
import click
4+
from click_didyoumean import DYMGroup
45
from huawei_lte_api.Client import Client
56
from huawei_lte_api.enums.device import ControlModeEnum
67

7-
from .. import core
88
from .root import cli
9+
from ..core.connection import HRC_Connection
910

1011

11-
@cli.group()
12+
@cli.group(cls=DYMGroup)
1213
def device():
1314
""" Device commands """
1415
pass
@@ -18,7 +19,7 @@ def device():
1819
def device_info():
1920
""" Get device information """
2021
try:
21-
with core.HRC_Connection() as conn:
22+
with HRC_Connection() as conn:
2223
client = Client(conn)
2324
device_info_str = pformat(
2425
client.device.information()
@@ -36,7 +37,7 @@ def device_info():
3637
def device_reboot():
3738
""" Reboot the router without any confirmation prompts """
3839
try:
39-
with core.HRC_Connection() as conn:
40+
with HRC_Connection() as conn:
4041
Client(conn).device.set_control(ControlModeEnum.REBOOT)
4142
except Exception as e:
4243
msg = 'Execution failed, reason: "{}"'.format(e)

hurocon/cli/lte.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import click
2+
from click_didyoumean import DYMGroup
23
from huawei_lte_api.Client import Client
34

4-
from .. import core
55
from .root import cli
6+
from ..core.connection import HRC_Connection
67

78

8-
@cli.group()
9+
@cli.group(cls=DYMGroup)
910
def lte():
1011
""" Cellular connection controls """
1112
pass
@@ -15,7 +16,7 @@ def lte():
1516
def lte_status():
1617
""" Get cellular connection status """
1718
try:
18-
with core.HRC_Connection() as conn:
19+
with HRC_Connection() as conn:
1920
con_stat = Client(conn).dial_up.mobile_dataswitch()['dataswitch']
2021
except Exception as e:
2122
msg = 'Execution failed, reason: "{}"'.format(e)
@@ -35,7 +36,7 @@ def lte_set_connection(mode: bool):
3536
MODE (bool): True, False | [Y]es, [N]o | 1, 0
3637
"""
3738
try:
38-
with core.HRC_Connection() as conn:
39+
with HRC_Connection() as conn:
3940
Client(conn).dial_up.set_mobile_dataswitch(int(mode))
4041
except Exception as e:
4142
msg = 'Can not switch connection mode, reason: "{}"'.format(e)

hurocon/cli/models/sms.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from huawei_lte_api.Client import Client
2+
3+
from ...core.connection import HRC_Connection
4+
5+
6+
def get_sms_list_deep(page_depth: int = 1) -> dict:
7+
"""
8+
SMS deep scanning function
9+
10+
:param page_depth: Depth of pages to be fetched and scanned, defaults to 1
11+
:return: Dictionary with all messages
12+
"""
13+
messages_all = {
14+
'Count': 0,
15+
'Messages': {
16+
'Pages': [
17+
# page_0[[message_0, message_1]], page_1[[...]]...
18+
]
19+
}
20+
}
21+
22+
for selected_page in range(1, 2 if page_depth <= 1 else page_depth + 1):
23+
with HRC_Connection() as conn:
24+
messages_current_page = Client(conn).sms.get_sms_list(
25+
page=selected_page
26+
)
27+
28+
if messages_current_page['Count'] == '0':
29+
break
30+
31+
messages_all['Count'] = str(
32+
int(messages_all['Count']) + int(messages_current_page['Count'])
33+
)
34+
35+
messages_all['Messages']['Pages'].append(
36+
messages_current_page['Messages']['Message']
37+
)
38+
39+
return messages_all

hurocon/cli/root.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import click
2+
from click_didyoumean import DYMGroup
23

34
from .. import meta
45

56

6-
@click.group()
7+
@click.group(cls=DYMGroup)
78
@click.version_option(meta.version)
89
def cli():
910
""" Command line interface for Huawei LTE routers """

0 commit comments

Comments
 (0)