plugin.video.viervijfzes/test/xbmcvfs.py

81 lines
2.1 KiB
Python
Raw Normal View History

2020-03-19 16:45:31 +01:00
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2020-03-20 13:32:55 +01:00
"""This file implements the Kodi xbmcvfs module, either using stubs or alternative functionality"""
2020-03-19 16:45:31 +01:00
# pylint: disable=invalid-name
from __future__ import absolute_import, division, print_function, unicode_literals
import os
2020-03-20 13:32:55 +01:00
from shutil import copyfile
2020-03-19 16:45:31 +01:00
def File(path, flags='r'):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs File() function"""
2020-03-19 16:45:31 +01:00
return open(path, flags)
def Stat(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs Stat() function"""
2020-03-19 16:45:31 +01:00
class stat:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs stat class"""
2020-03-19 16:45:31 +01:00
def __init__(self, path):
2020-03-20 13:32:55 +01:00
"""The constructor xbmcvfs stat class"""
2020-03-19 16:45:31 +01:00
self._stat = os.stat(path)
def st_mtime(self):
2020-03-20 13:32:55 +01:00
"""The xbmcvfs stat class st_mtime method"""
2020-03-19 16:45:31 +01:00
return self._stat.st_mtime
return stat(path)
2020-03-20 13:32:55 +01:00
def copy(src, dst):
"""A reimplementation of the xbmcvfs mkdir() function"""
return copyfile(src, dst) == dst
2020-03-19 16:45:31 +01:00
def delete(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs delete() function"""
2020-03-19 16:45:31 +01:00
try:
os.remove(path)
except OSError:
pass
def exists(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs exists() function"""
2020-03-19 16:45:31 +01:00
return os.path.exists(path)
def listdir(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs listdir() function"""
2020-03-19 16:45:31 +01:00
files = []
dirs = []
2020-03-20 13:32:55 +01:00
if not exists(path):
return dirs, files
2020-03-19 16:45:31 +01:00
for filename in os.listdir(path):
2020-03-20 13:32:55 +01:00
fullname = os.path.join(path, filename)
if os.path.isfile(fullname):
2020-03-19 16:45:31 +01:00
files.append(filename)
2020-03-20 13:32:55 +01:00
if os.path.isdir(fullname):
2020-03-19 16:45:31 +01:00
dirs.append(filename)
return dirs, files
def mkdir(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs mkdir() function"""
2020-03-19 16:45:31 +01:00
return os.mkdir(path)
def mkdirs(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs mkdirs() function"""
2020-03-19 16:45:31 +01:00
return os.makedirs(path)
def rmdir(path):
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcvfs rmdir() function"""
2020-03-19 16:45:31 +01:00
return os.rmdir(path)