Ejemplo n.º 1
0
    def delete(self):
        if "filename" in self.status:
            filename = self.status['filename']
        else:
            return
        try:
            fileutil.delete(filename)
        except OSError:
            logging.exception("Error deleting downloaded file: %s",
                              to_uni(filename))

        parent = os.path.join(fileutil.expand_filename(filename),
                              os.path.pardir)
        parent = os.path.normpath(parent)
        movies_dir = fileutil.expand_filename(
            app.config.get(prefs.MOVIES_DIRECTORY))
        if ((os.path.exists(parent) and os.path.exists(movies_dir)
             and not samefile(parent, movies_dir)
             and len(os.listdir(parent)) == 0)):
            try:
                os.rmdir(parent)
            except OSError:
                logging.exception(
                    "Error deleting empty download directory: %s",
                    to_uni(parent))
Ejemplo n.º 2
0
def _item_exists_for_path(path):
    # in SQLite, LIKE is case insensitive, so we can use it to only look at
    # filenames that possibly will match
    for item_ in item.Item.make_view('filename LIKE ?',
            (filename_to_unicode(path),)):
        if samefile(item_.filename, path):
            return item_
    return False
Ejemplo n.º 3
0
def _item_exists_for_path(path):
    # in SQLite, LIKE is case insensitive, so we can use it to only look at
    # filenames that possibly will match
    for item_ in item.Item.make_view('filename LIKE ?',
            (filename_to_unicode(path),)):
        if samefile(item_.filename, path):
            return item_
    return False
Ejemplo n.º 4
0
    def delete(self):
        if self.filename is None:
            return
        try:
            fileutil.delete(self.filename)
        except OSError:
            logging.exception("Error deleting downloaded file: %s",
                              to_uni(self.filename))

        parent = os.path.join(fileutil.expand_filename(self.filename),
                              os.path.pardir)
        parent = os.path.normpath(parent)
        movies_dir = fileutil.expand_filename(app.config.get(prefs.MOVIES_DIRECTORY))
        if ((os.path.exists(parent) and os.path.exists(movies_dir)
             and not samefile(parent, movies_dir)
             and len(os.listdir(parent)) == 0)):
            try:
                os.rmdir(parent)
            except OSError:
                logging.exception("Error deleting empty download directory: %s",
                                  to_uni(parent))
        self.filename = None