Skip to content

Commit 4dca0c1

Browse files
committed
Refactoring, add argparse support, update README.md
1 parent 10120e9 commit 4dca0c1

File tree

7 files changed

+142
-97
lines changed

7 files changed

+142
-97
lines changed

README.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Automatically generating directories and `browsers.json`, `docker-compose.yaml`,
1313
- [x] docker-compose.yaml
1414
- [x] teams-quota / users-quota
1515
- [x] htpasswd
16-
- [x] hosts config
16+
- [ ] hosts config
1717
- [x] standart parameters for selenoid
1818
- [ ] optional parameters for selenoid
1919
- [ ] shell-script for pull browser images from browsers-config
@@ -128,15 +128,37 @@ teams-quota: # [optional] - if use ggr balancer
128128
```
129129
130130
## Run script
131+
### 1. Go to the folder and give execute permissions
131132
```bash
132133
cd ~/selenoid-config-tool
133-
chmod u+x ./main.py
134-
./main.py
134+
chmod u+x ./sctool
135+
```
136+
### 2. Default usage
137+
```bash
138+
./sctool
139+
```
140+
### 3. Usage with parameters
141+
#### 3.1 Get help
142+
```bash
143+
./sctool --help
144+
```
145+
#### 3.2 Run with custom parameters
146+
```bash
147+
./sctool --results-dir ./your-results-dir --config-dir ./your-config-dir
148+
# or
149+
./sctool -r ./your-results-dir -c ./your-config-dir
135150
```
136151

137152
## Results
138153
### 1. Change to the directory with the results
139154
```bash
140155
cd ~/selenoid-config-tool/results
141156
```
142-
### 2. Ready!
157+
### 2. Ready!
158+
159+
## Possible problems
160+
The tool uses caching for http-responses. Therefore, in rare cases, you may not receive up-to-date information on browser versions. The cache is stored in the default folder for your user - `~/.cache/`
161+
#### For remove cache, usage:
162+
```bash
163+
rm ~/.cache/selenoid_config_tool_requests_cache.sqlite
164+
```

config/test_config.yaml examples/config/config.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ browsers:
1515
versions: # from min and to max in steps of 1
1616
range:
1717
min: 80.0
18-
max: 98.0
18+
max: 99.0
1919
ignore: [82.0]
20-
#capabilities:
21-
# vnc_enabled: True
22-
# video_enabled: False
23-
# session_timeout: "1m"
2420

2521
- type: chrome-mobile
2622
use: true

main.py

-35
This file was deleted.

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ pykwalify==1.8.0
44
requests==2.27.1
55
requests-cache==0.9.1
66
htpasswd==2.3
7-
lxml==4.8.0
7+
lxml==4.8.0
8+
halo==0.0.31

sctool

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /usr/bin/env python3
2+
3+
import argparse
4+
import sys
5+
import os
6+
7+
from helpers.change_root_dir import ChangeRootDir
8+
from src.configurator import Configurator
9+
10+
11+
def init() -> None:
12+
try:
13+
change_root_dir = ChangeRootDir()
14+
change_root_dir() # Change directory to be able to run script in different directories
15+
except:
16+
print("Something went wrong. Root directory not changed.")
17+
finally:
18+
del change_root_dir
19+
20+
21+
def main() -> None:
22+
init()
23+
cmd_args.config_dir = os.path.abspath(cmd_args.config_dir)
24+
cmd_args.results_dir = os.path.abspath(cmd_args.results_dir)
25+
print(cmd_args)
26+
configurator = Configurator(cmd_args)
27+
configurator()
28+
print(f'Complete!\n'
29+
f'\n'
30+
f'Find your results into {cmd_args.results_dir} directory')
31+
32+
33+
if __name__ == '__main__':
34+
parser = argparse.ArgumentParser(prog='sctool')
35+
36+
parser.add_argument('-r',
37+
'--results-dir',
38+
default='./results',
39+
help='Directory to save results, default - ./results'
40+
)
41+
parser.add_argument('-c',
42+
'--config-dir',
43+
default='./config',
44+
help='Directory to get yaml config file, default - ./config'
45+
)
46+
47+
cmd_args = parser.parse_args()
48+
sys.exit(main())

helpers/config_parser.py src/config_parser.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ class ConfigParser(OpenFile):
88
ic.disable()
99
# ic.enable()
1010

11-
def __init__(self) -> None:
12-
self.file_path = './config/test_config.yaml'
11+
def __init__(self, config_dir) -> None:
12+
self.config_dir = config_dir
13+
ic(self.config_dir)
14+
15+
self.file_path = f'{self.config_dir}/config.yaml'
1316
self.schema_path = './config/schema/config_schema.yaml'
1417
super().__init__(self.file_path)
1518
self.config_file = self.open_yaml_file()

0 commit comments

Comments
 (0)