Skip to content

Commit 6389a09

Browse files
committed
move Profile to __init__.py
1 parent b268d07 commit 6389a09

File tree

4 files changed

+52
-46
lines changed

4 files changed

+52
-46
lines changed

qbpm/__init__.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1+
from pathlib import Path
2+
from typing import Optional
3+
4+
from xdg import BaseDirectory
5+
6+
from .utils import error, qutebrowser_exe
7+
18
try:
29
from qbpm.version import version as __version__ # type: ignore
310
except ImportError:
411
__version__ = "unknown"
12+
13+
14+
class Profile:
15+
name: str
16+
profile_dir: Path
17+
root: Path
18+
qb_config_dir: Optional[Path]
19+
20+
def __init__(
21+
self,
22+
name: str,
23+
profile_dir: Optional[Path],
24+
qb_config_dir: Optional[Path] = None,
25+
) -> None:
26+
self.name = name
27+
self.profile_dir = profile_dir or Path(
28+
BaseDirectory.save_data_path("qutebrowser-profiles")
29+
)
30+
self.root = self.profile_dir / name
31+
self.qb_config_dir = qb_config_dir
32+
33+
def check(self) -> Optional["Profile"]:
34+
if "/" in self.name:
35+
error("profile name cannot contain slashes")
36+
return None
37+
return self
38+
39+
def exists(self) -> bool:
40+
return self.root.exists() and self.root.is_dir()
41+
42+
def cmdline(self) -> list[str]:
43+
return [
44+
qutebrowser_exe(),
45+
"-B",
46+
str(self.root),
47+
"--qt-arg",
48+
"name",
49+
self.name,
50+
"--desktop-file-name",
51+
self.name,
52+
]

qbpm/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import click
88

9-
from . import operations, profiles
10-
from .profiles import Profile
9+
from . import Profile, operations, profiles
1110
from .utils import SUPPORTED_MENUS, default_profile_dir, error, or_phrase, user_data_dir
1211

1312
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}

qbpm/operations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from xdg import BaseDirectory
99

10-
from . import profiles
11-
from .profiles import Profile
10+
from . import Profile, profiles
1211
from .utils import env_menus, error, installed_menus, or_phrase, qutebrowser_exe
1312

1413

qbpm/profiles.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,8 @@
55
from xdg import BaseDirectory
66
from xdg.DesktopEntry import DesktopEntry
77

8-
from .utils import error, or_phrase, qutebrowser_exe, user_config_dirs
9-
10-
11-
class Profile:
12-
name: str
13-
profile_dir: Path
14-
root: Path
15-
qb_config_dir: Optional[Path]
16-
17-
def __init__(
18-
self,
19-
name: str,
20-
profile_dir: Optional[Path],
21-
qb_config_dir: Optional[Path] = None,
22-
) -> None:
23-
self.name = name
24-
self.profile_dir = profile_dir or Path(
25-
BaseDirectory.save_data_path("qutebrowser-profiles")
26-
)
27-
self.root = self.profile_dir / name
28-
self.qb_config_dir = qb_config_dir
29-
30-
def check(self) -> Optional["Profile"]:
31-
if "/" in self.name:
32-
error("profile name cannot contain slashes")
33-
return None
34-
return self
35-
36-
def exists(self) -> bool:
37-
return self.root.exists() and self.root.is_dir()
38-
39-
def cmdline(self) -> list[str]:
40-
return [
41-
qutebrowser_exe(),
42-
"-B",
43-
str(self.root),
44-
"--qt-arg",
45-
"name",
46-
self.name,
47-
"--desktop-file-name",
48-
self.name,
49-
]
8+
from . import Profile
9+
from .utils import error, or_phrase, user_config_dirs
5010

5111

5212
def create_profile(profile: Profile, overwrite: bool = False) -> bool:

0 commit comments

Comments
 (0)