Example #1
0
 def get_locations(self, inputstring):
     """ Get file path for other file operations """
     # Get source for comparison
     source = url2pathname(self.location).replace('file:///', '/')
     if inputstring == 'source':
         return source
     # Set Destination Directory
     targetdir = '/' + self.rbfo.configurator.get_val('layout-path')
     targetdir = tools.data_filler(self, targetdir)
     targetdir = tools.folderize(self.rbfo.configurator, targetdir)
     # Set Destination  Filename
     targetname = self.rbfo.configurator.get_val('layout-filename')
     targetname = tools.data_filler(self, targetname)
     targetname += os.path.splitext(self.location)[1]
     # Join destination
     destin = (os.path.join(targetdir, targetname)).replace('file:///', '/')
     if inputstring == 'destin':
         return destin
     return
Example #2
0
 def get_locations(self, inputstring):
     """ Get file path for other file operations """
     # Get source for comparison
     source = url2pathname(self.location).replace('file:///', '/')
     if inputstring == 'source':
         return source
     # Set Destination Directory
     targetdir = '/' + self.rbfo.configurator.get_val('layout-path')
     targetdir = tools.data_filler(self, targetdir,
                                   strip_ntfs=self.strip_ntfs)
     targetdir = tools.folderize(self.rbfo.configurator, targetdir)
     # Set Destination  Filename
     targetname = self.rbfo.configurator.get_val('layout-filename')
     targetname = tools.data_filler(self, targetname,
                                    strip_ntfs=self.strip_ntfs)
     targetname += os.path.splitext(self.location)[1]
     # Join destination
     destin = (os.path.join(targetdir, targetname)).replace('file:///', '/')
     if inputstring == 'destin':
         return destin
     return
Example #3
0
 def get_locations(self, inputstring):
     """ Get file path for other file operations """
     # Get source for comparison
     source = self.location.replace('file:///', '/')
     if inputstring == 'source':
         return urllib.parse.unquote(source)
     # Set Destination Directory
     targetdir = '/' + self.rbfo.configurator.get_val('layout-path')
     targetdir = tools.data_filler(self, targetdir,
                                   strip_ntfs=self.strip_ntfs)
     targetloc = self.rbfo.configurator.get_val('locations')[0]
     targetpath = targetloc.replace('file:///', '/')
     targetdir = tools.folderize(targetpath, targetdir)
     # Set Destination  Filename
     targetname = self.rbfo.configurator.get_val('layout-filename')
     targetname = tools.data_filler(self, targetname,
                                    strip_ntfs=self.strip_ntfs)
     targetname += os.path.splitext(self.location)[1]
     # Join destination
     if inputstring == 'destin':
         return urllib.parse.unquote((os.path.join(targetdir, targetname)))
     return
Example #4
0
    def relocate(self):
        """Performs the actual moving.
        -Move file to correct place
        -Update file location in RB database.
        """
        source = self.get_locations('source')
        destin = urllib.parse.unquote(self.get_locations('destin'))
        # Begin Log File
        tmptime = time.strftime("%I:%M:%S %p", time.localtime())
        logheader = '%ta - %at - '
        logheader = (
            tools.data_filler(self, logheader, strip_ntfs=self.strip_ntfs) +
            tmptime)
        # self.log = LogFile()
        self.log.log_processing(logheader)
        self.log.log_processing((IN + source))

        # Relocate, if necessary
        if source == destin:
            print('No need for file relocation')
            self.log.log_processing(INFO + NO_NEED)
        else:
            if os.path.isfile(destin):
                # Copy the existing file to a backup dir
                tmpdir = (
                    self.rbfo.configurator.get_val('locations'))[0].replace(
                        'file:///', '/')
                tmpdir = urllib.parse.unquote(tmpdir)
                backupdir = tools.folderize(tmpdir, 'backup/')
                backup = os.path.join(backupdir, os.path.basename(destin))
                if os.path.isfile(backup):
                    counter = 0
                    backuptest = backup
                    while os.path.isfile(backup):
                        backup = backuptest
                        counter += 1
                        backup = (backup[:(backup.rfind('.'))] + str(counter) +
                                  backup[(backup.rfind('.')):])
                    try:
                        os.makedirs(os.path.dirname(backupdir))
                    except OSError:
                        pass
                    try:
                        shutil.move(source, backup)
                        self.log.log_processing(CONFLICT + FILE_EXISTS)
                        self.log.log_processing(OUT + backup)
                    except FileNotFoundError:
                        # we found a duplicate in the DB
                        pass
                destin = backup
            else:
                # Move the file to desired destination
                shutil.move(source, destin)
                self.log.log_processing(OUT + destin)

            # Update Rhythmbox database
            self.location = urllib.parse.quote(destin)
            self.location = ('file://' + self.location)
            self.location = self.set_ascii(self.location)
            print('Relocating file \n%s to\n%s' % (source, destin))
            self.log.log_processing(INFO + UPDATING)
            print(self.entry.get_string(RB.RhythmDBPropType.LOCATION))
            print(self.location)
            self.log.log_processing(
                IN + self.entry.get_string(RB.RhythmDBPropType.LOCATION))
            self.log.log_processing(OUT + self.location)
            # Make the change
            self.rbdb.entry_set(self.entry, RB.RhythmDBPropType.LOCATION,
                                self.location)
            # Non media clean up
            self.file_cleanup(source, destin)
        self.log.log_processing('')
Example #5
0
    def relocate(self):
        """Performs the actual moving.
        -Move file to correct place and cover art to RB cache (if enabled)
        -Update file location in RB database. Update tags (if enabled)
        """
        source = self.get_locations('source')
        destin = self.url.set_ascii(self.get_locations('destin'), 0)
        # Begin Log File
        tmptime = time.strftime("%I:%M:%S %p", time.localtime())
        logheader = '%ta - %at - '
        logheader = (tools.data_filler(self, logheader,
                                       strip_ntfs=self.strip_ntfs) + tmptime)
        # self.log = LogFile()
        self.log.log_processing(logheader)
        self.log.log_processing((IN + source))
        # Save cover art if found into Rhythmbox cover cache
        self.set_rb_coverart(source)

        # Relocate, if necessary
        if source == destin:
            print('No need for file relocation')
            self.log.log_processing(INFO + NO_NEED)
        else:
            if os.path.isfile(destin):
                # Copy the existing file to a backup dir
                # backupdir = (((self.rbfo.configurator.get_val('locations'))[0] +
                #              '/backup/').replace('file:///', '/'))
                tmpdir = (self.rbfo.configurator.get_val('locations'))[0].replace('file:///', '/')
                tmpdir = self.url.set_ascii(tmpdir, 0)
                backupdir = tools.folderize(tmpdir, 'backup/')
                backup = os.path.join(backupdir, os.path.basename(destin))
                if os.path.isfile(backup):
                    counter = 0
                    backuptest = backup
                    while os.path.isfile(backup):
                        backup = backuptest
                        counter += 1
                        backup = (backup[:(backup.rfind('.'))] + str(counter) +
                                  backup[(backup.rfind('.')):])
                try:
                    os.makedirs(os.path.dirname(backupdir))
                except OSError:
                    pass
                destin = backup
                self.log.log_processing(CONFLICT + FILE_EXISTS)
            print('source   ' + source)
            print('destin   ' + destin)
            try:
                mvsource = source  # .decode('utf-8')
                mvdestin = destin  # .decode('utf-8')
            except TypeError:
                print('TYPEERROR')
                mvsource = source
                mvdestin = destin
            shutil.move(mvsource, mvdestin)
            self.log.log_processing(OUT + mvdestin)

            # Update Rhythmbox database
            # self.url = UrlData()
            self.location = self.url.set_ascii(pathname2url(destin), 16)
            self.location = ('file://' + self.location)
            print('Relocating file %s to %s' % (source, destin))
            self.log.log_processing(INFO + UPDATING)
            print(self.entry.get_string(RB.RhythmDBPropType.LOCATION))
            print(self.location)
            # Make the change
            self.rbdb.entry_set(self.entry,
                                RB.RhythmDBPropType.LOCATION, self.location)
            self.log.log_processing(OUT + self.location)
            #tools.update_tags(mvdestin)
            # Non media clean up
            self.file_cleanup(mvsource, mvdestin)
        self.log.log_processing('')
Example #6
0
    def relocate(self):
        """Performs the actual moving.
        -Move file to correct place
        -Update file location in RB database.
        """
        source = self.get_locations('source')
        destin = urllib.parse.unquote(self.get_locations('destin'))
        # Begin Log File
        tmptime = time.strftime("%I:%M:%S %p", time.localtime())
        logheader = '%ta - %at - '
        logheader = (tools.data_filler(self, logheader,
                                       strip_ntfs=self.strip_ntfs) + tmptime)
        # self.log = LogFile()
        self.log.log_processing(logheader)
        self.log.log_processing((IN + source))

        # Relocate, if necessary
        if source == destin:
            print('No need for file relocation')
            self.log.log_processing(INFO + NO_NEED)
        else:
            if os.path.isfile(destin):
                # Copy the existing file to a backup dir
                tmpdir = (self.rbfo.configurator.get_val('locations'))[0].replace('file:///', '/')
                tmpdir = urllib.parse.unquote(tmpdir)
                backupdir = tools.folderize(tmpdir, 'backup/')
                backup = os.path.join(backupdir, os.path.basename(destin))
                if os.path.isfile(backup):
                    counter = 0
                    backuptest = backup
                    while os.path.isfile(backup):
                        backup = backuptest
                        counter += 1
                        backup = (backup[:(backup.rfind('.'))] + str(counter) +
                                  backup[(backup.rfind('.')):])
                    try:
                        os.makedirs(os.path.dirname(backupdir))
                    except OSError:
                        pass
                    try:
                        shutil.move(source, backup)
                        self.log.log_processing(CONFLICT + FILE_EXISTS)
                        self.log.log_processing(OUT + backup)
                    except FileNotFoundError:
                        # we found a duplicate in the DB
                        pass
                destin = backup
            else:
                # Move the file to desired destination
                shutil.move(source, destin)
                self.log.log_processing(OUT + destin)

            # Update Rhythmbox database
            self.location = urllib.parse.quote(destin)
            self.location = ('file://' + self.location)
            self.location = self.set_ascii(self.location)
            print('Relocating file \n%s to\n%s' % (source, destin))
            self.log.log_processing(INFO + UPDATING)
            print(self.entry.get_string(RB.RhythmDBPropType.LOCATION))
            print(self.location)
            self.log.log_processing(IN + self.entry.get_string(RB.RhythmDBPropType.LOCATION))
            self.log.log_processing(OUT + self.location)
            # Make the change
            self.rbdb.entry_set(self.entry,
                                RB.RhythmDBPropType.LOCATION,
                                self.location)
            # Non media clean up
            self.file_cleanup(source, destin)
        self.log.log_processing('')