qutebrowser profile manager
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

implement launch command

+73 -8
+25
qbpm/main.py
··· 25 25 operation=lambda args: operations.from_session(args.session, args.profile_name) 26 26 ) 27 27 28 + launch = subparsers.add_parser("launch") 29 + launch.add_argument( 30 + "profile_name", 31 + metavar="name", 32 + nargs="?", 33 + help="profile to launch. it will be created if it does not exist, unless -s is set", 34 + ) 35 + launch.add_argument( 36 + "-s", 37 + "--strict", 38 + action="store_true", 39 + help="return an error if the profile does not exist", 40 + ) 41 + launch.add_argument( 42 + "-f", 43 + "--foreground", 44 + action="store_true", 45 + help="launch qutebrowser in the foreground and print its stdout and stderr to the console", 46 + ) 47 + launch.set_defaults( 48 + operation=lambda args: operations.launch( 49 + args.profile_name, args.strict, args.foreground 50 + ) 51 + ) 52 + 28 53 args = parser.parse_args() 29 54 args.operation(args)
+48 -8
qbpm/operations.py
··· 1 + import os 1 2 import platform 2 3 import shutil 4 + import subprocess 3 5 import sys 4 6 from pathlib import Path 5 - from typing import Optional 7 + from typing import Optional, Union 6 8 7 9 from xdg import BaseDirectory # type: ignore 8 10 ··· 18 20 sys.exit(1) 19 21 20 22 21 - def create_profile(profile_name: str) -> Optional[Path]: 22 - profile_root = profiles_dir / profile_name 23 + def get_profile_root(profile_name: str) -> Path: 24 + return profiles_dir / profile_name 25 + 26 + 27 + def create_profile(profile: Union[str, Path]) -> Optional[Path]: 28 + if isinstance(profile, str): 29 + profile_root = get_profile_root(profile) 30 + else: 31 + profile_root = profile 23 32 24 33 if profile_root.exists(): 25 34 error(f"{profile_root} already exists") ··· 35 44 print(f"config.source('{main_config_dir / 'config.py'}')", file=conf) 36 45 37 46 38 - def new_profile(profile_name: str) -> Optional[Path]: 39 - profile_root = create_profile(profile_name) 40 - if not profile_root: 41 - return None 47 + def new_profile(profile: Union[str, Path]) -> Optional[Path]: 48 + profile_root = create_profile(profile) 49 + if profile_root: 50 + create_config(profile_root) 42 51 43 - create_config(profile_root) 44 52 return profile_root 45 53 46 54 55 + def ensure_profile_exists(profile_name: str, create: bool = True) -> Optional[Path]: 56 + profile = get_profile_root(profile_name) 57 + if profile.exists() and not profile.is_dir(): 58 + error(f"{profile} is not a directory") 59 + return None 60 + elif not profile.exists(): 61 + if create: 62 + return new_profile(profile) 63 + else: 64 + error(f"{profile} does not exist") 65 + return None 66 + else: 67 + return profile 68 + 69 + 47 70 def from_session( 48 71 session_name: str, profile_name: Optional[str] = None 49 72 ) -> Optional[Path]: ··· 61 84 shutil.copy(session, session_dir / "_autosave.yml") 62 85 63 86 return profile_root 87 + 88 + 89 + def launch(profile_name: str, strict: bool, foreground: bool) -> bool: 90 + profile = ensure_profile_exists(profile_name, not strict) 91 + if not profile: 92 + return False 93 + 94 + if foreground: 95 + os.execlp("qutebrowser", "qutebrowser", "-B", str(profile)) 96 + else: 97 + subprocess.Popen( 98 + ["qutebrowser", "-B", str(profile)], 99 + stdout=subprocess.DEVNULL, 100 + stderr=subprocess.DEVNULL, 101 + ) 102 + 103 + return True 64 104 65 105 66 106 def error(msg: str) -> None: