예제 #1
0
 def run(self):
     if xbmcvfs.exists(self.dst):
         xbmcvfs.delete(self.dst)
     xbmcvfs.mkdirs(os.path.dirname(self.dst))
     log.info("Copying %s to %s...", self.src, self.dst)
     xbmcvfs.delete(self.tmp)
     if xbmcvfs.copy(self.src, self.tmp):
         log.info("Success.")
         self.copied = True
         if xbmcvfs.rename(self.tmp, self.dst):
             if self.delete and xbmcvfs.delete(self.src):
                 log.info("File %s deleted.", self.src)
         else:
             log.info("Renaming %s to %s failed.", self.tmp, self.dst)
             xbmcvfs.delete(self.tmp)
     else:
         log.info("Failed")
예제 #2
0
 def run(self):
     if xbmcvfs.exists(self.dst):
         xbmcvfs.delete(self.dst)
     xbmcvfs.mkdirs(os.path.dirname(self.dst))
     log.info("Copying %s to %s...", self.src, self.dst)
     xbmcvfs.delete(self.tmp)
     if xbmcvfs.copy(self.src, self.tmp):
         log.info("Success.")
         self.copied = True
         if xbmcvfs.rename(self.tmp, self.dst):
             if self.delete and xbmcvfs.delete(self.src):
                 log.info("File %s deleted.", self.src)
         else:
             log.info("Renaming %s to %s failed.", self.tmp, self.dst)
             xbmcvfs.delete(self.tmp)
     else:
         log.info("Failed")
예제 #3
0
def save_files(files, rename=False, on_finish=None):
    save = plugin.get_setting('save-files', int)
    if not save:
        on_finish()
        return
    src, dst = temp_path(), save_path()
    files_dict = {}
    for old_path in files:
        old_path = ensure_unicode(old_path)
        rel_path = os.path.relpath(old_path, src)
        new_path = os.path.join(dst, rel_path)
        if xbmcvfs.exists(new_path):
            if rename:
                if xbmcvfs.delete(old_path):
                    log.info("File %s deleted.", old_path)
            continue
        files_dict[old_path] = new_path
    if not files_dict:
        if on_finish:
            on_finish()
        return
    files_to_copy = {}
    if save != 2 or xbmcgui.Dialog().yesno(lang(30000),
                                           *lang(40162).split("|")):
        for n, old_path in enumerate(files):
            old_path = ensure_unicode(old_path)
            if old_path not in files_dict:
                continue
            new_path = files_dict[old_path]
            xbmcvfs.mkdirs(os.path.dirname(new_path))
            if rename:
                log.info("Renaming %s to %s...", old_path, new_path)
                if not xbmcvfs.rename(old_path, new_path):
                    log.info(
                        "Renaming failed. Trying to copy and delete old file..."
                    )
                    files_to_copy[old_path] = new_path
                else:
                    log.info("Success.")
            else:
                files_to_copy[old_path] = new_path
    if files_to_copy:
        copy_files(files_to_copy, delete=rename, on_finish=on_finish)
    elif on_finish:
        on_finish()
예제 #4
0
def save_files(files, rename=False, on_finish=None):
    save = plugin.get_setting('save-files', int)
    if not save:
        on_finish()
        return
    src, dst = temp_path(), save_path()
    files_dict = {}
    for old_path in files:
        old_path = ensure_unicode(old_path)
        rel_path = os.path.relpath(old_path, src)
        new_path = os.path.join(dst, rel_path)
        if xbmcvfs.exists(new_path):
            if rename:
                if xbmcvfs.delete(old_path):
                    log.info("File %s deleted.", old_path)
            continue
        files_dict[old_path] = new_path
    if not files_dict:
        if on_finish:
            on_finish()
        return
    files_to_copy = {}
    if save != 2 or xbmcgui.Dialog().yesno(lang(30000), *lang(40162).split("|")):
        for n, old_path in enumerate(files):
            old_path = ensure_unicode(old_path)
            if old_path not in files_dict:
                continue
            new_path = files_dict[old_path]
            xbmcvfs.mkdirs(os.path.dirname(new_path))
            if rename:
                log.info("Renaming %s to %s...", old_path, new_path)
                if not xbmcvfs.rename(old_path, new_path):
                    log.info("Renaming failed. Trying to copy and delete old file...")
                    files_to_copy[old_path] = new_path
                else:
                    log.info("Success.")
            else:
                files_to_copy[old_path] = new_path
    if files_to_copy:
        copy_files(files_to_copy, delete=rename, on_finish=on_finish)
    elif on_finish:
        on_finish()