Exemplo n.º 1
0
 def set_rb_coverart(self, source):
     """ Copies cover art from the file location to the RB cache """
     coverart_enabled = self.conf.get('conf', 'cover_enabled')
     coverart_names = self.conf.get('conf', 'cover_names')
     coverart_names = coverart_names.split(',')
     if coverart_enabled == 'True':
         if not os.path.isdir(os.getenv('HOME') + RB_COVER_CACHE):
             try:
                 os.makedirs(os.getenv('HOME') + RB_COVER_CACHE)
             except PermissionError:
                 print('Create folder Failed: Missing permissions to path')
             except:
                 print('Create folder Failed')
         artfile = '%ta - %at'
         artfile = (tools.data_filler(self, artfile,
                                      strip_ntfs=self.strip_ntfs) + '.jpg')
         artfile = os.getenv('HOME') + RB_COVER_CACHE + artfile
         if not os.path.isfile(artfile):
             print('COVERART MISSING')
             for filenames in coverart_names:
                 test = os.path.dirname(source) + '/' + filenames
                 if os.path.isfile(test):
                     print('COPYING COVERART TO RB CACHE')
                     self.log.log_processing(INFO + ART_MOVED)
                     shutil.copyfile(test, artfile)
Exemplo n.º 2
0
 def set_rb_coverart(self, source):
     """ Copies cover art from the file location to the RB cache """
     coverart_enabled = self.conf.get('conf', 'cover_enabled')
     coverart_names = self.conf.get('conf', 'cover_names')
     coverart_names = coverart_names.split(',')
     if coverart_enabled == 'True':
         if not os.path.isdir(os.getenv('HOME') + RB_COVER_CACHE):
             try:
                 os.makedirs(os.getenv('HOME') + RB_COVER_CACHE)
             except PermissionError:
                 print('Create folder Failed: Missing permissions to path')
             except:
                 print('Create folder Failed')
         artfile = '%ta - %at'
         artfile = (tools.data_filler(self, artfile,
                                      strip_ntfs=self.strip_ntfs) + '.jpg')
         artfile = os.getenv('HOME') + RB_COVER_CACHE + artfile
         if not os.path.isfile(artfile):
             print('COVERART MISSING')
             for filenames in coverart_names:
                 test = os.path.dirname(source) + '/' + filenames
                 if os.path.isfile(test):
                     print('COPYING COVERART TO RB CACHE')
                     self.log.log_processing(INFO + ART_MOVED)
                     shutil.copyfile(test, artfile)
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 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('')
Exemplo n.º 7
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.get_locations('destin')
        # Begin Log File
        currenttime = time.strftime("%I:%M:%S %p", time.localtime())
        logheader = '%ta - %at - '
        logheader = (tools.data_filler(self, logheader) + currenttime)
        #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:///', '/'))
                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 = 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))
            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)
            self.update_tags(mvdestin)
            # Non media clean up
            self.file_cleanup(mvsource, mvdestin)
        self.log.log_processing('')
Exemplo n.º 8
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.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))
        # 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:///', '/'))
                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 = 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))
            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('')
Exemplo n.º 9
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('')