Example #1
0
 def get_free_space(self):
     # Reserve 10 MiB for iTunesDB writing (to be on the safe side)
     RESERVED_FOR_ITDB = 1024*1024*10
     result = util.get_free_disk_space(self.mountpoint)
     if result == -1:
         # Can't get free disk space
         return -1
     return result - RESERVED_FOR_ITDB
Example #2
0
 def get_free_space(self):
     # Reserve 10 MiB for iTunesDB writing (to be on the safe side)
     RESERVED_FOR_ITDB = 1024 * 1024 * 10
     result = util.get_free_disk_space(self.mountpoint)
     if result == -1:
         # Can't get free disk space
         return -1
     return result - RESERVED_FOR_ITDB
Example #3
0
    def write( self, channels):
        """
        Creates a XML document containing metadata for each 
        channel object in the "channels" parameter, which 
        should be a list of channel objects.

        OPML 2.0 specification: http://www.opml.org/spec2

        Returns True on success or False when there was an 
        error writing the file.
        """
        if self.filename is None:
            return False

        doc = xml.dom.minidom.Document()

        opml = doc.createElement('opml')
        opml.setAttribute('version', '2.0')
        doc.appendChild(opml)

        head = doc.createElement( 'head')
        head.appendChild( self.create_node( doc, 'title', 'gPodder subscriptions'))
        head.appendChild( self.create_node( doc, 'dateCreated', formatdate(localtime=True)))
        opml.appendChild( head)

        body = doc.createElement( 'body')
        for channel in channels:
            body.appendChild( self.create_outline( doc, channel))
        opml.appendChild( body)

        try:
            data = doc.toprettyxml(encoding='utf-8', indent='    ', newl=os.linesep)
            # We want to have at least 512 KiB free disk space after
            # saving the opml data, if this is not possible, don't 
            # try to save the new file, but keep the old one so we
            # don't end up with a clobbed, empty opml file.
            FREE_DISK_SPACE_AFTER = 1024*512
            available = util.get_free_disk_space(os.path.dirname(self.filename))
            if available < 2*len(data)+FREE_DISK_SPACE_AFTER:
                # On Windows, if we have zero bytes available, assume that we have
                # not had the win32file module available + assume enough free space
                if not gpodder.win32 or available > 0:
                    logger.error('Not enough free disk space to save channel list to %s', self.filename)
                    return False
            fp = open(self.filename+'.tmp', 'w')
            fp.write(data)
            fp.close()
            if gpodder.win32:
                # Win32 does not support atomic rename with os.rename
                shutil.move(self.filename+'.tmp', self.filename)
            else:
                os.rename(self.filename+'.tmp', self.filename)
        except:
            logger.error('Could not open file for writing: %s', self.filename,
                    exc_info=True)
            return False

        return True
Example #4
0
    def write( self, channels):
        """
        Creates a XML document containing metadata for each 
        channel object in the "channels" parameter, which 
        should be a list of channel objects.

        OPML 2.0 specification: http://www.opml.org/spec2

        Returns True on success or False when there was an 
        error writing the file.
        """
        if self.filename is None:
            return False

        doc = xml.dom.minidom.Document()

        opml = doc.createElement('opml')
        opml.setAttribute('version', '2.0')
        doc.appendChild(opml)

        head = doc.createElement( 'head')
        head.appendChild( self.create_node( doc, 'title', 'gPodder subscriptions'))
        head.appendChild( self.create_node( doc, 'dateCreated', formatdate(localtime=True)))
        opml.appendChild( head)

        body = doc.createElement( 'body')
        for channel in channels:
            body.appendChild( self.create_outline( doc, channel))
        opml.appendChild( body)

        try:
            data = doc.toprettyxml(encoding='utf-8', indent='    ', newl=os.linesep)
            # We want to have at least 512 KiB free disk space after
            # saving the opml data, if this is not possible, don't 
            # try to save the new file, but keep the old one so we
            # don't end up with a clobbed, empty opml file.
            FREE_DISK_SPACE_AFTER = 1024*512
            path = os.path.dirname(self.filename) or os.path.curdir
            available = util.get_free_disk_space(path)
            if available < 2*len(data)+FREE_DISK_SPACE_AFTER:
                # On Windows, if we have zero bytes available, assume that we have
                # not had the win32file module available + assume enough free space
                if not gpodder.ui.win32 or available > 0:
                    logger.error('Not enough free disk space to save channel list to %s', self.filename)
                    return False
            fp = open(self.filename+'.tmp', 'w')
            fp.write(data)
            fp.close()
            util.atomic_rename(self.filename+'.tmp', self.filename)
        except:
            logger.error('Could not open file for writing: %s', self.filename,
                    exc_info=True)
            return False

        return True
Example #5
0
    def write( self, channels):
        """
        Creates a XML document containing metadata for each 
        channel object in the "channels" parameter, which 
        should be a list of channel objects.

        Returns True on success or False when there was an 
        error writing the file.
        """
        doc=xml.dom.minidom.Document()

        opml=doc.createElement( 'opml')
        opml.setAttribute( 'version', '1.1')
        doc.appendChild( opml)

        head=doc.createElement( 'head')
        head.appendChild( self.create_node( doc, 'title', 'gPodder subscriptions'))
        head.appendChild( self.create_node( doc, 'dateCreated', datetime.datetime.now().ctime()))
        opml.appendChild( head)

        body=doc.createElement( 'body')
        for channel in channels:
            body.appendChild( self.create_outline( doc, channel))
        opml.appendChild( body)

        try:
            data=doc.toprettyxml(encoding='utf-8', indent='    ', newl=os.linesep)
            # We want to have at least 512 KiB free disk space after
            # saving the opml data, if this is not possible, don't 
            # try to save the new file, but keep the old one so we
            # don't end up with a clobbed, empty opml file.
            FREE_DISK_SPACE_AFTER=1024*512
            if util.get_free_disk_space(self.filename) < 2*len(data)+FREE_DISK_SPACE_AFTER:
                log('Not enough free disk space to save channel list to %s', self.filename, sender=self)
                return False
            fp=open(self.filename+'.tmp', 'w')
            fp.write(data)
            fp.close()
            os.rename(self.filename+'.tmp', self.filename)
        except:
            log( 'Could not open file for writing: %s', self.filename, sender=self)
            return False

        return True
Example #6
0
 def get_free_space(self):
     return util.get_free_disk_space(self.destination)
Example #7
0
 def get_free_space(self):
     # Reserve 10 MiB for iTunesDB writing (to be on the safe side)
     RESERVED_FOR_ITDB = 1024 * 1024 * 10
     return util.get_free_disk_space(self.mountpoint) - RESERVED_FOR_ITDB
Example #8
0
 def get_free_space(self):
     return util.get_free_disk_space(self.destination)
Example #9
0
 def get_free_space(self):
     # Reserve 10 MiB for iTunesDB writing (to be on the safe side)
     RESERVED_FOR_ITDB = 1024*1024*10
     return util.get_free_disk_space(self.mountpoint) - RESERVED_FOR_ITDB
Example #10
0
    def add_track(self, episode):
        self.notify('status', _('Adding %s') % episode.title)
        for track in gpod.sw_get_playlist_tracks(self.podcasts_playlist):
            if episode.url == track.podcasturl:
                if track.playcount > 0:
                    gl.history_mark_played(track.podcasturl)
                # Mark as played on iPod if played locally (and set podcast flags)
                self.set_podcast_flags(track)
                return True

        original_filename=str(episode.local_filename())
        local_filename=original_filename

        # Reserve 10 MiB for iTunesDB writing (to be on the safe side)
        RESERVED_FOR_ITDB=1024*1024*10
        space_for_track=util.get_free_disk_space(self.mountpoint) - RESERVED_FOR_ITDB
        needed=util.calculate_size(local_filename)

        if needed > space_for_track:
            log('Not enough space on %s: %s available, but need at least %s', self.mountpoint, util.format_filesize(space_for_track), util.format_filesize(needed), sender=self)
            self.errors.append( _('Error copying %s: Not enough free disk space on %s') % (episode.title, self.mountpoint))
            self.cancelled=True
            return False

        (fn, extension)=os.path.splitext(original_filename)
        if libconverter.converters.has_converter(extension):
            log('Converting: %s', original_filename, sender=self)
            callback_status=lambda percentage: self.notify('sub-progress', int(percentage))
            local_filename=libconverter.converters.convert(original_filename, callback=callback_status)

            if not libtagupdate.update_metadata_on_file(local_filename, title=episode.title, artist=episode.channel.title):
                log('Could not set metadata on converted file %s', local_filename, sender=self)

            if local_filename is None:
                log('Cannot convert %s', original_filename, sender=self)
                return False
            else:
                local_filename=str(local_filename)

        (fn, extension)=os.path.splitext(local_filename)
        if extension.lower().endswith('ogg'):
            log('Cannot copy .ogg files to iPod.', sender=self)
            return False

        track=gpod.itdb_track_new()
        
        # Add release time to track if pubDate is parseable
        ipod_date=email.Utils.parsedate(episode.pubDate)
        if ipod_date is not None:
            try:
                # libgpod>= 0.5.x uses a new timestamp format
                track.time_released=gpod.itdb_time_host_to_mac(int(time.mktime(ipod_date)))
            except:
                # old (pre-0.5.x) libgpod versions expect mactime, so
                # we're going to manually build a good mactime timestamp here :)
                #
                # + 2082844800 for unixtime => mactime (1970 => 1904)
                track.time_released=int(time.mktime(ipod_date) + 2082844800)
        
        track.title=str(episode.title)
        track.album=str(episode.channel.title)
        track.artist=str(episode.channel.title)
        track.description=str(episode.description)

        track.podcasturl=str(episode.url)
        track.podcastrss=str(episode.channel.url)

        track.tracklen=get_track_length(local_filename)
        track.size=os.path.getsize(local_filename)

        if episode.file_type() == 'audio':
            track.filetype='mp3'
            track.mediatype=0x00000004
        elif episode.file_type() == 'video':
            track.filetype='m4v'
            track.mediatype=0x00000006

        self.set_podcast_flags(track)
        self.set_cover_art(track, local_filename)

        gpod.itdb_track_add(self.itdb, track, -1)
        gpod.itdb_playlist_add_track(self.podcasts_playlist, track, -1)
        gpod.itdb_cp_track_to_ipod( track, local_filename, None)

        # If the file has been converted, delete the temporary file here
        if local_filename != original_filename:
            util.delete_file(local_filename)

        return True
Example #11
0
    def write(self, channels):
        """
        Creates a XML document containing metadata for each 
        channel object in the "channels" parameter, which 
        should be a list of channel objects.

        OPML 2.0 specification: http://www.opml.org/spec2

        Returns True on success or False when there was an 
        error writing the file.
        """
        if self.filename is None:
            return False

        doc = xml.dom.minidom.Document()

        opml = doc.createElement('opml')
        opml.setAttribute('version', '2.0')
        doc.appendChild(opml)

        head = doc.createElement('head')
        head.appendChild(
            self.create_node(doc, 'title', 'gPodder subscriptions'))
        head.appendChild(
            self.create_node(doc, 'dateCreated', formatdate(localtime=True)))
        opml.appendChild(head)

        body = doc.createElement('body')
        for channel in channels:
            body.appendChild(self.create_outline(doc, channel))
        opml.appendChild(body)

        try:
            data = doc.toprettyxml(encoding='utf-8',
                                   indent='    ',
                                   newl=os.linesep)
            # We want to have at least 512 KiB free disk space after
            # saving the opml data, if this is not possible, don't
            # try to save the new file, but keep the old one so we
            # don't end up with a clobbed, empty opml file.
            FREE_DISK_SPACE_AFTER = 1024 * 512
            available = util.get_free_disk_space(os.path.dirname(
                self.filename))
            if available < 2 * len(
                    data) + FREE_DISK_SPACE_AFTER and not gpodder.win32:
                # FIXME: get_free_disk_space still unimplemented for win32
                log('Not enough free disk space to save channel list to %s',
                    self.filename,
                    sender=self)
                return False
            fp = open(self.filename + '.tmp', 'w')
            fp.write(data)
            fp.close()
            if gpodder.win32:
                # Win32 does not support atomic rename with os.rename
                shutil.move(self.filename + '.tmp', self.filename)
            else:
                os.rename(self.filename + '.tmp', self.filename)
        except:
            log('Could not open file for writing: %s',
                self.filename,
                sender=self,
                traceback=True)
            return False

        return True