Skip to content

Commit 487c29e

Browse files
authored
Config str (#47)
1 parent a821fce commit 487c29e

7 files changed

+46
-8
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Prevent external HD's from becoming inactive (sleeping).
44

55
**[https://joaonc.github.io/hd_active](https://joaonc.github.io/hd_active)**
66

7+
## Quick start
8+
```
9+
python -m app.hd_active --conf app/hd_active.ini
10+
```
11+
712
## Development
813
Note: Best to work on a virtual environment.
914
This page doesn't go into how to do that.

app/hd_active.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def change_state(self) -> HdActionState:
174174
config = HdActiveConfig(args.conf)
175175
hd_active = HdActive(drive_paths=config.drive_paths, run=config.run, wait=config.wait)
176176
hd_active.start()
177-
print('HD Active started.')
177+
print(f'HD Active started.\n{config}')
178178
while True:
179179
x = input('Type `s` to stop: ')
180180
if x.lower() == 's':

app/hd_active_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def __init__(self, file_name: str):
2525
)
2626
self.read()
2727

28+
def __str__(self):
29+
return f'drive paths: {", ".join(self.drive_paths)}' f'\nwait: {self.wait}s'
30+
2831
def read(self):
2932
files_read = self.config.read(self.file_name)
3033
if not files_read:

dev-requirements.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ colorama==0.4.4
3030
# pytest
3131
distlib==0.3.4
3232
# via virtualenv
33-
dparse==0.5.1
33+
dparse==0.6.2
3434
# via safety
3535
filelock==3.7.0
3636
# via virtualenv
@@ -110,11 +110,14 @@ pytest-check==1.0.5
110110
pyyaml==6.0
111111
# via
112112
# bandit
113-
# dparse
114113
# pre-commit
115114
requests==2.27.1
116115
# via safety
117-
safety==1.10.3
116+
ruamel-yaml==0.17.21
117+
# via safety
118+
ruamel-yaml-clib==0.2.7
119+
# via ruamel-yaml
120+
safety==2.3.5
118121
# via -r dev-requirements.in
119122
shiboken6==6.2.2.1
120123
# via

docs/index.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ The _objectives_ of this project, however are the following:
1919
* Other functionality that PyInvoke provides.
2020
* CI with GitHub Actions.
2121

22+
## Quick start
23+
```
24+
python -m app.hd_active --conf app/hd_active.ini
25+
```
26+
2227
## Config file
2328
The file `hd_active.ini`, located in the same folder as the app, is used to persist settings.
2429

@@ -37,6 +42,6 @@ The file is created/updated when settings change.
3742
```
3843
[HD Active]
3944
run_on_start = True
40-
wait_between_access = 60
45+
wait_between_access = 30
4146
drives = e:\, f:\, g:\
4247
```

tasks.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def ui_edit(c, file):
109109
file_stem = file[:-3] if file.lower().endswith('.ui') else file
110110
ui_file_path = next((p for p in UI_FILES if p.stem == file_stem), None)
111111
if not ui_file_path:
112-
raise Exit(
113-
f'File "{file}" not found. Available files: ", ".join(p.stem for p in UI_FILES)'
114-
)
112+
raise Exit(f'File "{file}" not found. Available files: ", ".join(p.stem for p in UI_FILES)')
115113

116114
c.run(f'pyside6-designer {ui_file_path}', asynchronous=True)
117115

@@ -210,6 +208,9 @@ def pip_package(c, requirements, package):
210208
def pip_upgrade(c, requirements):
211209
"""
212210
Try to upgrade all dependencies to their latest versions.
211+
212+
Use `pip-compile <filename> --upgrade-package <package>` to only upgrade one package.
213+
Ex `pip-compile dev-requirements.in --upgrade-package safety`
213214
"""
214215
for filename in _get_requirements_files(requirements, 'in'):
215216
c.run(f'pip-compile --upgrade {filename}')

tests/test_hd_active_config.py

+21
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,24 @@ def test_drives(config_file):
7070
def test_file_doesnt_exist():
7171
with pytest.raises(FileNotFoundError):
7272
HdActiveConfig('foo_doesnt_exist.ini')
73+
74+
75+
@pytest.mark.parametrize(
76+
'config_file',
77+
[
78+
pytest.param(
79+
(
80+
'''[HD Active]
81+
wait_between_access = 7
82+
drives = e:\\,f:\\''',
83+
'drive paths: e:\\, f:\\\nwait: 7.0s',
84+
),
85+
id='two drives',
86+
),
87+
],
88+
indirect=True,
89+
)
90+
def test_str(config_file):
91+
file_name, expected_str = config_file
92+
config = HdActiveConfig(file_name)
93+
assert str(config) == expected_str

0 commit comments

Comments
 (0)