qutebrowser profile manager
0
fork

Configure Feed

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

better checking for invalid profile names

+20 -18
+5 -8
src/qbpm/__init__.py
··· 20 20 self.profile_dir = profile_dir 21 21 self.root = self.profile_dir / name 22 22 23 - def check(self) -> Optional["Profile"]: 24 - if "/" in self.name: 25 - error("profile name cannot contain slashes") 26 - return None 27 - return self 28 - 29 - def exists(self) -> bool: 30 - return self.root.exists() and self.root.is_dir() 23 + def check_name(self) -> bool: 24 + if "/" in self.name or self.name in [".", ".."]: 25 + error("profile name cannot be a path") 26 + return False 27 + return True 31 28 32 29 def cmdline(self) -> list[str]: 33 30 return [
+3 -2
src/qbpm/main.py
··· 190 190 191 191 All QB_ARGS are passed on to qutebrowser.""" 192 192 profile = Profile(profile_name, **vars(context)) 193 + if not profiles.check(profile): 194 + sys.exit(1) 193 195 exit_with(launch_qutebrowser(profile, foreground, qb_args)) 194 196 195 197 ··· 223 225 def edit(context: Context, profile_name: str) -> None: 224 226 """Edit a profile's config.py.""" 225 227 profile = Profile(profile_name, **vars(context)) 226 - if not profile.exists(): 227 - error(f"profile {profile.name} not found at {profile.root}") 228 + if not profiles.check(profile): 228 229 sys.exit(1) 229 230 click.edit(filename=str(profile.root / "config" / "config.py")) 230 231
+1 -3
src/qbpm/operations.py
··· 24 24 25 25 26 26 def desktop(profile: Profile) -> bool: 27 - exists = profile.exists() 27 + exists = profiles.check(profile) 28 28 if exists: 29 29 create_desktop_file(profile) 30 - else: 31 - error(f"profile {profile.name} not found at {profile.root}") 32 30 return exists
+11 -5
src/qbpm/profiles.py
··· 23 23 24 24 25 25 def create_profile(profile: Profile, overwrite: bool = False) -> bool: 26 - if not profile.check(): 26 + if not profile.check_name(): 27 27 return False 28 28 29 29 if not overwrite and profile.root.exists(): ··· 53 53 out(f"config.source(r'{qb_config_dir / 'config.py'}')") 54 54 55 55 56 - def exists(profile: Profile) -> bool: 57 - if profile.root.exists() and not profile.root.is_dir(): 58 - error(f"{profile.root} is not a directory") 56 + def check(profile: Profile) -> bool: 57 + if not profile.check_name(): 59 58 return False 60 - if not profile.root.exists(): 59 + exists = profile.root.exists() 60 + if not exists: 61 61 error(f"{profile.root} does not exist") 62 + return False 63 + if not profile.root.is_dir(): 64 + error(f"{profile.root} is not a directory") 65 + return False 66 + if not (profile.root / "config").is_dir(): 67 + error(f"no config directory in {profile.root}, is it a profile?") 62 68 return False 63 69 return True 64 70