Esempio n. 1
0
 def test_simple(self, do_setup):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     assert app.rename_selected('renamed')
     names = io.listdir(self.p)
     assert 'renamed' in names
     assert 'foo bar 2' not in names
     eq_(g.dupes[0].name, 'renamed')
Esempio n. 2
0
 def test_simple(self, do_setup):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     assert app.rename_selected('renamed')
     names = io.listdir(self.p)
     assert 'renamed' in names
     assert 'foo bar 2' not in names
     eq_(g.dupes[0].name, 'renamed')
Esempio n. 3
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('foo bar 1')
     msg = logging.warning.calls[0]['msg']
     assert msg.startswith('dupeGuru Warning: \'foo bar 1\' already exists in')
     names = io.listdir(self.p)
     assert 'foo bar 1' in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Esempio n. 4
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('renamed')
     msg = logging.warning.calls[0]['msg']
     eq_('dupeGuru Warning: list index out of range', msg)
     names = io.listdir(self.p)
     assert 'renamed' not in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Esempio n. 5
0
 def test_name_already_exists(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([1])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('foo bar 1')
     msg = logging.warning.calls[0]['msg']
     assert msg.startswith('dupeGuru Warning: \'foo bar 1\' already exists in')
     names = io.listdir(self.p)
     assert 'foo bar 1' in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Esempio n. 6
0
 def test_none_selected(self, do_setup, monkeypatch):
     app = self.app
     g = self.groups[0]
     self.rtable.select([])
     monkeypatch.setattr(logging, 'warning', log_calls(lambda msg: None))
     assert not app.rename_selected('renamed')
     msg = logging.warning.calls[0]['msg']
     eq_('dupeGuru Warning: list index out of range', msg)
     names = io.listdir(self.p)
     assert 'renamed' not in names
     assert 'foo bar 2' in names
     eq_(g.dupes[0].name, 'foo bar 2')
Esempio n. 7
0
def clean_empty_dirs(path, deleteself=False, files_to_delete=[]):
    """Recursively delete empty dirs in directory. 'directory' is deleted only
    if empty and 'deleteself' is True.
    Returns the list of delete paths.
    files_to_delete: The name is clear enough. However, files in
        this list will ONLY be deleted if it makes the directory deletable
        thereafter (In other words, if the directory contains files not in the
        list, NO file will be deleted)
    """
    result = []
    subdirs = [name for name in io.listdir(path) if io.isdir(path + name)]
    for subdir in subdirs:
        result.extend(clean_empty_dirs(path + subdir, True, files_to_delete))
    if deleteself and delete_if_empty(path, files_to_delete):
        result.append(str(path))
    return result
Esempio n. 8
0
def clean_empty_dirs(path, deleteself=False, files_to_delete=[]):
    """Recursively delete empty dirs in directory. 'directory' is deleted only
    if empty and 'deleteself' is True.
    Returns the list of delete paths.
    files_to_delete: The name is clear enough. However, files in
        this list will ONLY be deleted if it makes the directory deletable
        thereafter (In other words, if the directory contains files not in the
        list, NO file will be deleted)
    """
    result = []
    subdirs = [name for name in io.listdir(path) if io.isdir(path + name)]
    for subdir in subdirs:
        result.extend(clean_empty_dirs(path + subdir, True, files_to_delete))
    if deleteself and delete_if_empty(path, files_to_delete):
        result.append(str(path))
    return result
Esempio n. 9
0
 def _fetch_subitems(self):
     try:
         items = io.listdir(self.path)
         bogus_names = [name for name in items if not isinstance(name, str)]
         if bogus_names:
             logging.warning("Encountered files with the wrong encoding: %r", bogus_names)
             items = (name for name in items if isinstance(name, str))                
         items = (name for name in items if not io.islink(self.path + name))
         subdirs = []
         subfiles = []
         for name in items:
             if io.isdir(self.path + name):
                 subdirs.append(name)
             else:
                 subfiles.append(name)
         return (subdirs, subfiles)
     except OSError:
         if self.parent is not None:
             return ([], [])
         else:
             raise fs.InvalidPath(self)