Ejemplo n.º 1
0
def cleanup_incomplete_downloads():
    download_dir = os.path.join(app.config.get(prefs.MOVIES_DIRECTORY),
                                'Incomplete Downloads')
    if not fileutil.exists(download_dir):
        return

    files_in_use = set()
    for downloader in RemoteDownloader.make_view():
        if downloader.get_state() in ('downloading', 'paused',
                                     'offline', 'uploading', 'finished',
                                     'uploading-paused'):
            filename = downloader.get_filename()
            if filename:
                if not fileutil.isabs(filename):
                    filename = os.path.join(download_dir, filename)
                files_in_use.add(filename)

    try:
        entries = fileutil.listdir(download_dir)
    except OSError:
        entries = []

    for f in entries:
        f = os.path.join(download_dir, f)
        if f not in files_in_use:
            try:
                if fileutil.isfile(f):
                    fileutil.remove(f)
                elif fileutil.isdir(f):
                    fileutil.rmtree(f)
            except OSError:
                # FIXME - maybe a permissions error?
                pass
Ejemplo n.º 2
0
def cleanup_incomplete_downloads():
    download_dir = os.path.join(app.config.get(prefs.MOVIES_DIRECTORY),
                                'Incomplete Downloads')
    if not fileutil.exists(download_dir):
        return

    files_in_use = set()
    for downloader in RemoteDownloader.make_view():
        if downloader.get_state() in ('downloading', 'paused',
                                     'offline', 'uploading', 'finished',
                                     'uploading-paused'):
            filename = downloader.get_filename()
            if filename:
                if not fileutil.isabs(filename):
                    filename = os.path.join(download_dir, filename)
                files_in_use.add(filename)

    try:
        entries = fileutil.listdir(download_dir)
    except OSError:
        entries = []

    for f in entries:
        f = os.path.join(download_dir, f)
        if f not in files_in_use:
            try:
                if fileutil.isfile(f):
                    fileutil.remove(f)
                elif fileutil.isdir(f):
                    fileutil.rmtree(f)
            except OSError:
                # FIXME - maybe a permissions error?
                pass
Ejemplo n.º 3
0
 def on_cancel(self, remove_file):
     self._cleanup_filehandle()
     if remove_file and self.options.write_file:
         try:
             fileutil.remove(self.options.write_file)
         except OSError:
             pass
Ejemplo n.º 4
0
 def on_cancel(self, remove_file):
     self._cleanup_filehandle()
     if remove_file and self.options.write_file:
         try:
             fileutil.remove(self.options.write_file)
         except OSError:
             pass
Ejemplo n.º 5
0
def download_file(url, handle_unknown_callback):
    """
    Deals with turning an .amz file into some real downloads.
    """
    def unknown():
        handle_unknown_callback(url)

    def callback(data):
        _amazon_callback(data, unknown)

    if url.startswith('file://'):
        path = url[7:]
        try:
            with file(path) as f:
                if path.endswith('.m3u'):
                    _m3u_callback(f.read())
                else:
                    _amz_callback(f.read())
        finally:
            fileutil.remove(path)
        return
    options = httpclient.TransferOptions(url)
    options.requires_cookies = True
    transfer = httpclient.CurlTransfer(options, callback,
                                       handle_unknown_callback)
    transfer.start()
Ejemplo n.º 6
0
def download_file(url, handle_unknown_callback):
    """
    Deals with turning an .amz file into some real downloads.
    """
    def unknown():
        handle_unknown_callback(url)
    def callback(data):
        _amazon_callback(data, unknown)

    if url.startswith('file://'):
        path = url[7:]
        try:
            with file(path) as f:
                if path.endswith('.m3u'):
                    _m3u_callback(f.read())
                else:
                    _amz_callback(f.read())
        finally:
            fileutil.remove(path)
        return
    options = httpclient.TransferOptions(url)
    options.requires_cookies = True
    transfer = httpclient.CurlTransfer(options, callback,
                                       handle_unknown_callback)
    transfer.start()
Ejemplo n.º 7
0
 def handle_error(self, shortReason, reason):
     BGDownloader.handle_error(self, shortReason, reason)
     self.cancel_request()
     if os.path.exists(self.filename):
         try:
             fileutil.remove(self.filename)
         except OSError:
             pass
     self.currentSize = 0
     self.totalSize = -1
Ejemplo n.º 8
0
 def stop(self, delete):
     self.state = "stopped"
     self._shutdown_torrent()
     self.update_client()
     if delete:
         try:
             if fileutil.isdir(self.filename):
                 fileutil.rmtree(self.filename)
             else:
                 fileutil.remove(self.filename)
         except OSError:
             pass
Ejemplo n.º 9
0
def download_file(url, handle_unknown_callback):
    """
    Deals with turning an .amz file into some real downloads.
    """
    if url.startswith('file://'):
        path = url[7:]
        try:
            _download_emx_files(path)
        finally:
            fileutil.remove(path)
        return

    def callback(data):
        _emx_callback(data, handle_unknown_callback)

    options = httpclient.TransferOptions(url)
    options.requires_cookies = True
    transfer = httpclient.CurlTransfer(options, callback,
                                       handle_unknown_callback)
    transfer.start()
Ejemplo n.º 10
0
 def stop(self, delete):
     """Stops the download and removes the partially downloaded
     file.
     """
     if self.state == 'finished':
         if delete:
             try:
                 if fileutil.isdir(self.filename):
                     fileutil.rmtree(self.filename)
                 else:
                     fileutil.remove(self.filename)
             except OSError:
                 pass
     else:
         # Cancel the request, don't keep around partially
         # downloaded data
         self.cancel_request(remove_file=True)
     self.currentSize = 0
     self.state = "stopped"
     self.update_client()
Ejemplo n.º 11
0
def download_file(url, handle_unknown_callback):
    """
    Deals with turning an .amz file into some real downloads.
    """
    if url.startswith('file://'):
        path = url[7:]
        try:
            _download_emx_files(path)
        finally:
            fileutil.remove(path)
        return

    def callback(data):
        _emx_callback(data, handle_unknown_callback)

    options = httpclient.TransferOptions(url)
    options.requires_cookies = True
    transfer = httpclient.CurlTransfer(options, callback,
                                       handle_unknown_callback)
    transfer.start()
Ejemplo n.º 12
0
 def remove_file(self, filename):
     try:
         fileutil.remove(filename)
     except OSError:
         pass
Ejemplo n.º 13
0
 def remove_file(self, filename):
     try:
         fileutil.remove(filename)
     except OSError:
         pass