Пример #1
0
    def move(self, forceNsp=False):
        if not self.path:
            Print.error('no path set')
            return False

        if os.path.abspath(self.path).startswith(
                os.path.abspath(Config.paths.nspOut)
        ) and not self.path.endswith('.nsz') and not self.path.endswith(
                '.xcz') and Config.compression.auto:
            nszFile = nut.compress(self.path, Config.compression.level,
                                   os.path.abspath(Config.paths.nspOut))

            if nszFile:
                nsp = Nsps.registerFile(nszFile)
                nsp.hasValidTicket = True
                nsp.move(forceNsp=True)

        newPath = self.fileName(forceNsp=forceNsp)

        if not newPath:
            Print.error('could not get filename for ' + self.path)
            return False

        newPath = os.path.abspath(newPath)

        if newPath.lower().replace('\\', '/') == self.path.lower().replace(
                '\\', '/'):
            return False

        if os.path.isfile(newPath):
            Print.info('\nduplicate title: ')
            Print.info(os.path.abspath(self.path))
            Print.info(newPath)
            Print.info('\n')
            return False

        if self.isOpen():
            if not self.verifyNcaHeaders():
                Print.error('verification failed: could not move title for ' +
                            str(self.titleId) + ' or ' +
                            str(Title.getBaseId(self.titleId)))
                return False
        else:
            try:
                self.open(self.path)
                if not self.verifyNcaHeaders():
                    Print.error(
                        'verification failed: could not move title for ' +
                        str(self.titleId) + ' or ' +
                        str(Title.getBaseId(self.titleId)))
                    return False
            finally:
                self.close()

        try:
            Print.info(self.path + ' -> ' + newPath)

            if not Config.dryRun:
                os.makedirs(os.path.dirname(newPath), exist_ok=True)
            #newPath = self.fileName(forceNsp = forceNsp)

            if not Config.dryRun:
                if self.isOpen():
                    self.close()
                shutil.move(self.path, newPath)
                Nsps.moveFile(self.path, newPath)
                #Nsps.files[newPath] = self
                self.path = newPath
        except BaseException as e:
            Print.error('failed to rename file! %s -> %s  : %s' %
                        (self.path, newPath, e))
            if not Config.dryRun:
                self.moveDupe()

        return True
Пример #2
0
 def on_moved(self, event):
     print('moved: %s -> %s' % (event.src_path, event.dest_path))
     Nsps.moveFile(event.src_path, event.dest_path)