~shanepatrickfagan/ubuntu-sso-client/nm-state-bug-fix

« back to all changes in this revision

Viewing changes to ubuntu_sso/networkstate/linux.py

  • Committer: Shane Fagan
  • Date: 2011-06-02 15:04:14 UTC
  • Revision ID: shanepatrickfagan@ubuntu.com-20110602150414-hrgazbv0ze27kdl3
made the code a lot cleaner and did the suggestions that the guys said but still no tests. Will do them next

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
                                         NM_DBUS_OBJECTPATH,
91
91
                                         follow_name_owner_changes=True)
92
92
            nm_if = self.dbus.Interface(nm_proxy, NM_DBUS_INTERFACE)
93
 
            # detect the version and choose the correct values
94
 
            if str(nm_proxy.Get(NM_DBUS_INTERFACE, 
95
 
                    "Version")) >= "0.8.9997":
96
 
                self.NM_STATE_ASLEEP = 10
97
 
                self.NM_STATE_DISCONNECTED = 20
98
 
                self.NM_STATE_CONNECTING = 40
99
 
                self.NM_STATE_CONNECTED = 70
100
 
            else:
101
 
 
102
 
                self.NM_STATE_ASLEEP = 1
103
 
                self.NM_STATE_CONNECTING = 2
104
 
                self.NM_STATE_CONNECTED = 3
105
 
                self.NM_STATE_DISCONNECTED = 4
106
 
            self.NM_STATE_UNKNOWN = 0
 
93
            self.check_nm_state_version(nm_proxy)
107
94
            self.state_signal = nm_if.connect_to_signal(
108
95
                        signal_name="StateChanged",
109
96
                        handler_function=self.state_changed,
113
100
                         error_handler=self.got_error)
114
101
        except Exception, e:  # pylint: disable=W0703
115
102
            self.got_error(e)
 
103
 
 
104
    def check_nm_state_version(self, nm_proxy):
 
105
        """ detect the version and choose the correct values"""
 
106
        version = str(nm_proxy.Get(NM_DBUS_INTERFACE,
 
107
                    "Version")).split(".")
 
108
        new_state_version = False
 
109
        print "checking nm version for state API"
 
110
        print version
 
111
        print int(version[1])
 
112
        if int(version[0]) == 0 and int(version[1]) <= 8:
 
113
            print "below version 8"
 
114
            if int(version[1]) == 8 and version[2].startswith("99"):
 
115
                    new_state_version = True
 
116
        else:
 
117
            new_state_version = True
 
118
        if new_state_version == True:
 
119
            print "New state version"
 
120
            self.NM_STATE_ASLEEP = 10
 
121
            self.NM_STATE_DISCONNECTED = 20
 
122
            self.NM_STATE_CONNECTING = 40
 
123
            self.NM_STATE_CONNECTED = 70
 
124
        else:
 
125
            print "old state version"
 
126
            self.NM_STATE_ASLEEP = 1
 
127
            self.NM_STATE_CONNECTING = 2
 
128
            self.NM_STATE_CONNECTED = 3
 
129
            self.NM_STATE_DISCONNECTED = 4    
 
130
        self.NM_STATE_UNKNOWN = 0