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
c5432bb0
Commit
c5432bb0
authored
Sep 16, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various changes..
parent
ac051cb8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
22 deletions
+53
-22
fs/__init__.py
+10
-2
fs/fs.py
+29
-13
fs/osfs.py
+2
-2
fs/tempfs.py
+12
-5
No files found.
fs/__init__.py
View file @
c5432bb0
from
fs
import
*
from
fs
import
*
from
helpers
import
*
from
helpers
import
*
__all__
=
[
'browserwin'
,
'memoryfs'
,
'mountfs'
,
'multifs'
,
'osfs'
,
'utils'
,
'zipfs'
]
__all__
=
[
'browserwin'
,
\ No newline at end of file
'memoryfs'
,
'mountfs'
,
'multifs'
,
'osfs'
,
'utils'
,
'zipfs'
,
'helpers'
,
'tempfs'
]
\ No newline at end of file
fs/fs.py
View file @
c5432bb0
...
@@ -9,7 +9,8 @@ import datetime
...
@@ -9,7 +9,8 @@ import datetime
try
:
try
:
import
threading
import
threading
except
ImportError
:
except
ImportError
:
import
dummy_threading
as
threadding
import
dummy_threading
as
threading
import
dummy_threading
error_msgs
=
{
error_msgs
=
{
...
@@ -211,11 +212,16 @@ class FS(object):
...
@@ -211,11 +212,16 @@ class FS(object):
"""
"""
def
__init__
(
self
,
thread_syncronize
=
False
):
def
__init__
(
self
,
thread_syncronize
=
False
):
"""The baseclass for Filesystem objects.
thread_synconize -- If True, a lock object will be created for the
object, otherwise a dummy lock will be used.
"""
if
thread_syncronize
:
if
thread_syncronize
:
self
.
_lock
=
threading
.
RLock
()
self
.
_lock
=
threading
.
RLock
()
else
:
else
:
self
.
_lock
=
None
self
.
_lock
=
dummy_threading
.
RLock
()
def
_resolve
(
self
,
pathname
):
def
_resolve
(
self
,
pathname
):
resolved_path
=
resolvepath
(
pathname
)
resolved_path
=
resolvepath
(
pathname
)
...
@@ -241,9 +247,22 @@ class FS(object):
...
@@ -241,9 +247,22 @@ class FS(object):
return
None
return
None
def
hassyspath
(
self
,
path
):
def
hassyspath
(
self
,
path
):
"""Return True if the path maps to a system path.
path -- Pach to check
"""
return
self
.
getsyspath
(
path
,
None
)
is
not
None
return
self
.
getsyspath
(
path
,
None
)
is
not
None
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
"""Opens a file.
path -- Path to file that should be opened
mode -- Mode of file to open, identical too the mode string used in
'file' and 'open' builtins
kwargs -- Additional (optional) keyword parameters that may be required to open the file
"""
raise
UnsupportedError
(
"UNSUPPORTED"
)
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
safeopen
(
self
,
*
args
,
**
kwargs
):
def
safeopen
(
self
,
*
args
,
**
kwargs
):
...
@@ -334,9 +353,6 @@ class FS(object):
...
@@ -334,9 +353,6 @@ class FS(object):
else
:
else
:
return
"OS file, maps to
%
s"
%
sys_path
return
"OS file, maps to
%
s"
%
sys_path
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
raise
UnsupportedError
(
"UNSUPPORTED"
)
def
getcontents
(
self
,
path
):
def
getcontents
(
self
,
path
):
"""Returns the contents of a file as a string.
"""Returns the contents of a file as a string.
...
@@ -368,6 +384,11 @@ class FS(object):
...
@@ -368,6 +384,11 @@ class FS(object):
f
.
close
()
f
.
close
()
def
opendir
(
self
,
path
):
def
opendir
(
self
,
path
):
"""Opens a directory and returns a FS object representing its contents.
path -- Path to directory to open
"""
if
not
self
.
exists
(
path
):
if
not
self
.
exists
(
path
):
raise
ResourceNotFoundError
(
"NO_DIR"
,
path
)
raise
ResourceNotFoundError
(
"NO_DIR"
,
path
)
...
@@ -375,6 +396,8 @@ class FS(object):
...
@@ -375,6 +396,8 @@ class FS(object):
return
sub_fs
return
sub_fs
def
_listdir_helper
(
self
,
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
):
def
_listdir_helper
(
self
,
path
,
paths
,
wildcard
,
full
,
absolute
,
hidden
,
dirs_only
,
files_only
):
"""A helper function called by listdir method that applies filtering."""
if
dirs_only
and
files_only
:
if
dirs_only
and
files_only
:
raise
ValueError
(
"dirs_only and files_only can not both be True"
)
raise
ValueError
(
"dirs_only and files_only can not both be True"
)
...
@@ -604,13 +627,6 @@ class FS(object):
...
@@ -604,13 +627,6 @@ class FS(object):
raise
ResourceInvalid
(
"WRONG_TYPE"
,
src
,
msg
=
"Source is not a dst:
%(path)
s"
)
raise
ResourceInvalid
(
"WRONG_TYPE"
,
src
,
msg
=
"Source is not a dst:
%(path)
s"
)
if
not
self
.
isdir
(
dst
):
if
not
self
.
isdir
(
dst
):
raise
ResourceInvalid
(
"WRONG_TYPE"
,
dst
,
msg
=
"Source is not a dst:
%(path)
s"
)
raise
ResourceInvalid
(
"WRONG_TYPE"
,
dst
,
msg
=
"Source is not a dst:
%(path)
s"
)
#
#src_syspath = self.getsyspath(src, allow_none=True)
#dst_syspath = self.getsyspath(dst, allow_none=True)
#
#if src_syspath is not None and dst_syspath is not None:
# shutil.copytree(src_syspath, dst_syspath)
#else:
def
copyfile_noerrors
(
src
,
dst
):
def
copyfile_noerrors
(
src
,
dst
):
try
:
try
:
...
@@ -669,7 +685,7 @@ class SubFS(FS):
...
@@ -669,7 +685,7 @@ class SubFS(FS):
self
.
sub_dir
=
parent
.
_abspath
(
sub_dir
)
self
.
sub_dir
=
parent
.
_abspath
(
sub_dir
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"<SubFS
\"
%
s
\"
in
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
return
"<SubFS
:
\"
%
s
\"
in
%
s>"
%
(
self
.
sub_dir
,
self
.
parent
)
def
desc
(
self
,
path
):
def
desc
(
self
,
path
):
if
self
.
isdir
(
path
):
if
self
.
isdir
(
path
):
...
...
fs/osfs.py
View file @
c5432bb0
...
@@ -4,8 +4,8 @@ from fs import *
...
@@ -4,8 +4,8 @@ from fs import *
class
OSFS
(
FS
):
class
OSFS
(
FS
):
def
__init__
(
self
,
root_path
):
def
__init__
(
self
,
root_path
,
thread_syncronize
=
True
):
FS
.
__init__
(
self
)
FS
.
__init__
(
self
,
thread_syncronize
=
thread_syncronize
)
expanded_path
=
normpath
(
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
root_path
)))
expanded_path
=
normpath
(
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
root_path
)))
...
...
fs/tempfs.py
View file @
c5432bb0
...
@@ -9,7 +9,7 @@ class TempFS(OSFS):
...
@@ -9,7 +9,7 @@ class TempFS(OSFS):
"""Create a Filesystem in a tempory directory (with tempfile.mkdtemp),
"""Create a Filesystem in a tempory directory (with tempfile.mkdtemp),
and removes it when the TempFS object is cleaned up."""
and removes it when the TempFS object is cleaned up."""
def
__init__
(
self
,
identifier
=
None
):
def
__init__
(
self
,
identifier
=
None
,
thread_syncronize
=
True
):
"""Creates a temporary Filesystem
"""Creates a temporary Filesystem
identifier -- A string that is included in the name of the temporary directory,
identifier -- A string that is included in the name of the temporary directory,
...
@@ -18,18 +18,25 @@ class TempFS(OSFS):
...
@@ -18,18 +18,25 @@ class TempFS(OSFS):
"""
"""
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
)
self
.
_cleaned
=
False
self
.
_cleaned
=
False
OSFS
.
__init__
(
self
,
self
.
_temp_dir
)
OSFS
.
__init__
(
self
,
self
.
_temp_dir
,
thread_syncronize
=
thread_syncronize
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'<TempFS in "
%
s">'
%
self
.
_temp_dir
return
'<TempFS in "
%
s">'
%
self
.
_temp_dir
def
__unicode__
(
self
):
return
uncode
(
self
.
__str__
())
def
_cleanup
(
self
):
def
_cleanup
(
self
):
"""Called by __del__ to remove the temporary directory. Can be called directly,
"""Called by __del__ to remove the temporary directory. Can be called directly,
but it is probably not
advisable
."""
but it is probably not
neccesary
."""
if
not
self
.
_cleaned
:
if
not
self
.
_cleaned
:
rmtree
(
self
.
_temp_dir
)
self
.
_lock
.
acquire
()
self
.
_cleaned
=
True
try
:
rmtree
(
self
.
_temp_dir
)
self
.
_cleaned
=
True
finally
:
self
.
_lock
.
release
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
_cleanup
()
self
.
_cleanup
()
...
...
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