Пример #1
0
 def performRename(self, afrom, ato):
     result = False
     try:
         result = cellrename_engine.renameFiles(self.data.directory, afrom, ato)
     except Exception:
         wxutil.alertDialog(self, 'Exception occurred: '+str(sys.exc_info()[0]))
         return
     
     if result != True:
         wxutil.alertDialog(self, str(result))
         self.writeStatus("")
         return
     
     self.undo_history = self.data.directory, afrom, ato
     self.menuobj_undo.Enable(True)
     self.onMenuFileRefresh()
     self.writeStatus( str(self.data.getLength())+' files renamed.')
Пример #2
0
    def performRename(self, afrom, ato):
        result = False
        try:
            result = cellrename_engine.renameFiles(self.data.directory, afrom,
                                                   ato)
        except Exception:
            wxutil.alertDialog(self,
                               'Exception occurred: ' + str(sys.exc_info()[0]))
            return

        if result != True:
            wxutil.alertDialog(self, str(result))
            self.writeStatus("")
            return

        self.undo_history = self.data.directory, afrom, ato
        self.menuobj_undo.Enable(True)
        self.onMenuFileRefresh()
        self.writeStatus(str(self.data.getLength()) + ' files renamed.')
def engineunittest():
    from cellrename_engine import renameFiles, marker
    names = unittestsetup()

    # test same names
    expectEqual(renameFiles(dir, [names[1], names[2]], [names[1], names[2]]),
                True)

    # test name swap
    fout = open(join(dir, names[1]), 'w')
    fout.write('testswap')
    fout.close()
    expectEqual(renameFiles(dir, [names[1], names[2]], [names[2], names[1]]),
                True)
    fout = open(join(dir, names[2]), 'r')
    txt = fout.read()
    fout.close()
    assert 'testswap' in txt

    # test simple prefix
    namestochange = [names[3], names[4], names[5], names[6]]
    expectEqual(
        renameFiles(dir, namestochange,
                    ['pref' + name for name in namestochange]), True)
    for name in namestochange:
        assert exists(join(dir, 'pref' + name))
    expectEqual(
        renameFiles(dir, ['pref' + name for name in namestochange],
                    namestochange), True)
    for name in namestochange:
        assert not exists(join(dir, 'pref' + name))

    # expect failure, different lengths
    expectStringContains(renameFiles(dir, ['a', 'b', 'c'], ['a', 'b']),
                         'Lengths')
    # expect failure, marker
    expectStringContains(
        renameFiles(dir, [names[0], names[1]], [names[0], names[1] + marker]),
        'its name')
    expectStringContains(
        renameFiles(dir, [names[0], names[1] + marker], [names[0], names[1]]),
        'its name')
    # expect failure, bad filenames
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', '']),
        'invalid filename')
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', 'ok:one']),
        'invalid filename')
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', 'some/other']),
        'invalid filename')
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', 'some\\other']),
        'invalid filename')
    # expect failure, duplicates
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', 'a']), 'Duplicate')
    expectStringContains(
        renameFiles(dir, ['6', '7', '8', '9'], ['y', 'x', 'z', 'x']),
        'Duplicate')
    if os.name == 'nt':
        expectStringContains(
            renameFiles(dir, ['6', '7', '8', '9'], ['y', 'X', 'z', 'x']),
            'Duplicate')

    # expect failure, file exists
    expectStringContains(
        renameFiles(dir, [names[0], names[1]], [names[0], names[8]]), 'exists')
    os.mkdir(join(dir, 'existdir'))
    expectStringContains(
        renameFiles(dir, [names[0], names[1]], ['existdir', names[1]]),
        'exists')
    expectEqual(renameFiles(dir, ['existdir'], ['existdirrenamed']), True)
    os.rmdir(join(dir, 'existdirrenamed'))
    if os.name == 'nt':
        assert names[8].upper() != names[8]
        expectStringContains(
            renameFiles(dir, [names[0], names[1]],
                        [names[0], names[8].upper()]), 'exists')

    # expect failure, cannot access
    expectStringContains(
        renameFiles(dir, ['notexist1', 'notexist2'], ['a', 'b']),
        'longer exists')
    expectStringContains(
        renameFiles(dir, [names[0], 'notexist1', 'notexist2'],
                    [names[0], 'a', 'b']), 'longer exists')
    if os.name == 'nt':
        # expectStringContains( renameFiles('c:\\windows',['DirectX.log'], ['DirectX2.log']), 'could not be')
        expectStringContains(renameFiles('c:\\', ['Windows'], ['Windows2']),
                             'could not be')
Пример #4
0
def engineunittest():
    from cellrename_engine import renameFiles, marker
    names = unittestsetup()
    
    # test same names
    expectEqual( renameFiles(dir,[names[1],names[2]], [names[1],names[2]]), True)
    
    # test name swap
    fout=open(join(dir,names[1]),'w'); fout.write('testswap'); fout.close()
    expectEqual( renameFiles(dir,[names[1],names[2]], [names[2],names[1]]), True)
    fout=open(join(dir,names[2]),'r'); txt=fout.read(); fout.close()
    assert 'testswap' in txt
    
    # test simple prefix
    namestochange = [names[3],names[4],names[5],names[6]]
    expectEqual( renameFiles(dir,namestochange, ['pref'+name for name in namestochange]), True)
    for name in namestochange: assert exists(join(dir, 'pref'+name))
    expectEqual( renameFiles(dir, ['pref'+name for name in namestochange], namestochange), True)
    for name in namestochange: assert not exists(join(dir, 'pref'+name))
    
    # expect failure, different lengths
    expectStringContains( renameFiles(dir,['a','b','c'], ['a','b']), 'Lengths')
    # expect failure, marker
    expectStringContains( renameFiles(dir,[names[0],names[1]], [names[0],names[1]+marker]), 'its name')
    expectStringContains( renameFiles(dir,[names[0],names[1]+marker], [names[0],names[1]]), 'its name')
    # expect failure, bad filenames
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','']), 'invalid filename')
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','ok:one']), 'invalid filename')
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','some/other']), 'invalid filename')
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','some\\other']), 'invalid filename')
    # expect failure, duplicates
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','a']), 'Duplicate')
    expectStringContains( renameFiles(dir,['6','7','8','9'], ['y','x','z','x']), 'Duplicate')
    if os.name=='nt':
        expectStringContains( renameFiles(dir,['6','7','8','9'], ['y','X','z','x']), 'Duplicate')
    
    # expect failure, file exists
    expectStringContains( renameFiles(dir,[names[0],names[1]], [names[0],names[8]]), 'exists')
    os.mkdir(join(dir,'existdir'))
    expectStringContains( renameFiles(dir,[names[0],names[1]], ['existdir',names[1]]), 'exists')
    expectEqual( renameFiles(dir,['existdir'], ['existdirrenamed']), True)
    os.rmdir(join(dir,'existdirrenamed'))
    if os.name=='nt':
        assert names[8].upper()!=names[8]
        expectStringContains( renameFiles(dir,[names[0],names[1]], [names[0],names[8].upper()]), 'exists')
        
    # expect failure, cannot access
    expectStringContains( renameFiles(dir,['notexist1','notexist2'], ['a','b']), 'longer exists')
    expectStringContains( renameFiles(dir,[names[0],'notexist1','notexist2'], [names[0],'a','b']), 'longer exists')
    if os.name=='nt':
        # expectStringContains( renameFiles('c:\\windows',['DirectX.log'], ['DirectX2.log']), 'could not be')
        expectStringContains( renameFiles('c:\\',['Windows'], ['Windows2']), 'could not be')