qutebrowser profile manager

factory method

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