Ejemplo n.º 1
0
 def do_move(self):
     ind=self.lb.current()
     src=self.all[ind][0]
     if src.lower().startswith('z:'):
         return self.do_copy()
     base=os.path.basename(src)
     if src.endswith(':') or not os.path.exists(src):
         return 1
     path=os.path.dirname(src)
     if path.endswith('\\'):
         path=path[:-1]
     ui.note(u'select destination')
     running=1
     while running:
         self.lb.set_list([(u'please wait...', self.wait_icon)])
         #e32.ao_yield()
         dst=useFman().AskUser(path, base, type='folder')
         if dst==None:
             return self.run(path, base)
         if dst.lower().startswith('z:'):
             ui.note(u'ACCESS DENIED', 'error')
             return self.run(path, base)
         try:
             sh.move(src, dst)
             ui.note(u'successful', 'conf')
         except IOError:
             fd=dst+'\\'+os.path.basename(src)
             if os.path.isfile(fd):
                 os.chmod(fd, ~0)
                 os.remove(fd)
             ui.note(u'cant move', 'error')
             return self.run(path, base)
         except:
             if ui.query(u'Already exists! Sure to replace existing and Read-Only files?', 'query'):
                 if self.__pwrmov(src, dst):
                     ui.note(u'successful', 'conf')
                 else:
                     ui.note(u'cant move', 'error')
                     return self.run(path, base)
         if ind==0:
             new=os.path.basename(self.all[ind][0])
         else:
             new=os.path.basename(self.all[ind-1][0])
         return self.run(path, new)
Ejemplo n.º 2
0
    def _rename_item(self, i, original, renamed, refresh_int):
        """
        Renaming operation, with recursive error handling.

        Returns False on success.
        """
        try:
            shutil1.move(original[0], renamed[0], True)
        except IOError as (errNumb, err):
            app.debug_print("IOError : %s, %s" % (errNumb, err))
            # may need to create dirs first
            if errNumb == 2 and not os.path.exists(os.path.dirname(renamed[0])):
                try:
                    os.makedirs(os.path.dirname(renamed[0]))
                except OSError as (n, err):
                    self._show_rename_error(i, err, original, renamed)
                    return 'makedirs'
                else:
                    return self._rename_item(i, original, renamed, refresh_int)
Ejemplo n.º 3
0
 def __pwrmov(src, dst):
     try:
         try:
             os.chmod(src, ~0)
             sh.move(src, dst)
             return 1
         except IOError:
             fd = dst + "\\" + os.path.basename(src)
             if os.path.isfile(fd):
                 os.chmod(fd, ~0)
                 os.remove(fd)
             return 0
         except sh.Error:
             os.chmod(src, ~0)
             if os.path.isfile(src):
                 os.chmod(dst + "\\" + os.path.basename(src), ~0)
                 os.remove(dst + "\\" + os.path.basename(src))
                 sh.move(src, dst)
                 return 1
             li = os.listdir(src)
             if not li:
                 os.chmod(src, ~0)
                 os.rmdir(src)
                 return 1
             for i in li:
                 a = src + "\\" + i
                 b = dst + "\\" + os.path.basename(src)
                 os.chmod(a, ~0)
                 if not os.path.exists(b + "\\" + i):
                     sh.move(a, b)
                 else:
                     __pwrmov(a, b)
             try:
                 os.chmod(src, ~0)
                 os.rmdir(src)
             except:
                 raise
             return 1
         except:
             return 0
     except IOError:
         f = b + "\\" + os.path.basename(a)
         if os.path.isfile(f):
             os.chmod(f, ~0)
             os.remove(f)
         return 0
     except:
         return 0