| OLD | NEW | 
|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python | 
| 2 | 2 | 
| 3 import sys | 3 import dbus, flimflam, sys | 
| 4 import dbus |  | 
| 5 | 4 | 
| 6 bus = dbus.SystemBus() | 5 flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| 7 |  | 
| 8 manager = dbus.Interface(bus.get_object("org.chromium.flimflam", "/"), |  | 
| 9 »       »       »       »       »       "org.chromium.flimflam.Manager") |  | 
| 10 | 6 | 
| 11 if len(sys.argv) < 2: | 7 if len(sys.argv) < 2: | 
| 12 »       print "Usage: %s <command>" % (sys.argv[0]) | 8     print "Usage: %s <command>" % (sys.argv[0]) | 
| 13 »       print "" | 9     print "  create <profile>" | 
| 14 »       print "  list" | 10     print "  list" | 
| 15 »       print "  name <profile> [name]" | 11     print "  name <profile> [name]" | 
| 16 »       print "" | 12     print "  pop [<profile>]" | 
| 17 »       print "  create <profile> [name]" | 13     print "  push <profile>" | 
| 18 »       print "  remove <profile>" | 14     print "  remove <profile>" | 
| 19 »       sys.exit(1) | 15     print "" | 
|  | 16     print "where <profile> is of the form ident or ~user/ident" | 
|  | 17     print "(beware that ~user may need shell quoting)" | 
|  | 18     sys.exit(1) | 
| 20 | 19 | 
| 21 def print_profiles(profiles, active): |  | 
| 22         for path in profiles: |  | 
| 23                 profile = dbus.Interface(bus.get_object("org.chromium.flimflam",
      path), |  | 
| 24                                                 "org.chromium.flimflam.Profile") |  | 
| 25 | 20 | 
| 26 »       »       properties = profile.GetProperties() | 21 def print_profiles(): | 
|  | 22     active = flim.GetActiveProfile() | 
|  | 23     for profile in flim.GetObjectList("Profile"): | 
|  | 24         if profile.object_path == active.object_path: | 
|  | 25             isactive = "*" | 
|  | 26         else: | 
|  | 27             isactive = " " | 
| 27 | 28 | 
| 28 »       »       identifier = path[path.rfind("/") + 1:] | 29 »       # TODO(sleffler) handler ~user paths | 
|  | 30         identifier = profile.object_path[profile.object_path.rfind("/") + 1:] | 
| 29 | 31 | 
| 30 »       »       if (path == active): | 32         properties = profile.GetProperties() | 
| 31 »       »       »       default = "*" | 33         name = properties.get("Name", "<unnamed>"); | 
| 32 »       »       else: |  | 
| 33 »       »       »       default = " " |  | 
| 34 | 34 | 
| 35 »       »       if "Name" in properties.keys(): | 35         print "%s %-12s %s" % (isactive, identifier, name) | 
| 36 »       »       »       name = properties["Name"] |  | 
| 37 »       »       else: |  | 
| 38 »       »       »       name = "<unnamed>" |  | 
| 39 |  | 
| 40 »       »       print "%s %-12s %s" % (default, identifier, name) |  | 
| 41 | 36 | 
| 42 if sys.argv[1] in ["list", "show"]: | 37 if sys.argv[1] in ["list", "show"]: | 
| 43 »       properties = manager.GetProperties() | 38     print_profiles() | 
| 44 |  | 
| 45 »       print_profiles(properties["Profiles"], properties["ActiveProfile"]) |  | 
| 46 | 39 | 
| 47 elif sys.argv[1] in ["name"]: | 40 elif sys.argv[1] in ["name"]: | 
| 48 »       if (len(sys.argv) < 3): | 41     if (len(sys.argv) < 3): | 
| 49 »       »       print "Need at least profile parameter" | 42         print "Need at least profile parameter" | 
| 50 »       »       sys.exit(1) | 43         sys.exit(1) | 
| 51 | 44 | 
| 52 »       path = "/profile/" + sys.argv[2] | 45     profile = flim.FindElementByNameSubstring('Profile', sys.argv[2]) | 
|  | 46     if (len(sys.argv) > 3): | 
|  | 47         profile.SetProperty("Name", sys.argv[3]); | 
|  | 48     else: | 
|  | 49         properties = profile.GetProperties() | 
|  | 50         print "%s" % properties.get("Name", "<unnamed>") | 
| 53 | 51 | 
| 54 »       profile = dbus.Interface(bus.get_object("org.chromium.flimflam", path), | 52 elif sys.argv[1] in ["create"]: | 
| 55 »       »       »       »       »       »       "org.chromium.flimflam.Profile") | 53     if (len(sys.argv) < 3): | 
|  | 54         print "Profile identifier required" | 
|  | 55         sys.exit(1) | 
| 56 | 56 | 
| 57 »       if (len(sys.argv) > 3): | 57     flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| 58 »       »       name = sys.argv[3] | 58     profile = flim.CreateProfile(sys.argv[2]) | 
|  | 59     print "Created profile %s" % (profile.object_path) | 
| 59 | 60 | 
| 60 »       »       profile.SetProperty("Name", name); | 61 elif sys.argv[1] in ["remove"]: | 
|  | 62     if (len(sys.argv) < 3): | 
|  | 63         print "Profile identifier required" | 
|  | 64         sys.exit(1) | 
| 61 | 65 | 
| 62 »       »       print "Name \"%s\" set for %s" % (name, sys.argv[2]) | 66     flim = flimflam.FlimFlam(dbus.SystemBus()) | 
| 63 »       else: | 67     flim.RemoveProfile(sys.argv[2]) | 
| 64 »       »       properties = profile.GetProperties() | 68     print "Removed profile %s" % (sys.argv[2]) | 
| 65 | 69 | 
| 66 »       »       if "Name" in properties.keys(): | 70 elif sys.argv[1] in ["push"]: | 
| 67 »       »       »       name = "\"" + properties["Name"] + "\"" | 71     if (len(sys.argv) < 3): | 
| 68 »       »       else: | 72         print "Profile identifier required" | 
| 69 »       »       »       name = "<unnamed>" | 73         sys.exit(1) | 
| 70 | 74 | 
| 71 »       »       print "Name for %s is %s" % (sys.argv[2], name) | 75     flim = flimflam.FlimFlam(dbus.SystemBus()) | 
|  | 76     profile = flim.PushProfile(sys.argv[2]) | 
|  | 77     print "Pushed profile %s" % (profile.object_path) | 
| 72 | 78 | 
| 73 elif sys.argv[1] in ["create", "add"]: | 79 elif sys.argv[1] in ["pop"]: | 
| 74 »       if (len(sys.argv) < 3): | 80     if (len(sys.argv) == 3): | 
| 75 »       »       print "Profile parameter required" | 81         flim.PopProfile(sys.argv[2]) | 
| 76 »       »       sys.exit(1) | 82     else: | 
| 77 | 83         flim.PopAnyProfile() | 
| 78 »       path = manager.CreateProfile(sys.argv[2]) |  | 
| 79 |  | 
| 80 »       print "New profile created at %s" % (path) |  | 
| 81 |  | 
| 82 »       profile = dbus.Interface(bus.get_object("org.chromium.flimflam", path), |  | 
| 83 »       »       »       »       »       »       "org.chromium.flimflam.Profile") |  | 
| 84 |  | 
| 85 »       if (len(sys.argv) > 3): |  | 
| 86 »       »       name = sys.argv[3] |  | 
| 87 |  | 
| 88 »       »       profile.SetProperty("Name", name); |  | 
| 89 |  | 
| 90 »       »       print "Name \"%s\" set for %s" % (name, sys.argv[2]) |  | 
| 91 |  | 
| 92 elif sys.argv[1] in ["remove", "delete", "del"]: |  | 
| 93 »       if (len(sys.argv) < 3): |  | 
| 94 »       »       print "Profile parameter required" |  | 
| 95 »       »       sys.exit(1) |  | 
| 96 |  | 
| 97 »       path = "/profile/" + sys.argv[2] |  | 
| 98 |  | 
| 99 »       manager.RemoveProfile(path) |  | 
| 100 | 84 | 
| 101 else: | 85 else: | 
| 102 »       print "Unknown command" | 86     print "Unknown command" | 
| OLD | NEW | 
|---|