| #!/usr/bin/python |
| |
| import dbus, flimflam, sys |
| |
| flim = flimflam.FlimFlam(dbus.SystemBus()) |
| |
| if len(sys.argv) < 2: |
| 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 a_profile in flim.GetObjectList("Profile"): |
| if a_profile.object_path == active.object_path: |
| isactive = "*" |
| else: |
| isactive = " " |
| |
| # TODO(sleffler) handler ~user paths |
| identifier = a_profile.object_path[ |
| a_profile.object_path.rfind("/") + 1:] |
| |
| profile_properties = a_profile.GetProperties(utf8_strings = True) |
| name = profile_properties.get("Name", "<unnamed>") |
| |
| print "%s %-12s %s" % (isactive, identifier, name) |
| |
| if sys.argv[1] in ["list", "show"]: |
| print_profiles() |
| |
| elif sys.argv[1] in ["name"]: |
| 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(utf8_strings = True) |
| 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" |