qutebrowser profile manager

factory method

+18 -9
+5 -9
qbpm/main.py
··· 34 34 new.add_argument("home_page", metavar="url", nargs="?", help="profile's home page") 35 35 new.set_defaults( 36 36 operation=lambda args: profiles.new_profile( 37 - build_profile(args), 37 + Profile.of(args), 38 38 args.home_page, 39 39 args.desktop_file, 40 40 args.overwrite, ··· 73 73 desktop.add_argument( 74 74 "profile_name", metavar="profile", help="profile to create a desktop file for" 75 75 ) 76 - desktop.set_defaults(operation=lambda args: operations.desktop(build_profile(args))) 76 + desktop.set_defaults(operation=lambda args: operations.desktop(Profile.of(args))) 77 77 78 78 launch = subparsers.add_parser( 79 79 "launch", aliases=["run"], help="launch qutebrowser with the given profile" ··· 98 98 ) 99 99 launch.set_defaults( 100 100 operation=lambda args: operations.launch( 101 - build_profile(args), args.strict, args.foreground, args.qb_args 101 + Profile.of(args), args.strict, args.foreground, args.qb_args 102 102 ), 103 103 passthrough=True, 104 104 ) ··· 128 128 "edit", help="edit a profile's config.py using $EDITOR" 129 129 ) 130 130 edit.add_argument("profile_name", metavar="profile", help="profile to edit") 131 - edit.set_defaults(operation=lambda args: operations.edit(build_profile(args))) 131 + edit.set_defaults(operation=lambda args: operations.edit(Profile.of(args))) 132 132 133 133 raw_args = parser.parse_known_args(mock_args) 134 134 args = raw_args[0] ··· 191 191 if isinstance(result, Profile): 192 192 profile = result 193 193 else: 194 - profile = build_profile(args) 194 + profile = Profile.of(args) 195 195 return operations.launch(profile, False, args.foreground, args.qb_args) 196 196 return False 197 - 198 - 199 - def build_profile(args: argparse.Namespace) -> Profile: 200 - return Profile(args.profile_name, args.profile_dir) 201 197 202 198 203 199 if __name__ == "__main__":
+13
qbpm/profiles.py
··· 21 21 ) 22 22 self.root = self.profile_dir / name 23 23 24 + def of(args: object) -> "Profile": 25 + args = vars(args) 26 + name = args.get("profile_name") 27 + assert isinstance(name, str) 28 + return Profile( 29 + name, 30 + args.get( 31 + "profile_dir", 32 + Path(BaseDirectory.save_data_path("qutebrowser-profiles")), 33 + ), 34 + args.get("set_app_id", False), 35 + ) 36 + 24 37 def check(self) -> Optional["Profile"]: 25 38 if "/" in self.name: 26 39 error("profile name cannot contain slashes")