|
8 | 8 |
|
9 | 9 | import click |
10 | 10 |
|
11 | | -from . import Profile, operations, profiles |
| 11 | +from . import Profile, profiles |
12 | 12 | from .choose import choose_profile |
13 | 13 | from .config import DEFAULT_CONFIG_FILE, Config, find_config |
| 14 | +from .desktop import create_desktop_file |
14 | 15 | from .launch import launch_qutebrowser |
15 | | -from .log import error, or_phrase |
16 | 16 | from .menus import supported_menus |
17 | | -from .paths import default_qbpm_config_dir, qutebrowser_data_dir |
| 17 | +from .paths import default_qbpm_config_dir |
| 18 | +from .session import profile_from_session |
18 | 19 |
|
19 | 20 | CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"], "max_content_width": 91} |
20 | 21 |
|
@@ -156,7 +157,6 @@ def new( |
156 | 157 | config.qutebrowser_config_directory = c_opts.qb_config_dir.absolute() |
157 | 158 | if c_opts.desktop_file is not None: |
158 | 159 | config.generate_desktop_file = c_opts.desktop_file |
159 | | - |
160 | 160 | exit_with( |
161 | 161 | profiles.new_profile( |
162 | 162 | profile, |
@@ -185,20 +185,18 @@ def from_session( |
185 | 185 | or a path to a session yaml file. |
186 | 186 | """ |
187 | 187 | config = context.load_config() |
188 | | - profile, session_path = session_info( |
189 | | - session, profile_name, config.profile_directory |
190 | | - ) |
191 | 188 | if c_opts.qb_config_dir: |
192 | 189 | config.qutebrowser_config_directory = c_opts.qb_config_dir.absolute() |
193 | 190 | if c_opts.desktop_file is not None: |
194 | 191 | config.generate_desktop_file = c_opts.desktop_file |
| 192 | + profile = profile_from_session( |
| 193 | + session, |
| 194 | + profile_name, |
| 195 | + config, |
| 196 | + c_opts.overwrite, |
| 197 | + ) |
195 | 198 | exit_with( |
196 | | - operations.from_session( |
197 | | - profile, |
198 | | - session_path, |
199 | | - config, |
200 | | - c_opts.overwrite, |
201 | | - ) |
| 199 | + profile is not None |
202 | 200 | and ((not c_opts.launch) or launch_qutebrowser(profile, c_opts.foreground)) |
203 | 201 | ) |
204 | 202 |
|
@@ -284,7 +282,10 @@ def desktop( |
284 | 282 | """Create an XDG desktop entry for an existing profile.""" |
285 | 283 | config = context.load_config() |
286 | 284 | profile = Profile(profile_name, config.profile_directory) |
287 | | - exit_with(operations.desktop(profile, config.desktop_file_directory)) |
| 285 | + exists = profiles.check(profile) |
| 286 | + if exists: |
| 287 | + create_desktop_file(profile, config.desktop_file_directory) |
| 288 | + return exit_with(exists) |
288 | 289 |
|
289 | 290 |
|
290 | 291 | @main.group(context_settings={"help_option_names": []}) |
@@ -314,28 +315,5 @@ def default() -> None: |
314 | 315 | print(DEFAULT_CONFIG_FILE.read_text(), end="") |
315 | 316 |
|
316 | 317 |
|
317 | | -def session_info( |
318 | | - session: str, profile_name: str | None, profile_dir: Path |
319 | | -) -> tuple[Profile, Path]: |
320 | | - user_session_dir = qutebrowser_data_dir() / "sessions" |
321 | | - session_paths = [] |
322 | | - if "/" not in session: |
323 | | - session_paths.append(user_session_dir / (session + ".yml")) |
324 | | - session_paths.append(Path(session)) |
325 | | - session_path = next(filter(lambda path: path.is_file(), session_paths), None) |
326 | | - |
327 | | - if session_path: |
328 | | - return ( |
329 | | - Profile( |
330 | | - profile_name or session_path.stem, |
331 | | - profile_dir, |
332 | | - ), |
333 | | - session_path, |
334 | | - ) |
335 | | - tried = or_phrase([str(p.resolve()) for p in session_paths]) |
336 | | - error(f"could not find session file at {tried}") |
337 | | - sys.exit(1) |
338 | | - |
339 | | - |
340 | 318 | def exit_with(result: bool) -> NoReturn: |
341 | 319 | sys.exit(0 if result else 1) |
0 commit comments