Coverage for procpath/cmd/explore.py: 100%
36 statements
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2025-04-05 18:56 +0000
1import logging
2import os
3import shutil
4import threading
5import webbrowser
6from functools import partial
7from pathlib import Path
8from typing import Optional
9from urllib.parse import urlencode
11from .. import sqliteviz
14__all__ = 'run',
16logger = logging.getLogger('procpath')
19def run(
20 bind: str,
21 port: int,
22 open_in_browser: bool,
23 reinstall: bool,
24 build_url: str,
25 database_file: Optional[str] = None,
26):
27 user_cache_dir = Path(os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
28 sqliteviz_dir = user_cache_dir / 'procpath' / 'sqliteviz' (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
29 if not sqliteviz_dir.exists() or reinstall: (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
30 shutil.rmtree(sqliteviz_dir, ignore_errors=True) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
31 sqliteviz_dir.mkdir(parents=True) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
32 logger.info('Downloading %s into %s', build_url, sqliteviz_dir) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
33 sqliteviz.install_sqliteviz(build_url, sqliteviz_dir) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
34 else:
35 logger.info('Serving existing Sqliteviz from %s', sqliteviz_dir) procpath.test.cmd.TestExploreCommand.test_explore
37 url = 'http://{host}:{port}/'.format(port=port, host=bind or 'localhost') (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
38 logger.info('Serving Sqliteviz at %s', url) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
40 server_fn = partial(sqliteviz.serve_dir, bind, port, str(sqliteviz_dir)) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
41 server = threading.Thread(target=server_fn, daemon=True) (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
42 server.start() (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
44 if database_file: (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
45 try: procpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
46 sym_path = sqliteviz.symlink_database(database_file, sqliteviz_dir) procpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
47 except FileNotFoundError: procpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
48 logger.warning('Database file %s does not exist', database_file) procpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
49 else:
50 params = urlencode({'data_url': url + sym_path.name, 'data_format': 'sqlite'}) procpath.test.cmd.TestExploreCommand.test_explore_preload_database
51 url += f'#/load?{params}' procpath.test.cmd.TestExploreCommand.test_explore_preload_database
53 if open_in_browser: (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
54 webbrowser.open(url) procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing
56 server.join() (empty)procpath.test.cmd.TestExploreCommand.test_exploreprocpath.test.cmd.TestExploreCommand.test_explore_preload_databaseprocpath.test.cmd.TestExploreCommand.test_explore_preload_database_missing