Exemplo n.º 1
0
def copy(source, destination):
    """Copy file to destination, returns true/false.

    source: string - file to copy.
    destination: string - destination file

    Example:
        success = xbmcvfs.copy(source, destination)"""
    try:
        shutil.copy(encode_fs(source), encode_fs(destination))
        return True
    except:
        log.warning("Can't copy %s to %s", file, destination, exc_info=True)
        return False
Exemplo n.º 2
0
    def _connect(self):
        log.debug("Opening Sqlite table %r in %s" % (self.tablename, self.filename))
        filename = encode_fs(self.filename)
        if self.flag == 'n':
            if os.path.exists(filename):
                os.remove(filename)
        dirname = os.path.dirname(filename)
        if dirname and not os.path.exists(dirname):
            raise RuntimeError('Error! The directory does not exist, %s' % self.filename)

        if self.autocommit:
            self.conn = sqlite3.connect(self.filename, isolation_level=None)
        else:
            self.conn = sqlite3.connect(self.filename)
        try:
            self._execute(self.CREATE_TABLE % self.tablename)
            self._execute(self.CREATE_INDEX % self.tablename)
            if self.flag == 'w':
                self.clear()
            elif self.autopurge and self.ttl:
                self.purge()
            elif self.cached:
                self._load()
        except sqlite3.DatabaseError:
            self.close()
            raise
Exemplo n.º 3
0
    def _connect(self, check_same_thread=False):
        log.debug("Opening Sqlite table %r in %s" % (self.tablename, self.filename))
        filename = encode_fs(self.filename)
        if self.flag == 'n':
            if os.path.exists(filename):
                os.remove(filename)
        dirname = os.path.dirname(filename)
        if dirname and not os.path.exists(dirname):
            raise RuntimeError('Error! The directory does not exist, %s' % self.filename)

        if self.autocommit:
            self.conn = sqlite3.connect(self.filename, isolation_level=None, check_same_thread=check_same_thread)
        else:
            self.conn = sqlite3.connect(self.filename, check_same_thread=check_same_thread)
        try:
            self._execute(self.CREATE_TABLE % self.tablename)
            self._execute(self.CREATE_INDEX % self.tablename)
            if self.flag == 'w':
                self.clear()
            elif self.autopurge and self.ttl:
                self.purge()
            elif self.cached:
                self._load()
        except sqlite3.DatabaseError:
            self.close()
            raise
Exemplo n.º 4
0
def exists(path):
    """Checks for a file or folder existance, mimics Pythons os.path.exists()

    path: string - file or folder

    Example:
        success = xbmcvfs.exists(path)"""
    try:
        return os.path.exists(encode_fs(path))
    except:
        return False
Exemplo n.º 5
0
def delete(file):
    """Deletes a file.

    file: string - file to delete

    Example:
        xbmcvfs.delete(file)"""
    try:
        os.remove(encode_fs(file))
        return True
    except:
        log.warning("Can't remove %s", file, exc_info=True)
        return False
Exemplo n.º 6
0
def rmdir(path):
    """Remove a folder.

    path: folder

    Example:
        success = xbmcfvs.rmdir(path)
    """
    try:
        os.rmdir(encode_fs(path))
        return True
    except:
        log.warning("Can't rmdir %s", path, exc_info=True)
        return False
Exemplo n.º 7
0
def mkdirs(path):
    """
    mkdirs(path)--Create folder(s) - it will create all folders in the path.

    path : folder

    example:

    - success = xbmcvfs.mkdirs(path)
    """
    try:
        os.makedirs(encode_fs(path))
        return True
    except:
        log.warning("Can't makedirs %s", path, exc_info=True)
        return False