Пример #1
0
 def _rename( self, options ):
     self.filename, ext = os.path.splitext( self._make_filename( options ) )
     if self.file.filename != self.filename + ext:
         new_dirname = os.path.dirname( self.filename )
         if not os.path.isdir( utils.encode_filename( new_dirname ) ):
             os.makedirs( new_dirname )
         tmp_filename = self.filename
         i = 1
         while ( not utils.pathcmp( self.file.filename, self.filename + ext ) and os.path.exists( utils.encode_filename( self.filename + ext ) ) ):
             self.filename = u"{} ({})".format( tmp_filename, i )
             i += 1
         self.filename = self.filename + ext
         common = os.path.commonprefix( list( ( os.path.dirname( self.file.filename ), os.path.dirname( self.filename ) ) ) )
         utils.safeprint( u"{} -> {}".format( os.path.relpath( self.file.filename, common ), os.path.relpath( self.filename, common ) ) )
         shutil.move( utils.encode_filename( self.file.filename ), utils.encode_filename( self.filename ) )
         return self.filename
     else:
         return self.file.filename
Пример #2
0
 def _handle_filesystem_options( self, options ):
     """Save the metadata."""
     self.filename = self.file.filename
     # Rename files
     if options["rename_files"] or options["move_files"]:
         self.filename = self._rename( options )
     # Delete empty directories
     if options["delete_empty_dirs"]:
         dirname = utils.encode_filename( os.path.dirname( self.file.filename ) )
         try:
             self._rmdir( dirname )
             head, tail = os.path.split( dirname )
             if not tail:
                 head, tail = os.path.split( head )
             while head and tail:
                 try:
                     self._rmdir( head )
                 except:
                     break
                 head, tail = os.path.split( head )
         except EnvironmentError:
             pass
     return self.filename