| Index: test/test-profile | 
| diff --git a/test/test-profile b/test/test-profile | 
| index 28cf775bacfd9e94b00330dc6cbc97eb4ccd2b82..7dccd1befb0d278924af6a3e22db8899ffe35172 100755 | 
| --- a/test/test-profile | 
| +++ b/test/test-profile | 
| @@ -1,102 +1,86 @@ | 
| #!/usr/bin/python | 
|  | 
| -import sys | 
| -import dbus | 
| +import dbus, flimflam, sys | 
|  | 
| -bus = dbus.SystemBus() | 
| - | 
| -manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"), | 
| -					"org.chromium.flimflam.Manager") | 
| +flim = flimflam.FlimFlam(dbus.SystemBus()) | 
|  | 
| if len(sys.argv) < 2: | 
| -	print "Usage: %s <command>" % (sys.argv[0]) | 
| -	print "" | 
| -	print "  list" | 
| -	print "  name <profile> [name]" | 
| -	print "" | 
| -	print "  create <profile> [name]" | 
| -	print "  remove <profile>" | 
| -	sys.exit(1) | 
| - | 
| -def print_profiles(profiles, active): | 
| -	for path in profiles: | 
| -		profile = dbus.Interface(bus.get_object("org.chromium.flimflam", path), | 
| -						"org.chromium.flimflam.Profile") | 
| - | 
| -		properties = profile.GetProperties() | 
| - | 
| -		identifier = path[path.rfind("/") + 1:] | 
| - | 
| -		if (path == active): | 
| -			default = "*" | 
| -		else: | 
| -			default = " " | 
| - | 
| -		if "Name" in properties.keys(): | 
| -			name = properties["Name"] | 
| -		else: | 
| -			name = "<unnamed>" | 
| - | 
| -		print "%s %-12s %s" % (default, identifier, name) | 
| +    print "Usage: %s <command>" % (sys.argv[0]) | 
| +    print "  create <profile>" | 
| +    print "  list" | 
| +    print "  name <profile> [name]" | 
| +    print "  pop [<profile>]" | 
| +    print "  push <profile>" | 
| +    print "  remove <profile>" | 
| +    print "" | 
| +    print "where <profile> is of the form ident or ~user/ident" | 
| +    print "(beware that ~user may need shell quoting)" | 
| +    sys.exit(1) | 
| + | 
| + | 
| +def print_profiles(): | 
| +    active = flim.GetActiveProfile() | 
| +    for profile in flim.GetObjectList("Profile"): | 
| +        if profile.object_path == active.object_path: | 
| +            isactive = "*" | 
| +        else: | 
| +            isactive = " " | 
| + | 
| +	# TODO(sleffler) handler ~user paths | 
| +        identifier = profile.object_path[profile.object_path.rfind("/") + 1:] | 
| + | 
| +        properties = profile.GetProperties() | 
| +        name = properties.get("Name", "<unnamed>"); | 
| + | 
| +        print "%s %-12s %s" % (isactive, identifier, name) | 
|  | 
| if sys.argv[1] in ["list", "show"]: | 
| -	properties = manager.GetProperties() | 
| - | 
| -	print_profiles(properties["Profiles"], properties["ActiveProfile"]) | 
| +    print_profiles() | 
|  | 
| elif sys.argv[1] in ["name"]: | 
| -	if (len(sys.argv) < 3): | 
| -		print "Need at least profile parameter" | 
| -		sys.exit(1) | 
| - | 
| -	path = "/profile/" + sys.argv[2] | 
| - | 
| -	profile = dbus.Interface(bus.get_object("org.chromium.flimflam", path), | 
| -						"org.chromium.flimflam.Profile") | 
| - | 
| -	if (len(sys.argv) > 3): | 
| -		name = sys.argv[3] | 
| - | 
| -		profile.SetProperty("Name", name); | 
| - | 
| -		print "Name \"%s\" set for %s" % (name, sys.argv[2]) | 
| -	else: | 
| -		properties = profile.GetProperties() | 
| - | 
| -		if "Name" in properties.keys(): | 
| -			name = "\"" + properties["Name"] + "\"" | 
| -		else: | 
| -			name = "<unnamed>" | 
| - | 
| -		print "Name for %s is %s" % (sys.argv[2], name) | 
| - | 
| -elif sys.argv[1] in ["create", "add"]: | 
| -	if (len(sys.argv) < 3): | 
| -		print "Profile parameter required" | 
| -		sys.exit(1) | 
| - | 
| -	path = manager.CreateProfile(sys.argv[2]) | 
| - | 
| -	print "New profile created at %s" % (path) | 
| - | 
| -	profile = dbus.Interface(bus.get_object("org.chromium.flimflam", path), | 
| -						"org.chromium.flimflam.Profile") | 
| - | 
| -	if (len(sys.argv) > 3): | 
| -		name = sys.argv[3] | 
| - | 
| -		profile.SetProperty("Name", name); | 
| - | 
| -		print "Name \"%s\" set for %s" % (name, sys.argv[2]) | 
| - | 
| -elif sys.argv[1] in ["remove", "delete", "del"]: | 
| -	if (len(sys.argv) < 3): | 
| -		print "Profile parameter required" | 
| -		sys.exit(1) | 
| - | 
| -	path = "/profile/" + sys.argv[2] | 
| - | 
| -	manager.RemoveProfile(path) | 
| +    if (len(sys.argv) < 3): | 
| +        print "Need at least profile parameter" | 
| +        sys.exit(1) | 
| + | 
| +    profile = flim.FindElementByNameSubstring('Profile', sys.argv[2]) | 
| +    if (len(sys.argv) > 3): | 
| +        profile.SetProperty("Name", sys.argv[3]); | 
| +    else: | 
| +        properties = profile.GetProperties() | 
| +        print "%s" % properties.get("Name", "<unnamed>") | 
| + | 
| +elif sys.argv[1] in ["create"]: | 
| +    if (len(sys.argv) < 3): | 
| +        print "Profile identifier required" | 
| +        sys.exit(1) | 
| + | 
| +    flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| +    profile = flim.CreateProfile(sys.argv[2]) | 
| +    print "Created profile %s" % (profile.object_path) | 
| + | 
| +elif sys.argv[1] in ["remove"]: | 
| +    if (len(sys.argv) < 3): | 
| +        print "Profile identifier required" | 
| +        sys.exit(1) | 
| + | 
| +    flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| +    flim.RemoveProfile(sys.argv[2]) | 
| +    print "Removed profile %s" % (sys.argv[2]) | 
| + | 
| +elif sys.argv[1] in ["push"]: | 
| +    if (len(sys.argv) < 3): | 
| +        print "Profile identifier required" | 
| +        sys.exit(1) | 
| + | 
| +    flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| +    profile = flim.PushProfile(sys.argv[2]) | 
| +    print "Pushed profile %s" % (profile.object_path) | 
| + | 
| +elif sys.argv[1] in ["pop"]: | 
| +    if (len(sys.argv) == 3): | 
| +        flim.PopProfile(sys.argv[2]) | 
| +    else: | 
| +        flim.PopAnyProfile() | 
|  | 
| else: | 
| -	print "Unknown command" | 
| +    print "Unknown command" | 
|  |