Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
32a62c41
Commit
32a62c41
authored
Oct 18, 2013
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getinfokeys method
parent
c2aa5d7a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
fs/base.py
+21
-0
fs/opener.py
+1
-1
fs/osfs/__init__.py
+26
-3
No files found.
fs/base.py
View file @
32a62c41
...
...
@@ -740,6 +740,22 @@ class FS(object):
"""
raise
UnsupportedError
(
"get resource info"
)
def
getinfokeys
(
self
,
path
,
*
keys
):
"""Get specified keys from info dict, as returned from `getinfo`. The returned dictionary may
not contain all the keys that were asked for, if they aren't available.
This method allows a filesystem to potentially provide a faster way of retrieving these info values if you
are only interested in a subset of them.
:param path: a path to retrieve information for
:param keys: the info keys you would like to retrieve
:rtype: dict
"""
info
=
self
.
getinfo
(
path
)
return
{
k
:
info
[
k
]
for
k
in
keys
if
k
in
info
}
def
desc
(
self
,
path
):
"""Returns short descriptive text regarding a path. Intended mainly as
a debugging aid.
...
...
@@ -760,8 +776,13 @@ class FS(object):
"""Returns the contents of a file as a string.
:param path: A path of file to read
:param mode: Mode to open file with (should be 'rb' for binary or 't' for text)
:param encoding: Encoding to use when reading contents in text mode
:param errors: Unicode errors parameter if text mode is use
:param newline: Newlines parameter for text mode decoding
:rtype: str
:returns: file contents
"""
if
'r'
not
in
mode
:
raise
ValueError
(
"mode must contain 'r' to be readable"
)
...
...
fs/opener.py
View file @
32a62c41
...
...
@@ -271,7 +271,7 @@ class OpenerRegistry(object):
file_object
.
fs
=
fs
return
file_object
def
getcontents
(
self
,
fs_url
,
n
ode
=
'rb'
,
encoding
=
None
,
errors
=
None
,
newline
=
None
):
def
getcontents
(
self
,
fs_url
,
m
ode
=
'rb'
,
encoding
=
None
,
errors
=
None
,
newline
=
None
):
"""Gets the contents from a given FS url (if it references a file)
:param fs_url: a FS URL e.g. ftp://ftp.mozilla.org/README
...
...
fs/osfs/__init__.py
View file @
32a62c41
...
...
@@ -343,17 +343,40 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS):
info
=
dict
((
k
,
getattr
(
stats
,
k
))
for
k
in
dir
(
stats
)
if
k
.
startswith
(
'st_'
))
info
[
'size'
]
=
info
[
'st_size'
]
# TODO: this doesn't actually mean 'creation time' on unix
fromtimestamp
=
datetime
.
datetime
.
fromtimestamp
ct
=
info
.
get
(
'st_ctime'
,
None
)
if
ct
is
not
None
:
info
[
'created_time'
]
=
datetime
.
datetime
.
fromtimestamp
(
ct
)
info
[
'created_time'
]
=
fromtimestamp
(
ct
)
at
=
info
.
get
(
'st_atime'
,
None
)
if
at
is
not
None
:
info
[
'accessed_time'
]
=
datetime
.
datetime
.
fromtimestamp
(
at
)
info
[
'accessed_time'
]
=
fromtimestamp
(
at
)
mt
=
info
.
get
(
'st_mtime'
,
None
)
if
mt
is
not
None
:
info
[
'modified_time'
]
=
datetime
.
datetime
.
fromtimestamp
(
mt
)
info
[
'modified_time'
]
=
fromtimestamp
(
mt
)
return
info
@convert_os_errors
def
getinfokeys
(
self
,
path
,
*
keys
):
info
=
{}
stats
=
self
.
_stat
(
path
)
fromtimestamp
=
datetime
.
datetime
.
fromtimestamp
for
key
in
keys
:
try
:
if
key
==
'size'
:
info
[
key
]
=
stats
.
st_size
elif
key
==
'modified_time'
:
info
[
key
]
=
fromtimestamp
(
stats
.
st_mtime
)
elif
key
==
'created_time'
:
info
[
key
]
=
fromtimestamp
(
stats
.
st_ctime
)
elif
key
==
'accessed_time'
:
info
[
key
]
=
fromtimestamp
(
stats
.
st_atime
)
else
:
info
[
key
]
=
getattr
(
stats
,
key
)
except
AttributeError
:
continue
return
info
@convert_os_errors
def
getsize
(
self
,
path
):
return
self
.
_stat
(
path
)
.
st_size
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment