Skip to content

Commit bf07d2d

Browse files
committed
feat: refactor project and process configurations for improved readability and maintainability across multiple examples
1 parent 9478759 commit bf07d2d

File tree

5 files changed

+113
-66
lines changed

5 files changed

+113
-66
lines changed

README.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,22 @@ You can pass all configurations directly in Python code without needing a YAML f
140140
```python
141141
from fortscript import FortScript, RamConfig
142142

143+
projects = [
144+
{"name": "My Bot", "path": "./bot/main.py"},
145+
{"name": "Node API", "path": "./api/package.json"},
146+
]
147+
148+
heavy_processes = [
149+
{"name": "GTA V", "process": "gta5"},
150+
{"name": "OBS Studio", "process": "obs64"},
151+
]
152+
153+
ram_config = RamConfig(threshold=90, safe=80)
154+
143155
app = FortScript(
144-
projects=[
145-
{"name": "My Bot", "path": "./bot/main.py"},
146-
{"name": "Node API", "path": "./api/package.json"},
147-
],
148-
heavy_process=[
149-
{"name": "GTA V", "process": "gta5"},
150-
{"name": "OBS Studio", "process": "obs64"},
151-
],
152-
ram_config=RamConfig(threshold=90, safe=80),
156+
projects=projects,
157+
heavy_process=heavy_processes,
158+
ram_config=ram_config,
153159
log_level="INFO",
154160
)
155161

@@ -195,12 +201,14 @@ def when_paused():
195201
def when_resumed():
196202
print("💻 Back to work! Scripts resumed.")
197203

204+
callbacks = Callbacks(
205+
on_pause=when_paused,
206+
on_resume=when_resumed,
207+
)
208+
198209
app = FortScript(
199210
config_path="fortscript.yaml",
200-
callbacks=Callbacks(
201-
on_pause=when_paused,
202-
on_resume=when_resumed,
203-
)
211+
callbacks=callbacks,
204212
)
205213

206214
app.run()
@@ -284,22 +292,22 @@ my_project/
284292

285293
```python
286294
import os
287-
from fortscript import FortScript, GAMES
295+
from fortscript import FortScript, GAMES, RamConfig, Callbacks
288296

289297
# Project paths
290298
base_dir = os.path.dirname(os.path.abspath(__file__))
291299
bot_path = os.path.join(base_dir, "discord_bot", "main.py")
292300
api_path = os.path.join(base_dir, "local_api", "package.json")
293301

294302
# Projects to manage
295-
my_projects = [
303+
projects = [
296304
{"name": "Discord Bot", "path": bot_path},
297305
{"name": "Local API", "path": api_path},
298306
]
299307

300308
# Combining the default game list with custom processes
301309
# GAMES already includes GTA, Valorant, CS2, LOL, Fortnite, etc.
302-
my_heavy_processes = GAMES + [
310+
heavy_processes = GAMES + [
303311
{"name": "Video Editor", "process": "premiere"},
304312
{"name": "C++ Compiler", "process": "cl"}
305313
]
@@ -314,15 +322,20 @@ def on_resume():
314322
print("💻 WORK MODE - Resuming your scripts...")
315323
print("=" * 50)
316324

325+
# Configuration
326+
ram_config = RamConfig(threshold=85, safe=75)
327+
328+
callbacks = Callbacks(
329+
on_pause=on_pause,
330+
on_resume=on_resume,
331+
)
332+
317333
# Initialize FortScript
318334
app = FortScript(
319-
projects=my_projects,
320-
heavy_process=my_heavy_processes,
321-
ram_config=RamConfig(threshold=85, safe=75),
322-
callbacks=Callbacks(
323-
on_pause=on_pause,
324-
on_resume=on_resume,
325-
),
335+
projects=projects,
336+
heavy_process=heavy_processes,
337+
ram_config=ram_config,
338+
callbacks=callbacks,
326339
)
327340

328341
if __name__ == "__main__":

README_ptBR.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,22 @@ Você pode passar todas as configurações diretamente no código Python, sem pr
154154
```python
155155
from fortscript import FortScript, RamConfig
156156
157+
projects = [
158+
{"name": "Meu Bot", "path": "./bot/main.py"},
159+
{"name": "API Node", "path": "./api/package.json"},
160+
]
161+
162+
heavy_processes = [
163+
{"name": "GTA V", "process": "gta5"},
164+
{"name": "OBS Studio", "process": "obs64"},
165+
]
166+
167+
ram_config = RamConfig(threshold=90, safe=80)
168+
157169
app = FortScript(
158-
projects=[
159-
{"name": "Meu Bot", "path": "./bot/main.py"},
160-
{"name": "API Node", "path": "./api/package.json"},
161-
],
162-
heavy_process=[
163-
{"name": "GTA V", "process": "gta5"},
164-
{"name": "OBS Studio", "process": "obs64"},
165-
],
166-
ram_config=RamConfig(threshold=90, safe=80),
170+
projects=projects,
171+
heavy_process=heavy_processes,
172+
ram_config=ram_config,
167173
log_level="INFO",
168174
)
169175
@@ -213,12 +219,14 @@ def quando_retomar():
213219
print("💻 Voltando ao trabalho! Scripts retomados.")
214220
# Você pode: reconectar serviços, logar retorno, etc.
215221
222+
callbacks = Callbacks(
223+
on_pause=quando_pausar,
224+
on_resume=quando_retomar,
225+
)
226+
216227
app = FortScript(
217228
config_path="fortscript.yaml",
218-
callbacks=Callbacks(
219-
on_pause=quando_pausar, # Função executada ao pausar
220-
on_resume=quando_retomar, # Função executada ao retomar
221-
)
229+
callbacks=callbacks,
222230
)
223231
224232
app.run()
@@ -302,22 +310,22 @@ meu_projeto/
302310

303311
```python
304312
import os
305-
from fortscript import FortScript, GAMES
313+
from fortscript import FortScript, GAMES, RamConfig, Callbacks
306314
307315
# Caminhos dos projetos (usando os.path para compatibilidade)
308316
base_dir = os.path.dirname(os.path.abspath(__file__))
309317
bot_path = os.path.join(base_dir, "bot_discord", "main.py")
310318
api_path = os.path.join(base_dir, "api_local", "package.json")
311319
312320
# Lista de projetos para gerenciar
313-
meus_projetos = [
321+
projects = [
314322
{"name": "Bot Discord", "path": bot_path},
315323
{"name": "API Local", "path": api_path},
316324
]
317325
318326
# Combinando a lista de jogos padrão com processos personalizados
319327
# GAMES já inclui GTA, Valorant, CS2, LOL, Fortnite, etc.
320-
meus_processos_pesados = GAMES + [
328+
heavy_processes = GAMES + [
321329
{"name": "Editor De Vídeo", "process": "premiere"},
322330
{"name": "Compilador C++", "process": "cl"}
323331
]
@@ -333,15 +341,20 @@ def ao_retomar():
333341
print("💻 MODO TRABALHO - Retomando seus scripts...")
334342
print("=" * 50)
335343
344+
# Configurações
345+
ram_config = RamConfig(threshold=85, safe=75)
346+
347+
callbacks = Callbacks(
348+
on_pause=ao_pausar,
349+
on_resume=ao_retomar,
350+
)
351+
336352
# Inicializa o FortScript
337353
app = FortScript(
338-
projects=meus_projetos,
339-
heavy_process=meus_processos_pesados,
340-
ram_config=RamConfig(threshold=85, safe=75),
341-
callbacks=Callbacks(
342-
on_pause=ao_pausar,
343-
on_resume=ao_retomar,
344-
),
354+
projects=projects,
355+
heavy_process=heavy_processes,
356+
ram_config=ram_config,
357+
callbacks=callbacks,
345358
)
346359
347360
if __name__ == "__main__":

src/fortscript/cookbook/project_with_arguments/main.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
# Configuration for a typical developer development stack
1414
# These projects will be started automatically when system resources are stable
15-
development_projects = [
15+
projects = [
1616
{'name': 'API Gateway Simulator', 'path': backend_path}
1717
]
1818

1919
# Define heavy applications that should pause our dev stack
2020
# (e.g., when you want to play a game or render a video)
21-
productivity_blockers = [
21+
heavy_processes = [
2222
{'name': 'Chrome (Heavy Usage)', 'process': 'chrome.exe'},
2323
{'name': 'High-End Game', 'process': 'cyberpunk2077.exe'},
2424
{'name': 'Video Editor', 'process': 'premiere.exe'},
@@ -33,20 +33,24 @@ def on_resume():
3333
print('>>> [Event] System stable. Returning to development mode...')
3434

3535

36-
ram = RamConfig(
36+
# RAM configuration with hysteresis to prevent constant toggling
37+
ram_config = RamConfig(
3738
threshold=90, # Pause if RAM usage exceeds 90%
38-
safe=80, # Resume only when RAM falls below 80% (Hysteresis)
39+
safe=80, # Resume only when RAM falls below 80%
3940
)
4041

41-
# Initialize FortScript with our custom configuration and events
42+
# Callback functions for system events
43+
callbacks = Callbacks(
44+
on_pause=on_pause,
45+
on_resume=on_resume,
46+
)
47+
48+
# Initialize FortScript with our custom configuration
4249
app = FortScript(
43-
projects=development_projects,
44-
heavy_process=productivity_blockers,
45-
ram_config=ram,
46-
callbacks=Callbacks(
47-
on_pause=on_pause,
48-
on_resume=on_resume,
49-
),
50+
projects=projects,
51+
heavy_process=heavy_processes,
52+
ram_config=ram_config,
53+
callbacks=callbacks,
5054
log_level='DEBUG', # Show detailed logs for debugging
5155
)
5256

src/fortscript/cookbook/project_with_games_list/main.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
backend_path = os.path.join(base_dir, 'backend_simulator.py')
1919

2020
# Configuration for a typical developer development stack
21-
development_projects = [
21+
projects = [
2222
{'name': 'Backend API Simulator', 'path': backend_path}
2323
]
2424

2525

26+
# Callback functions for game detection events
2627
def on_pause():
2728
print('>>> [Event] Game detected! Development stack PAUSED.')
2829

@@ -31,16 +32,26 @@ def on_resume():
3132
print('>>> [Event] No games running. Resuming development stack...')
3233

3334

35+
# RAM configuration with hysteresis to prevent constant toggling
36+
ram_config = RamConfig(
37+
threshold=95, # Pause if RAM usage exceeds 95%
38+
safe=85, # Resume only when RAM falls below 85%
39+
)
40+
41+
# Callback configuration
42+
callbacks = Callbacks(
43+
on_pause=on_pause,
44+
on_resume=on_resume,
45+
)
46+
47+
3448
# Initialize FortScript utilizing the imported GAMES list
3549
# This demonstrates how to use the built-in list of heavy processes
3650
app = FortScript(
37-
projects=development_projects,
51+
projects=projects,
3852
heavy_process=GAMES, # Using the imported list directly
39-
ram_config=RamConfig(threshold=95, safe=85),
40-
callbacks=Callbacks(
41-
on_pause=on_pause,
42-
on_resume=on_resume,
43-
),
53+
ram_config=ram_config,
54+
callbacks=callbacks,
4455
log_level='DEBUG',
4556
)
4657

src/fortscript/cookbook/project_with_yaml_file/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ def welcome_back():
2121
print('✅ [System Alert] Resources cleared. Overlays are live again!')
2222

2323

24+
# Callback configuration
25+
callbacks = Callbacks(
26+
on_pause=alert_system,
27+
on_resume=welcome_back,
28+
)
29+
2430
# Initialize FortScript using the external YAML file and events
2531
app = FortScript(
2632
config_path=config_path,
27-
callbacks=Callbacks(on_pause=alert_system, on_resume=welcome_back),
33+
callbacks=callbacks,
2834
)
2935

3036

0 commit comments

Comments
 (0)