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
d9986180
Commit
d9986180
authored
Dec 13, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Major ftp improvments
parent
7f1e44a3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
92 additions
and
60 deletions
+92
-60
fs/base.py
+2
-2
fs/commands/fscat.py
+2
-2
fs/commands/fsls.py
+14
-6
fs/commands/fsmount.py
+10
-5
fs/commands/runner.py
+1
-1
fs/expose/fuse/__init__.py
+3
-7
fs/ftpfs.py
+0
-0
fs/opener.py
+16
-28
fs/path.py
+4
-0
fs/rpcfs.py
+1
-0
fs/tempfs.py
+10
-0
fs/tests/__init__.py
+1
-0
fs/tests/test_ftpfs.py
+3
-2
fs/utils.py
+25
-7
No files found.
fs/base.py
View file @
d9986180
...
@@ -419,7 +419,7 @@ class FS(object):
...
@@ -419,7 +419,7 @@ class FS(object):
:raises ResourceInvalidError: If the path exists, but is not a directory
:raises ResourceInvalidError: If the path exists, but is not a directory
"""
"""
path
=
normpath
(
path
)
def
getinfo
(
p
):
def
getinfo
(
p
):
try
:
try
:
if
full
or
absolute
:
if
full
or
absolute
:
...
@@ -783,7 +783,7 @@ class FS(object):
...
@@ -783,7 +783,7 @@ class FS(object):
raise
OperationFailedError
(
"get size of resource"
,
path
)
raise
OperationFailedError
(
"get size of resource"
,
path
)
return
size
return
size
def
copy
(
self
,
src
,
dst
,
overwrite
=
False
,
chunk_size
=
1
638
4
):
def
copy
(
self
,
src
,
dst
,
overwrite
=
False
,
chunk_size
=
1
024
*
6
4
):
"""Copies a file from src to dst.
"""Copies a file from src to dst.
:param src: the source path
:param src: the source path
...
...
fs/commands/fscat.py
View file @
d9986180
...
@@ -13,10 +13,10 @@ Concetanate FILE(s)"""
...
@@ -13,10 +13,10 @@ Concetanate FILE(s)"""
def
do_run
(
self
,
options
,
args
):
def
do_run
(
self
,
options
,
args
):
count
=
0
count
=
0
for
fs
,
path
,
is_dir
in
self
.
get_resources
(
args
):
for
fs
,
path
,
is_dir
in
self
.
get_resources
(
args
):
if
is_dir
:
if
is_dir
:
self
.
error
(
'
%
s is a directory
\n
'
%
path
)
self
.
error
(
'
%
s is a directory
\n
'
%
path
)
return
1
return
1
self
.
output
(
fs
.
getcontents
(
path
))
self
.
output
(
fs
.
getcontents
(
path
))
count
+=
1
count
+=
1
if
self
.
is_terminal
()
and
count
:
if
self
.
is_terminal
()
and
count
:
...
...
fs/commands/fsls.py
View file @
d9986180
...
@@ -6,14 +6,14 @@ from fs.commands.runner import Command
...
@@ -6,14 +6,14 @@ from fs.commands.runner import Command
from
collections
import
defaultdict
from
collections
import
defaultdict
import
sys
import
sys
class
FS
List
(
Command
):
class
FS
ls
(
Command
):
usage
=
"""fsls [OPTIONS]... [PATH]
usage
=
"""fsls [OPTIONS]... [PATH]
List contents of [PATH]"""
List contents of [PATH]"""
def
get_optparse
(
self
):
def
get_optparse
(
self
):
optparse
=
super
(
FS
List
,
self
)
.
get_optparse
()
optparse
=
super
(
FS
ls
,
self
)
.
get_optparse
()
optparse
.
add_option
(
'-u'
,
'--full'
,
dest
=
'fullpath'
,
action
=
"store_true"
,
default
=
False
,
optparse
.
add_option
(
'-u'
,
'--full'
,
dest
=
'fullpath'
,
action
=
"store_true"
,
default
=
False
,
help
=
"output full path"
,
metavar
=
"FULL"
)
help
=
"output full path"
,
metavar
=
"FULL"
)
optparse
.
add_option
(
'-s'
,
'--syspath'
,
dest
=
'syspath'
,
action
=
"store_true"
,
default
=
False
,
optparse
.
add_option
(
'-s'
,
'--syspath'
,
dest
=
'syspath'
,
action
=
"store_true"
,
default
=
False
,
...
@@ -37,9 +37,11 @@ List contents of [PATH]"""
...
@@ -37,9 +37,11 @@ List contents of [PATH]"""
args
=
[
u'.'
]
args
=
[
u'.'
]
dir_paths
=
[]
dir_paths
=
[]
file_paths
=
[]
file_paths
=
[]
fs_used
=
set
()
for
fs_url
in
args
:
for
fs_url
in
args
:
fs
,
path
=
self
.
open_fs
(
fs_url
)
fs
,
path
=
self
.
open_fs
(
fs_url
)
fs_used
.
add
(
fs
)
path
=
path
or
'.'
path
=
path
or
'.'
wildcard
=
None
wildcard
=
None
...
@@ -61,7 +63,13 @@ List contents of [PATH]"""
...
@@ -61,7 +63,13 @@ List contents of [PATH]"""
wildcard
=
wildcard
,
wildcard
=
wildcard
,
full
=
options
.
fullpath
,
full
=
options
.
fullpath
,
files_only
=
True
)
files_only
=
True
)
try
:
for
fs
in
fs_used
:
fs
.
close
()
except
FSError
:
pass
if
options
.
syspath
:
if
options
.
syspath
:
dir_paths
=
[
fs
.
getsyspath
(
path
,
allow_none
=
True
)
or
path
for
path
in
dir_paths
]
dir_paths
=
[
fs
.
getsyspath
(
path
,
allow_none
=
True
)
or
path
for
path
in
dir_paths
]
file_paths
=
[
fs
.
getsyspath
(
path
,
allow_none
=
True
)
or
path
for
path
in
file_paths
]
file_paths
=
[
fs
.
getsyspath
(
path
,
allow_none
=
True
)
or
path
for
path
in
file_paths
]
...
@@ -154,7 +162,7 @@ List contents of [PATH]"""
...
@@ -154,7 +162,7 @@ List contents of [PATH]"""
output
(
'
\n
'
)
output
(
'
\n
'
)
def
run
():
def
run
():
return
FS
List
()
.
run
()
return
FS
ls
()
.
run
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
sys
.
exit
(
run
())
sys
.
exit
(
run
())
fs/commands/fsmount.py
View file @
d9986180
...
@@ -22,6 +22,8 @@ Mounts a file system on a system path"""
...
@@ -22,6 +22,8 @@ Mounts a file system on a system path"""
help
=
"run the mount process in the foreground"
,
metavar
=
"FOREGROUND"
)
help
=
"run the mount process in the foreground"
,
metavar
=
"FOREGROUND"
)
optparse
.
add_option
(
'-u'
,
'--unmount'
,
dest
=
'unmount'
,
action
=
"store_true"
,
default
=
False
,
optparse
.
add_option
(
'-u'
,
'--unmount'
,
dest
=
'unmount'
,
action
=
"store_true"
,
default
=
False
,
help
=
"unmount path"
,
metavar
=
"UNMOUNT"
)
help
=
"unmount path"
,
metavar
=
"UNMOUNT"
)
optparse
.
add_option
(
'-n'
,
'--nocache'
,
dest
=
'nocache'
,
action
=
"store_true"
,
default
=
False
,
help
=
"do not cache network filesystems"
,
metavar
=
"NOCACHE"
)
return
optparse
return
optparse
...
@@ -59,17 +61,20 @@ Mounts a file system on a system path"""
...
@@ -59,17 +61,20 @@ Mounts a file system on a system path"""
return
1
return
1
fs
=
fs
.
opendir
(
path
)
fs
=
fs
.
opendir
(
path
)
path
=
'/'
path
=
'/'
if
not
options
.
nocache
:
fs
.
cache_hint
(
True
)
if
not
os
.
path
.
exists
(
mount_path
):
if
not
os
.
path
.
exists
(
mount_path
):
os
.
makedirs
(
mount_path
)
os
.
makedirs
(
mount_path
)
from
fs.expose
import
fuse
from
fs.expose
import
fuse
if
options
.
foreground
:
if
options
.
foreground
:
fuse_process
=
fuse
.
mount
(
fs
,
fuse_process
=
fuse
.
mount
(
fs
,
mount_path
,
mount_path
,
foreground
=
True
)
foreground
=
True
)
else
:
else
:
mp
=
fuse
.
mount
(
fs
,
if
not
os
.
fork
():
mount_path
,
mp
=
fuse
.
mount
(
fs
,
foreground
=
False
)
mount_path
,
foreground
=
True
)
...
...
fs/commands/runner.py
View file @
d9986180
...
@@ -131,7 +131,7 @@ class Command(object):
...
@@ -131,7 +131,7 @@ class Command(object):
resources
=
[]
resources
=
[]
for
fs
,
path
in
fs_paths
:
for
fs
,
path
in
fs_paths
:
if
path
and
iswildcard
(
path
):
if
path
and
iswildcard
(
path
):
if
not
files_only
:
if
not
files_only
:
dir_paths
=
fs
.
listdir
(
wildcard
=
path
,
dirs_only
=
True
)
dir_paths
=
fs
.
listdir
(
wildcard
=
path
,
dirs_only
=
True
)
...
...
fs/expose/fuse/__init__.py
View file @
d9986180
...
@@ -245,14 +245,10 @@ class FSOperations(Operations):
...
@@ -245,14 +245,10 @@ class FSOperations(Operations):
@handle_fs_errors
@handle_fs_errors
def
readdir
(
self
,
path
,
fh
=
None
):
def
readdir
(
self
,
path
,
fh
=
None
):
path
=
path
.
decode
(
NATIVE_ENCODING
)
path
=
path
.
decode
(
NATIVE_ENCODING
)
entries
=
[
'.'
,
'..'
]
entries
=
[
'.'
,
'..'
]
#print
for
(
nm
,
info
)
in
self
.
fs
.
listdirinfo
(
path
):
#print self.fs
for
(
nm
,
info
)
in
self
.
fs
.
listdirinfo
(
path
):
#print "*", repr(nm), info
self
.
_fill_stat_dict
(
pathjoin
(
path
,
nm
),
info
)
self
.
_fill_stat_dict
(
pathjoin
(
path
,
nm
),
info
)
entries
.
append
((
nm
.
encode
(
NATIVE_ENCODING
),
info
,
0
))
entries
.
append
((
nm
.
encode
(
NATIVE_ENCODING
),
info
,
0
))
#print
return
entries
return
entries
@handle_fs_errors
@handle_fs_errors
...
...
fs/ftpfs.py
View file @
d9986180
This diff is collapsed.
Click to expand it.
fs/opener.py
View file @
d9986180
...
@@ -102,14 +102,12 @@ class OpenerRegistry(object):
...
@@ -102,14 +102,12 @@ class OpenerRegistry(object):
fs_name
=
default_fs_name
or
self
.
default_opener
fs_name
=
default_fs_name
or
self
.
default_opener
fs_url
=
_expand_syspath
(
fs_url
)
fs_url
=
_expand_syspath
(
fs_url
)
path
=
''
path
=
''
fs_name
,
fs_name_params
=
self
.
parse_name
(
fs_name
)
fs_name
,
fs_name_params
=
self
.
parse_name
(
fs_name
)
opener
=
self
.
get_opener
(
fs_name
)
opener
=
self
.
get_opener
(
fs_name
)
if
fs_url
is
None
:
if
fs_url
is
None
:
raise
OpenerError
(
"Unable to parse '
%
s'"
%
orig_url
)
raise
OpenerError
(
"Unable to parse '
%
s'"
%
orig_url
)
fs
,
fs_path
=
opener
.
get_fs
(
self
,
fs_name
,
fs_name_params
,
fs_url
,
writeable
,
create
)
fs
,
fs_path
=
opener
.
get_fs
(
self
,
fs_name
,
fs_name_params
,
fs_url
,
writeable
,
create
)
...
@@ -118,19 +116,14 @@ class OpenerRegistry(object):
...
@@ -118,19 +116,14 @@ class OpenerRegistry(object):
if
pathname
:
if
pathname
:
fs
=
fs
.
opendir
(
pathname
)
fs
=
fs
.
opendir
(
pathname
)
return
fs
,
resourcename
return
fs
,
resourcename
#pathname, resourcename = pathsplit(fs_path or '')
#if pathname and resourcename:
# fs = fs.opendir(pathname)
# fs_path = resourcename
fs_path
=
join
(
fs_path
,
path
)
fs_path
=
join
(
fs_path
,
path
)
pathname
,
resourcename
=
pathsplit
(
fs_path
or
''
)
pathname
,
resourcename
=
pathsplit
(
fs_path
or
''
)
if
pathname
and
resourcename
:
if
pathname
and
resourcename
:
fs
=
fs
.
opendir
(
pathname
)
fs
=
fs
.
opendir
(
pathname
)
fs_path
=
resourcename
fs_path
=
resourcename
return
fs
,
fs_path
return
fs
,
fs_path
def
parse_credentials
(
self
,
url
):
def
parse_credentials
(
self
,
url
):
...
@@ -198,13 +191,10 @@ class ZipOpener(Opener):
...
@@ -198,13 +191,10 @@ class ZipOpener(Opener):
zip_fs
,
zip_path
=
registry
.
parse
(
fs_path
)
zip_fs
,
zip_path
=
registry
.
parse
(
fs_path
)
if
zip_path
is
None
:
if
zip_path
is
None
:
raise
OpenerError
(
'File required for zip opener'
)
raise
OpenerError
(
'File required for zip opener'
)
if
create
:
if
writeable
:
open_mode
=
'wb'
open_mode
=
'r+b'
if
append_zip
:
open_mode
=
'r+b'
else
:
else
:
open_mode
=
'rb'
open_mode
=
'rb'
zip_file
=
zip_fs
.
open
(
zip_path
,
mode
=
open_mode
)
zip_file
=
zip_fs
.
open
(
zip_path
,
mode
=
open_mode
)
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
...
@@ -212,18 +202,12 @@ class ZipOpener(Opener):
...
@@ -212,18 +202,12 @@ class ZipOpener(Opener):
from
fs.zipfs
import
ZipFS
from
fs.zipfs
import
ZipFS
if
zip_file
is
None
:
if
zip_file
is
None
:
zip_file
=
fs_path
zip_file
=
fs_path
if
append_zip
:
mode
=
'r'
if
writeable
:
mode
=
'a'
mode
=
'a'
elif
create
:
mode
=
'w'
else
:
if
writeable
:
mode
=
'w'
else
:
mode
=
'a'
allow_zip_64
=
fs_name
==
'zip64'
allow_zip_64
=
fs_name
.
endswith
(
'64'
)
zipfs
=
ZipFS
(
zip_file
,
mode
=
mode
,
allow_zip_64
=
allow_zip_64
)
zipfs
=
ZipFS
(
zip_file
,
mode
=
mode
,
allow_zip_64
=
allow_zip_64
)
return
zipfs
,
None
return
zipfs
,
None
...
@@ -256,7 +240,7 @@ class FTPOpener(Opener):
...
@@ -256,7 +240,7 @@ class FTPOpener(Opener):
def
get_fs
(
cls
,
registry
,
fs_name
,
fs_name_params
,
fs_path
,
writeable
,
create
):
def
get_fs
(
cls
,
registry
,
fs_name
,
fs_name_params
,
fs_path
,
writeable
,
create
):
from
fs.ftpfs
import
FTPFS
from
fs.ftpfs
import
FTPFS
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
scheme
,
netloc
,
path
,
params
,
query
,
fragment
=
urlparse
(
fs_path
)
scheme
,
netloc
,
path
,
params
,
query
,
fragment
=
urlparse
(
fs_path
)
if
not
scheme
:
if
not
scheme
:
fs_path
=
'ftp://'
+
fs_path
fs_path
=
'ftp://'
+
fs_path
...
@@ -365,7 +349,11 @@ class TempOpener(Opener):
...
@@ -365,7 +349,11 @@ class TempOpener(Opener):
@classmethod
@classmethod
def
get_fs
(
cls
,
registry
,
fs_name
,
fs_name_params
,
fs_path
,
writeable
,
create
):
def
get_fs
(
cls
,
registry
,
fs_name
,
fs_name_params
,
fs_path
,
writeable
,
create
):
from
fs.tempfs
import
TempFS
from
fs.tempfs
import
TempFS
return
TempFS
(
identifier
=
fs_name_params
,
temp_dir
=
fs_path
),
None
fs
=
TempFS
(
identifier
=
fs_name_params
)
if
create
and
fs_path
:
fs
=
fs
.
makeopendir
(
fs_path
)
fs_path
=
pathsplit
(
fs_path
)
return
fs
,
fs_path
opener
=
OpenerRegistry
([
OSFSOpener
,
opener
=
OpenerRegistry
([
OSFSOpener
,
...
@@ -382,7 +370,7 @@ opener = OpenerRegistry([OSFSOpener,
...
@@ -382,7 +370,7 @@ opener = OpenerRegistry([OSFSOpener,
def
main
():
def
main
():
#fs, path = opener.parse('zip:zip://~/zips.zip!t.zip!')
#fs, path = opener.parse('zip:zip://~/zips.zip!t.zip!')
fs
,
path
=
opener
.
parse
(
'
rpc://127.0.0.1/a/*.JPG
'
)
fs
,
path
=
opener
.
parse
(
'
ftp://releases.mozilla.org/welcome.msg
'
)
print
fs
,
path
print
fs
,
path
...
...
fs/path.py
View file @
d9986180
...
@@ -266,6 +266,10 @@ def issamedir(path1, path2):
...
@@ -266,6 +266,10 @@ def issamedir(path1, path2):
"""
"""
return
pathsplit
(
normpath
(
path1
))[
0
]
==
pathsplit
(
normpath
(
path2
))[
0
]
return
pathsplit
(
normpath
(
path1
))[
0
]
==
pathsplit
(
normpath
(
path2
))[
0
]
def
isbase
(
path1
,
path2
):
p1
=
forcedir
(
abspath
(
path1
))
p2
=
forcedir
(
abspath
(
path2
))
return
p1
==
p2
or
p1
.
startswith
(
p2
)
def
isprefix
(
path1
,
path2
):
def
isprefix
(
path1
,
path2
):
"""Return true is path1 is a prefix of path2.
"""Return true is path1 is a prefix of path2.
...
...
fs/rpcfs.py
View file @
d9986180
...
@@ -108,6 +108,7 @@ class RPCFS(FS):
...
@@ -108,6 +108,7 @@ class RPCFS(FS):
self
.
_transport
=
transport
self
.
_transport
=
transport
self
.
proxy
=
self
.
_make_proxy
()
self
.
proxy
=
self
.
_make_proxy
()
FS
.
__init__
(
self
,
thread_synchronize
=
False
)
FS
.
__init__
(
self
,
thread_synchronize
=
False
)
self
.
isdir
(
'/'
)
def
_make_proxy
(
self
):
def
_make_proxy
(
self
):
kwds
=
dict
(
allow_none
=
True
)
kwds
=
dict
(
allow_none
=
True
)
...
...
fs/tempfs.py
View file @
d9986180
...
@@ -39,6 +39,9 @@ class TempFS(OSFS):
...
@@ -39,6 +39,9 @@ class TempFS(OSFS):
default uses "TempFS"
default uses "TempFS"
"""
"""
self
.
identifier
=
identifier
self
.
temp_dir
=
temp_dir
self
.
dir_mode
=
dir_mode
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
,
dir
=
temp_dir
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
identifier
or
"TempFS"
,
dir
=
temp_dir
)
self
.
_cleaned
=
False
self
.
_cleaned
=
False
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
dir_mode
=
dir_mode
,
thread_synchronize
=
thread_synchronize
)
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
dir_mode
=
dir_mode
,
thread_synchronize
=
thread_synchronize
)
...
@@ -50,6 +53,13 @@ class TempFS(OSFS):
...
@@ -50,6 +53,13 @@ class TempFS(OSFS):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
u'<TempFS:
%
s>'
%
self
.
_temp_dir
return
u'<TempFS:
%
s>'
%
self
.
_temp_dir
def
__setstate__
(
self
,
state
):
state
=
super
(
TempFS
,
self
)
.
__setstate__
(
state
)
self
.
_temp_dir
=
tempfile
.
mkdtemp
(
self
.
identifier
or
"TempFS"
,
dir
=
self
.
temp_dir
)
super
(
TempFS
,
self
)
.
__init__
(
self
.
_temp_dir
,
dir_mode
=
self
.
dir_mode
,
thread_synchronize
=
self
.
thread_synchronize
)
def
close
(
self
):
def
close
(
self
):
"""Removes the temporary directory.
"""Removes the temporary directory.
...
...
fs/tests/__init__.py
View file @
d9986180
...
@@ -486,6 +486,7 @@ class FSTestCases(object):
...
@@ -486,6 +486,7 @@ class FSTestCases(object):
makefile
(
"foo/bar/a.txt"
)
makefile
(
"foo/bar/a.txt"
)
self
.
assert_
(
check
(
"foo/bar/a.txt"
))
self
.
assert_
(
check
(
"foo/bar/a.txt"
))
self
.
assert_
(
checkcontents
(
"foo/bar/a.txt"
))
self
.
assert_
(
checkcontents
(
"foo/bar/a.txt"
))
#import rpdb2; rpdb2.start_embedded_debugger('password');
self
.
fs
.
copy
(
"foo/bar/a.txt"
,
"foo/b.txt"
)
self
.
fs
.
copy
(
"foo/bar/a.txt"
,
"foo/b.txt"
)
self
.
assert_
(
check
(
"foo/bar/a.txt"
))
self
.
assert_
(
check
(
"foo/bar/a.txt"
))
self
.
assert_
(
check
(
"foo/b.txt"
))
self
.
assert_
(
check
(
"foo/b.txt"
))
...
...
fs/tests/test_ftpfs.py
View file @
d9986180
...
@@ -32,8 +32,9 @@ class TestFTPFS(unittest.TestCase, FSTestCases, ThreadingTestCases):
...
@@ -32,8 +32,9 @@ class TestFTPFS(unittest.TestCase, FSTestCases, ThreadingTestCases):
self
.
ftp_server
=
subprocess
.
Popen
([
sys
.
executable
,
abspath
(
__file__
),
self
.
temp_dir
,
str
(
use_port
)])
self
.
ftp_server
=
subprocess
.
Popen
([
sys
.
executable
,
abspath
(
__file__
),
self
.
temp_dir
,
str
(
use_port
)])
# Need to sleep to allow ftp server to start
# Need to sleep to allow ftp server to start
time
.
sleep
(
.
1
)
time
.
sleep
(
.
2
)
self
.
fs
=
ftpfs
.
FTPFS
(
'127.0.0.1'
,
'user'
,
'12345'
,
port
=
use_port
,
timeout
=
5.0
)
self
.
fs
=
ftpfs
.
FTPFS
(
'127.0.0.1'
,
'user'
,
'12345'
,
dircache
=
True
,
port
=
use_port
,
timeout
=
5.0
)
self
.
fs
.
cache_hint
(
True
)
def
tearDown
(
self
):
def
tearDown
(
self
):
...
...
fs/utils.py
View file @
d9986180
...
@@ -53,14 +53,23 @@ def copyfile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1
...
@@ -53,14 +53,23 @@ def copyfile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1
FS
.
_shutil_copyfile
(
src_syspath
,
dst_syspath
)
FS
.
_shutil_copyfile
(
src_syspath
,
dst_syspath
)
return
return
src
=
None
src
=
None
dst
=
None
try
:
try
:
# Chunk copy
# Chunk copy
src
=
src_fs
.
open
(
src_path
,
'rb'
)
src
=
src_fs
.
open
(
src_path
,
'rb'
)
dst_fs
.
setcontents
(
dst_path
,
src
,
chunk_size
=
chunk_size
)
dst
=
src_fs
.
open
(
dst_path
,
'wb'
)
write
=
dst
.
write
read
=
src
.
read
chunk
=
read
(
chunk_size
)
while
chunk
:
write
(
chunk
)
chunk
=
read
(
chunk_size
)
finally
:
finally
:
if
src
is
not
None
and
hasattr
(
src
,
'close'
)
:
if
src
is
not
None
:
src
.
close
()
src
.
close
()
if
dst
is
not
None
:
dst
.
close
()
def
movefile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
overwrite
=
True
,
chunk_size
=
64
*
1024
):
def
movefile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
overwrite
=
True
,
chunk_size
=
64
*
1024
):
...
@@ -89,14 +98,23 @@ def movefile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1
...
@@ -89,14 +98,23 @@ def movefile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1
FS
.
_shutil_movefile
(
src_syspath
,
dst_syspath
)
FS
.
_shutil_movefile
(
src_syspath
,
dst_syspath
)
return
return
src
=
None
src
=
None
dst
=
None
try
:
try
:
# Chunk copy
# Chunk copy
src
=
src_fs
.
open
(
src_path
,
'rb'
)
src
=
src_fs
.
open
(
src_path
,
'rb'
)
dst_fs
.
setcontents
(
dst_path
,
src
,
chunk_size
=
chunk_size
)
dst
=
src_fs
.
open
(
dst_path
,
'wb'
)
write
=
dst
.
write
read
=
src
.
read
chunk
=
read
(
chunk_size
)
while
chunk
:
write
(
chunk
)
chunk
=
read
(
chunk_size
)
finally
:
finally
:
if
src
is
not
None
and
hasattr
(
src
,
'close'
)
:
if
src
is
not
None
:
src
.
close
()
src
.
close
()
if
dst
is
not
None
:
dst
.
close
()
src_fs
.
remove
(
src_path
)
src_fs
.
remove
(
src_path
)
...
@@ -416,7 +434,7 @@ def print_fs(fs, path='/', max_levels=5, file_out=None, terminal_colors=None, hi
...
@@ -416,7 +434,7 @@ def print_fs(fs, path='/', max_levels=5, file_out=None, terminal_colors=None, hi
if
is_dir
:
if
is_dir
:
write
(
'
%
s
%
s'
%
(
wrap_prefix
(
prefix
+
'--'
),
wrap_dirname
(
item
)))
write
(
'
%
s
%
s'
%
(
wrap_prefix
(
prefix
+
'--'
),
wrap_dirname
(
item
)))
if
max_levels
is
not
None
and
len
(
levels
)
>=
max_levels
:
if
max_levels
is
not
None
and
len
(
levels
)
+
1
>=
max_levels
:
pass
pass
#write(wrap_prefix(prefix[:-1] + ' ') + wrap_error('max recursion levels reached'))
#write(wrap_prefix(prefix[:-1] + ' ') + wrap_error('max recursion levels reached'))
else
:
else
:
...
...
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