File tree Expand file tree Collapse file tree 3 files changed +30
-12
lines changed
Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Original file line number Diff line number Diff line change 1515)
1616from . import logger
1717from .app import create_app
18- from .startup import STARTUP_DIR , run_scripts
18+ from .startup import STARTUP_DIR , get_scripts , run_scripts
1919
2020
2121def parse_args (args : List [str ]) -> argparse .Namespace :
@@ -82,8 +82,13 @@ def main():
8282 if not STARTUP_DIR .is_dir ():
8383 STARTUP_DIR .mkdir (parents = True )
8484
85- logger .info ("Running startup scripts." )
86- processes = run_scripts ()
85+ scripts = get_scripts ()
86+ if scripts :
87+ logger .info ("Running startup scripts." )
88+ logger .debug ("Startup scripts: %s" , [script .name for script in scripts ])
89+ processes = run_scripts (scripts )
90+ else :
91+ processes = []
8792
8893 if args .show_qrcode :
8994 logger .info ("Generating qrcode." )
Original file line number Diff line number Diff line change 2222from ..tickers ._base import INTERVAL_LOOKBACKS
2323from ..waveshare_lib .models import MODELS
2424from .command import COMMANDS , reboot
25- from .startup import STARTUP_DIR
25+ from .startup import STARTUP_DIR , get_scripts
2626
2727LOGGER = logging .getLogger (__name__ )
2828TEMPLATE_PATH = str (Path (__file__ ).parent / "templates" )
@@ -208,8 +208,8 @@ def get_startup_script(filename):
208208 return send_from_directory (STARTUP_DIR , filename , mimetype = "text/plain" )
209209
210210 @app .route ("/startup" )
211- def startup_scippts ():
212- files = sorted ([path .name for path in STARTUP_DIR . glob ( "*" )])
211+ def startup_scripts ():
212+ files = sorted ([script .name for script in get_scripts ( )])
213213 return render_template ("startup.html" , files = files )
214214
215215 return app
Original file line number Diff line number Diff line change 11import logging
2+ import os
23import subprocess
34from pathlib import Path
5+ from typing import List
46
57LOGGER = logging .getLogger (__name__ )
68STARTUP_DIR = Path .home () / ".config" / "tinyticker" / "startup"
79
810
9- def run_scripts ():
10- scripts = [
11+ def get_scripts () -> List [Path ]:
12+ """Get the startup scripts."""
13+ return [
1114 file
12- for file in STARTUP_DIR .glob ( "*" )
13- if file .is_file () and not file .name .startswith ("." )
15+ for file in STARTUP_DIR .iterdir ( )
16+ if file .is_file () and not file .name .startswith ("." ) and os . access ( file , os . X_OK )
1417 ]
15- LOGGER .debug ("Running startup scripts: %s" , [file .name for file in scripts ])
18+
19+
20+ def run_scripts (scripts : List [Path ]) -> List [subprocess .Popen ]:
21+ """Run the startup scripts. The scripts must be executable.
22+
23+ Args:
24+ scripts: The scripts to run.
25+
26+ Returns:
27+ The processes running the scripts.
28+ """
1629 processes = []
1730 for file in scripts :
1831 LOGGER .debug ("Running startup script: %s" , file .name )
19- processes .append (subprocess .Popen (f" { file } " , shell = True ))
32+ processes .append (subprocess .Popen (str ( file ) , shell = True ))
2033 return processes
You can’t perform that action at this time.
0 commit comments