Add PIO Home "os.get_file_mtime" RPC method

This commit is contained in:
Ivan Kravets
2019-11-16 22:57:56 +02:00
parent c1394b290d
commit 464e1a509f

View File

@ -19,7 +19,6 @@ import glob
import os import os
import shutil import shutil
from functools import cmp_to_key from functools import cmp_to_key
from os.path import isdir, isfile, join
import click import click
from twisted.internet import defer # pylint: disable=import-error from twisted.internet import defer # pylint: disable=import-error
@ -67,7 +66,7 @@ class OSRPC(object):
def request_content(self, uri, data=None, headers=None, cache_valid=None): def request_content(self, uri, data=None, headers=None, cache_valid=None):
if uri.startswith("http"): if uri.startswith("http"):
return self.fetch_content(uri, data, headers, cache_valid) return self.fetch_content(uri, data, headers, cache_valid)
if not isfile(uri): if not os.path.isfile(uri):
return None return None
with codecs.open(uri, encoding="utf-8") as fp: with codecs.open(uri, encoding="utf-8") as fp:
return fp.read() return fp.read()
@ -88,16 +87,20 @@ class OSRPC(object):
@staticmethod @staticmethod
def is_file(path): def is_file(path):
return isfile(path) return os.path.isfile(path)
@staticmethod @staticmethod
def is_dir(path): def is_dir(path):
return isdir(path) return os.path.isdir(path)
@staticmethod @staticmethod
def make_dirs(path): def make_dirs(path):
return os.makedirs(path) return os.makedirs(path)
@staticmethod
def get_file_mtime(path):
return os.path.getmtime(path)
@staticmethod @staticmethod
def rename(src, dst): def rename(src, dst):
return os.rename(src, dst) return os.rename(src, dst)
@ -112,7 +115,7 @@ class OSRPC(object):
pathnames = [pathnames] pathnames = [pathnames]
result = set() result = set()
for pathname in pathnames: for pathname in pathnames:
result |= set(glob.glob(join(root, pathname) if root else pathname)) result |= set(glob.glob(os.path.join(root, pathname) if root else pathname))
return list(result) return list(result)
@staticmethod @staticmethod
@ -131,13 +134,13 @@ class OSRPC(object):
items = [] items = []
if path.startswith("~"): if path.startswith("~"):
path = fs.expanduser(path) path = fs.expanduser(path)
if not isdir(path): if not os.path.isdir(path):
return items return items
for item in os.listdir(path): for item in os.listdir(path):
try: try:
item_is_dir = isdir(join(path, item)) item_is_dir = os.path.isdir(os.path.join(path, item))
if item_is_dir: if item_is_dir:
os.listdir(join(path, item)) os.listdir(os.path.join(path, item))
items.append((item, item_is_dir)) items.append((item, item_is_dir))
except OSError: except OSError:
pass pass