Subversion Repositories programming

Rev

Rev 150 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 150 Rev 152
Line 48... Line 48...
48
# - 2005-10-30
48
# - 2005-10-30
49
# - Added the '-o' option, to output debugging info. Hopefully next time
49
# - Added the '-o' option, to output debugging info. Hopefully next time
50
#   someone finds a bug, they can output this and send it to me with a
50
#   someone finds a bug, they can output this and send it to me with a
51
#   description of the bug they're seeing.
51
#   description of the bug they're seeing.
52
#
52
#
-
 
53
# - 2005-11-05
-
 
54
# - Added an output system to rarslave. This makes a nice status report
-
 
55
#   possible at the end of the program run.
-
 
56
#
53
 
57
 
54
################################################################################
58
################################################################################
55
# REQUIREMENTS:
59
# REQUIREMENTS:
56
#
60
#
57
# This code requires the programs cfv, par2repair, lxsplit, and rar to be able
61
# This code requires the programs cfv, par2repair, lxsplit, and rar to be able
Line 173... Line 177...
173
 
177
 
174
# This is the global config variable.
178
# This is the global config variable.
175
config = rarslave_config()
179
config = rarslave_config()
176
 
180
 
177
################################################################################
181
################################################################################
-
 
182
# The rarslave_output class
-
 
183
#
-
 
184
# This class handles the nice output summary which is printed at the end
-
 
185
# of a run
-
 
186
################################################################################
-
 
187
 
-
 
188
class rarslave_output:
-
 
189
    # Data structure: list of lists
-
 
190
    # [ [status, filename], ... ]
-
 
191
    #
-
 
192
    # Where status is one of:
-
 
193
    # 0: Verified and Extracted Perfectly
-
 
194
    # 1: Failed to Verify (and therefore Extract)
-
 
195
    # 2: Verified correctly, but failed to Extract
-
 
196
    #
-
 
197
 
-
 
198
    def __init__(self):
-
 
199
        self.output_list    = []
-
 
200
        self.good_files     = 0
-
 
201
        self.unverified     = 0
-
 
202
        self.unextractable  = 0
-
 
203
        self.corrupt_par2   = 0
-
 
204
 
-
 
205
    def print_equal_line(self, size=80):
-
 
206
        """Print an 80 character line of equal signs"""
-
 
207
 
-
 
208
        str = ''
-
 
209
 
-
 
210
        for i in range(size):
-
 
211
            str += '='
-
 
212
 
-
 
213
        print str
-
 
214
 
-
 
215
    def print_results_table(self):
-
 
216
        """Print a nice table of the results from this run"""
-
 
217
 
-
 
218
        # Print the table of good files (if we have any)
-
 
219
        if self.good_files > 0:
-
 
220
            print
-
 
221
            self.print_equal_line()
-
 
222
            print 'Files that were extracted perfectly'
-
 
223
            self.print_equal_line()
-
 
224
 
-
 
225
            for entry in self.output_list:
-
 
226
                if entry[0] == 0:
-
 
227
                    print '%s' % (entry[1], )
-
 
228
 
-
 
229
        # Print the table of unverified files (if we have any)
-
 
230
        if self.unverified > 0:
-
 
231
            print
-
 
232
            self.print_equal_line()
-
 
233
            print 'Files that failed to verify (and extract)'
-
 
234
            self.print_equal_line()
-
 
235
 
-
 
236
            for entry in self.output_list:
-
 
237
                if entry[0] == 1:
-
 
238
                    print '%s' % (entry[1], )
-
 
239
 
-
 
240
        # Print the table of unextracted files (if we have any)
-
 
241
        if self.unextractable > 0:
-
 
242
            print
-
 
243
            self.print_equal_line()
-
 
244
            print 'Files that were verified, but failed to extract'
-
 
245
            self.print_equal_line()
-
 
246
 
-
 
247
            for entry in self.output_list:
-
 
248
                if entry[0] == 2:
-
 
249
                    print '%s' % (entry[1], )
-
 
250
 
-
 
251
        # Print the table of corrupt PAR2 files (if we have any)
-
 
252
        if self.corrupt_par2 > 0:
-
 
253
            print
-
 
254
            self.print_equal_line()
-
 
255
            print 'Files that had corrupt par2 files'
-
 
256
            self.print_equal_line()
-
 
257
 
-
 
258
            for entry in self.output_list:
-
 
259
                if entry[0] == 3:
-
 
260
                    print '%s' % (entry[1], )
-
 
261
 
-
 
262
        # Print a blank line at the end
-
 
263
        print
-
 
264
 
-
 
265
    def add_file(self, status, filename):
-
 
266
 
-
 
267
        if status == 0:
-
 
268
            self.good_files += 1
-
 
269
        elif status == 1:
-
 
270
            self.unverified += 1
-
 
271
        elif status == 2:
-
 
272
            self.unextractable += 1
-
 
273
        elif status == 3:
-
 
274
            self.corrupt_par2 += 1
-
 
275
        else:
-
 
276
            # We have a bad value, so raise a ValueError
-
 
277
            raise ValueError
-
 
278
 
-
 
279
        self.output_list.append([status, filename])
-
 
280
 
-
 
281
# This is the global output variable
-
 
282
output = rarslave_output()
-
 
283
 
-
 
284
################################################################################
178
# The PAR2 Parser
285
# The PAR2 Parser
179
#
286
#
180
# This was stolen from cfv (see http://cfv.sourceforge.net/ for a copy)
287
# This was stolen from cfv (see http://cfv.sourceforge.net/ for a copy)
181
################################################################################
288
################################################################################
182
 
289
 
Line 292... Line 399...
292
        print '========== DEBUG INFO STARTS HERE =========='
399
        print '========== DEBUG INFO STARTS HERE =========='
293
        print 'parfile: %s' % (self.parfile, )
400
        print 'parfile: %s' % (self.parfile, )
294
        print 'extra_pars: %s' % (self.extra_pars, )
401
        print 'extra_pars: %s' % (self.extra_pars, )
295
        print 'files: %s' % (self.files, )
402
        print 'files: %s' % (self.files, )
296
        print '========== DEBUG INFO ENDS HERE =========='
403
        print '========== DEBUG INFO ENDS HERE =========='
297
        
404
 
298
    def get_filenames(self):
405
    def get_filenames(self):
299
        return get_par2_filenames(parfile)
406
        return get_par2_filenames(self.parfile)
300
 
407
 
301
    def all_there(self):
408
    def all_there(self):
302
        """Check if all the files for the parset are present.
409
        """Check if all the files for the parset are present.
303
        This will help us decide which par2 checker to use first"""
410
        This will help us decide which par2 checker to use first"""
304
        for f in self.files:
411
        for f in self.files:
Line 425... Line 532...
425
 
532
 
426
    def extract(self):
533
    def extract(self):
427
        """Attempt to extract all of the files related to this parset"""
534
        """Attempt to extract all of the files related to this parset"""
428
        if not self.verified:
535
        if not self.verified:
429
            self.extracted = False
536
            self.extracted = False
430
            print 'Not (successfully) verified, not extracting'
537
            output.add_file(1, self.parfile)
431
            return False #failed to extract
538
            return False #failed to extract
432
 
539
 
433
        extract_file = self.__get_extract_file()
540
        extract_file = self.__get_extract_file()
434
 
541
 
435
        if extract_file != None:
542
        if extract_file != None:
Line 437... Line 544...
437
                retval = os.system('rar x -o+ "%s"' % (extract_file, ))
544
                retval = os.system('rar x -o+ "%s"' % (extract_file, ))
438
            else:
545
            else:
439
                retval = os.system('rar e -o+ "%s"' % (extract_file, ))
546
                retval = os.system('rar e -o+ "%s"' % (extract_file, ))
440
 
547
 
441
            if retval != 0:
548
            if retval != 0:
442
                print 'Failed to extract'
549
                output.add_file(2, self.parfile)
443
                self.extracted = False
550
                self.extracted = False
444
                return self.extracted
551
                return self.extracted
445
 
552
 
446
        # we extracted ok, so remove the currentset
553
        # we extracted ok, so remove the currentset
447
        self.extracted = True
554
        self.extracted = True
448
        self.__remove_currentset()
555
        self.__remove_currentset()
449
 
556
 
-
 
557
        output.add_file(0, self.parfile)
-
 
558
 
450
        return self.extracted
559
        return self.extracted
451
 
560
 
452
 
561
 
453
################################################################################
562
################################################################################
454
# The rarslave program itself
563
# The rarslave program itself
Line 495... Line 604...
495
    for i in par2files:
604
    for i in par2files:
496
        try:
605
        try:
497
            filenames = get_par2_filenames(i)
606
            filenames = get_par2_filenames(i)
498
            create_new = True
607
            create_new = True
499
        except EnvironmentError:
608
        except EnvironmentError:
500
            print 'CORRUPT PARFILE: %s' % (i, )
609
            output.add_file(3, i)
501
            continue
610
            continue
502
 
611
 
503
        # if we already have an instance for this set, append
612
        # if we already have an instance for this set, append
504
        # this par file to the extra_pars field
613
        # this par file to the extra_pars field
505
        for j in parsets:
614
        for j in parsets:
Line 529... Line 638...
529
        for p in parsets:
638
        for p in parsets:
530
            p.debug()
639
            p.debug()
531
 
640
 
532
    # No debug info
641
    # No debug info
533
    else:
642
    else:
534
    
643
 
535
        # Verify each parset
644
        # Verify each parset
536
        for p in parsets:
645
        for p in parsets:
537
            p.verify()
646
            p.verify()
538
 
647
 
539
        # Attempt to extract each parset
648
        # Attempt to extract each parset
Line 597... Line 706...
597
        for root, dirs, files in os.walk(options.work_dir):
706
        for root, dirs, files in os.walk(options.work_dir):
598
            directory_worker(root, options)
707
            directory_worker(root, options)
599
    else:
708
    else:
600
        directory_worker(options.work_dir, options)
709
        directory_worker(options.work_dir, options)
601
 
710
 
-
 
711
    # Print the results
-
 
712
    output.print_results_table()
-
 
713
 
602
if __name__ == '__main__':
714
if __name__ == '__main__':
603
    main()
715
    main()
604
 
716