Subversion Repositories programming

Rev

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

Rev 277 Rev 278
Line 56... Line 56...
56
# - Fixed the rar command so that it can extract files whose names begin
56
# - Fixed the rar command so that it can extract files whose names begin
57
#   with a hyphen.
57
#   with a hyphen.
58
#
58
#
59
# - 2006-03-08
59
# - 2006-03-08
60
# - Make an interactive mode which asks the user before deleting files.
60
# - Make an interactive mode which asks the user before deleting files.
-
 
61
# - Make multi-file parjoin work.
61
#
62
#
62
 
63
 
63
################################################################################
64
################################################################################
64
# REQUIREMENTS:
65
# REQUIREMENTS:
65
#
66
#
Line 447... Line 448...
447
 
448
 
448
            if retval == False:
449
            if retval == False:
449
                # Failed to verify fast, so try it slow, maybe it needs repair
450
                # Failed to verify fast, so try it slow, maybe it needs repair
450
                retval = self.__slow_verify()
451
                retval = self.__slow_verify()
451
 
452
 
452
        # If we've got a video file, maybe we should try to parjoin it
453
        # If we've got video files, maybe we should try to parjoin them
453
        elif self.__has_video_file():
454
        elif self.__number_of_video_files() > 0:
454
            retval = self.__parjoin()
455
            retval = self.__parjoin()
455
 
456
 
456
        else: #not all there, maybe we can slow-repair
457
        else: #not all there, maybe we can slow-repair
457
            retval = self.__slow_verify()
458
            retval = self.__slow_verify()
458
 
459
 
Line 474... Line 475...
474
            return True #success
475
            return True #success
475
 
476
 
476
        return False #failure
477
        return False #failure
477
 
478
 
478
    def __parjoin(self):
479
    def __parjoin(self):
479
        retval = os.system('lxsplit -j "%s.001"' % (self.files[0], ))
-
 
480
 
480
 
-
 
481
        # Join all of the files
-
 
482
        for f in self.files:
-
 
483
            if self.__is_video_file(f):
-
 
484
                self.__parjoin_single(f)
-
 
485
 
-
 
486
        # Re-verify the parset
481
        retval = self.__fast_verify()
487
        retval = self.__fast_verify()
482
 
488
 
483
        if retval == False:
489
        if retval == False:
484
            # Failed to verify fast, so try it slow, maybe it needs repair
490
            # Failed to verify fast, so try it slow, maybe it needs repair
485
            retval = self.__slow_verify()
491
            retval = self.__slow_verify()
486
 
492
 
487
        if retval == False: # failed to verify, so remove the lxsplit created file
493
        # Failed to verify, so remove all of the lxsplit created files
-
 
494
        if retval == False:
-
 
495
            for f in self.files:
-
 
496
                if self.__is_video_file(f):
488
            try:
497
                    try:
489
                os.remove(self.files[0])
498
                        os.remove(f)
490
            except OSError:
499
                    except OSError:
491
                print 'Failed to remove file: %s' % (self.files[0], )
500
                        print 'Failed to remove file: %s' % (f, )
492
 
501
 
493
        self.used_parjoin = retval
502
        self.used_parjoin = retval
494
        self.verified = retval
503
        self.verified = retval
495
        return self.verified
504
        return self.verified
496
 
505
 
-
 
506
    def __parjoin_single(self, base_file):
-
 
507
 
-
 
508
        parjoinable = False
-
 
509
        regex = re.compile("^%s\.001$" % (re.escape(base_file), ), re.IGNORECASE)
-
 
510
 
-
 
511
        for f in os.listdir(os.getcwd()):
-
 
512
            if regex.match(f):
-
 
513
                parjoinable = True
-
 
514
                break
-
 
515
 
-
 
516
        if parjoinable:
-
 
517
            retval = os.system('lxsplit -j "%s.001"' % (base_file, ))
-
 
518
            return retval
-
 
519
 
-
 
520
        return False
-
 
521
 
497
    def __has_video_file(self):
522
    def __is_video_file(self, file):
-
 
523
 
498
        regex = re.compile(
524
        regex = re.compile(
499
                config.get_value('regular expressions', 'video_file_regex'),
525
                config.get_value('regular expressions', 'video_file_regex'),
500
                re.IGNORECASE)
526
                re.IGNORECASE)
501
 
527
 
502
        for f in self.files:
-
 
503
            if regex.match(f):
528
        if regex.match(file):
504
                return True
529
            return True
505
 
530
 
506
        return False
531
        return False
507
 
532
 
-
 
533
    def __number_of_video_files(self):
-
 
534
 
-
 
535
        count = 0
-
 
536
 
-
 
537
        for f in self.files:
-
 
538
            if self.__is_video_file(f):
-
 
539
                count += 1
-
 
540
 
-
 
541
        return count
-
 
542
 
-
 
543
    def __remove_split_files(self, base_name, files_to_remove):
-
 
544
        """Store base_name.{001,002, ... , 999} files in the list
-
 
545
        $files_to_remove"""
-
 
546
 
-
 
547
        base_name_regex = "^%s\.\d\d\d$" % (re.escape(base_name), )
-
 
548
 
-
 
549
        regex = re.compile(base_name_regex, re.IGNORECASE)
-
 
550
 
-
 
551
        for f in os.listdir(os.getcwd()):
-
 
552
            if regex.match(f):
-
 
553
                files_to_remove.append(f)
-
 
554
 
508
    def __remove_currentset(self):
555
    def __remove_currentset(self):
509
        """Remove all of the files that are extractable, as well as the pars.
556
        """Remove all of the files that are extractable, as well as the pars.
510
        Leave everything else alone"""
557
        Leave everything else alone"""
511
 
558
 
512
        if not self.extracted:
559
        if not self.extracted:
Line 532... Line 579...
532
            if regex.match(i):
579
            if regex.match(i):
533
                files_to_remove.append(i)
580
                files_to_remove.append(i)
534
 
581
 
535
        # remove any .{001,002,...} files (from parjoin)
582
        # remove any .{001,002,...} files (from parjoin)
536
        if self.used_parjoin:
583
        if self.used_parjoin:
537
            for i in os.listdir(os.getcwd()):
584
            for f in self.files:
538
                if i != self.files[0] and self.files[0] in i:
585
                self.__remove_split_files(f, files_to_remove)
539
                    files_to_remove.append(i)
-
 
540
 
586
 
541
        # remove any temp repair files
587
        # remove any temp repair files
542
        regex = re.compile(
588
        regex = re.compile(
543
                config.get_value('regular expressions', 'temp_repair_regex'),
589
                config.get_value('regular expressions', 'temp_repair_regex'),
544
                re.IGNORECASE)
590
                re.IGNORECASE)