~nilsschlupp/auto-ndiswrapper/rewrite

« back to all changes in this revision

Viewing changes to main/auto-ndis.py

  • Committer: Nils Schlupp
  • Date: 2009-03-24 19:37:36 UTC
  • Revision ID: nils.schlupp@gmail.com-20090324193736-kdiaky8i1prhzlji
added test case to database, modified database layout, moved some stuff to subfunctions

about to remove old database files

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
                ##Stores the usb ids in a list
123
123
                usb = self.process_pciids(outtext)
124
124
                
125
 
                
126
 
                pcilist = usblist = None
127
 
                
128
 
                # Try getting info from server
129
 
                if opts.repo == 'auto' or opts.repo == 'remote':
130
 
                        try:
131
 
                                pcilist = self.serverquery(pci)
132
 
                                usblist = self.serverquery(usb)
133
 
                        except ConnectionFailed:
134
 
                                logger.error('Failed to connect to server')
135
 
                                if opts.repo == 'auto':
136
 
                                        logger.error('Trying local database')
137
 
                
138
 
                # If we have nothing, either fail or try the local reposotory
139
 
                if pcilist == None and usblist == None:
140
 
                        if opts.repo == 'remote':
141
 
                                raise ConnectionFailed('Unable to establish connection. Please either check your interent connection or download the local database from FIXME...')
142
 
                        
143
 
                        pcilist = self.localquery(pci)
144
 
                        usblist = self.localquery(usb)
145
 
                
146
 
                return pcilist, usblist
147
 
        
 
125
                return pci, usb
 
126
                
148
127
                ##Checks if the user has a pci card or a usb card, if he has both the program will ask card he wants to setup
149
128
                ##If he has neither the program will exit and tell him what pci card he has if he has one
150
129
                #if pcicard != 'empty' and usbcard == 'empty':
172
151
                        #get_print_card_info()
173
152
                        #sys.exit(1)
174
153
        
 
154
        def get_lists(self,pci,usb):
 
155
                pcilist = usblist = None
 
156
                
 
157
                # Try getting info from server
 
158
                if opts.repo == 'auto' or opts.repo == 'remote':
 
159
                        try:
 
160
                                pcilist = self.serverquery(pci)
 
161
                                usblist = self.serverquery(usb)
 
162
                        except ConnectionFailed:
 
163
                                logger.error('Failed to connect to server')
 
164
                                if opts.repo == 'auto':
 
165
                                        logger.error('Trying local database')
 
166
                
 
167
                # If we have nothing, either fail or try the local reposotory
 
168
                if pcilist == None and usblist == None:
 
169
                        if opts.repo == 'remote':
 
170
                                raise ConnectionFailed('Unable to establish connection. Please either check your interent connection or download the local database from FIXME...')
 
171
                
 
172
                
 
173
                        pcilist = self.localquery(pci)
 
174
                        usblist = self.localquery(usb)
 
175
                
 
176
                return pcilist, usblist
 
177
        
 
178
        
175
179
        def process_pciids(self, output):
176
180
                logger.debug('Starting process_pciids')
177
181
                output = output.split("\n")
183
187
                                try:
184
188
                                        pciid = i[5]
185
189
                                except:
186
 
                                        pass
 
190
                                        pciid = None
187
191
                        else:
188
192
                                try:
189
193
                                        pciid = i[2]
190
194
                                except:
191
 
                                        pass
 
195
                                        pciid = None
192
196
                                try:
193
197
                                        rev = i[4][:2]
194
198
                                except:
209
213
                
210
214
                logger.debug('Done serverquery')
211
215
 
212
 
        def localquery(self, devices_list,database):
 
216
        def localquery(self, devices_list, database):
213
217
                '''Looks if one of the ids in the devices list given as argument matches an entry in the database'''
214
218
                
215
219
                logger.debug('Starting localquery')
 
220
                matches = None
 
221
                f = open(database)
 
222
                for line in f:
 
223
                        line = line.split(';;;')
 
224
                        for pci in devices_list:
 
225
                                if line[0].strip() == pci[0]:
 
226
                                        if line[1].strip() == pci[1]:
 
227
                                                try:
 
228
                                                        matches.insert(0,line)
 
229
                                                except:
 
230
                                                        matches = [line]
 
231
                                        else:
 
232
                                                try:
 
233
                                                        matches.append(line)
 
234
                                                except:
 
235
                                                        matches = [line]
 
236
                                                        
 
237
                f.close()
 
238
                logger.debug('Done localquery')
 
239
                return matches
216
240
 
217
241
        def selectdatabase(self, selection = None):
218
242
                #find database file:
225
249
 
226
250
                databases = []
227
251
                
 
252
                for i in inprogramdir:
 
253
                        if 'database' in i:
 
254
                                if i == 'database':
 
255
                                        databases.insert(0,os.path.split(os.path.abspath(sys.argv[0]))[0] + '/' + i)
 
256
                                else:
 
257
                                        databases.append(os.path.split(os.path.abspath(sys.argv[0]))[0] + '/' + i)
 
258
                
228
259
                for i in incwd:
229
260
                        if 'database' in i:
230
 
                                databases.append(os.getcwd() + '/' + i)
231
 
                
232
 
                for i in inprogramdir:
233
 
                        if 'database' in i:
234
 
                                databases.append(os.path.split(os.path.abspath(sys.argv[0]))[0] + '/' + i)
 
261
                                if i == 'database':
 
262
                                        databases.insert(0,os.getcwd() + '/' + i)
 
263
                                else:
 
264
                                        databases.append(os.getcwd() + '/' + i)
235
265
                
236
266
                for i in intmpdir:
237
267
                        if 'database' in i:
238
 
                                databases.append(opts.tmp_dir + '/' + i)
 
268
                                if i == 'database':
 
269
                                        databases.insert(0,opts.tmp_dir + '/' + i)
 
270
                                else:
 
271
                                        databases.append(opts.tmp_dir + '/' + i)
239
272
                
240
273
                if len(databases) == 0:
241
274
                        raise DatabaseNotFound('No database found anywhere')
242
275
                
243
 
                if selection != None:
244
 
                        return databases[selection]
245
 
                        
246
276
                if len(databases) > 1:
247
277
                        return databases
248
278
                
310
340
                else:
311
341
                        print '[*] Internet connection found, continuing installation'
312
342
        
313
 
        
314
343
        def remove_old_drivers(self):
315
344
                '''Removes existing wireless drivers.'''
316
345
                print '[*] Removing Old Drivers:'
652
681
        logger.addHandler(ch)
653
682
        return logger
654
683
        
 
684
def grab_lists(pci,usb):
 
685
        pcilist = usblist = None
 
686
        
 
687
        # Try getting info from server
 
688
        if opts.repo == 'auto' or opts.repo == 'remote':
 
689
                try:
 
690
                        pcilist = main.serverquery(pci)
 
691
                        usblist = main.serverquery(usb)
 
692
                except ConnectionFailed:
 
693
                        logger.error('Failed to connect to server')
 
694
                        if opts.repo == 'auto':
 
695
                                logger.error('Trying local database')
 
696
        
 
697
        # If we have nothing, either fail or try the local reposotory
 
698
        if pcilist == None and usblist == None:
 
699
                if opts.repo == 'remote':
 
700
                        logger.error('Unable to establish connection. Please either check your interent connection or download the local database from FIXME...')
 
701
                        sys.exit(1)
 
702
        
 
703
                database = None
 
704
                selection = None
 
705
                try:
 
706
                        database = main.selectdatabase(selection)
 
707
                except DatabaseNotFound:
 
708
                        logger.error('No database found for local query. Please place a database file in either the current directory, the auto-ndis file directory or in ' + opts.tmp_dir)
 
709
                        sys.exit(1)
 
710
                if type(database) == type([]):
 
711
                        print 'Found these databases:'
 
712
                        for i,file in enumerate(database):
 
713
                                print '   [%s]  %s' % (i+1,file)
 
714
                        while True:
 
715
                                try:
 
716
                                        selection = input('Please enter the number of the database to use\n')
 
717
                                except Exception:
 
718
                                        selection = None
 
719
                                if type(selection) == type(1) and selection <= len(database):
 
720
                                        database = database[(selection-1)]
 
721
                                        break
 
722
                
 
723
                pcilist = main.localquery(pci,database)
 
724
                usblist = main.localquery(usb,database)
 
725
                
 
726
        print pcilist
 
727
        print usblist
 
728
        return pcilist,usblist  
655
729
 
656
730
if __name__ == '__main__':
657
731
        print 'Welcome to auto-ndiswrapper %s' % (__version__, )
681
755
                logger.error('Error occured, exiting')
682
756
                sys.exit(1)
683
757
        
684
 
        main.get_card_id()
685
 
        
 
758
        pci, usb = main.get_card_id()
 
759
        
 
760
        pcilist,usblist=grab_lists(pci,usb)
 
761
        
 
762
                
686
763
        print 'DONE'
687
764
        sys.exit(0)
 
 
b'\\ No newline at end of file'