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
f1f224c1
Commit
f1f224c1
authored
Dec 07, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for zip opener
parent
40c775ea
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
38 deletions
+46
-38
fs/commands/fscp.py
+9
-10
fs/commands/runner.py
+8
-6
fs/opener.py
+17
-11
fs/rpcfs.py
+3
-1
fs/zipfs.py
+9
-10
No files found.
fs/commands/fscp.py
View file @
f1f224c1
...
@@ -29,7 +29,7 @@ class FileOpThread(threading.Thread):
...
@@ -29,7 +29,7 @@ class FileOpThread(threading.Thread):
except
queue
.
Empty
:
except
queue
.
Empty
:
continue
continue
try
:
try
:
if
path_type
==
FS
Copy
.
DIR
:
if
path_type
==
FS
cp
.
DIR
:
self
.
dest_fs
.
makedir
(
path
,
recursive
=
True
,
allow_recreate
=
True
)
self
.
dest_fs
.
makedir
(
path
,
recursive
=
True
,
allow_recreate
=
True
)
else
:
else
:
self
.
action
(
fs
,
path
,
self
.
dest_fs
,
dest_path
,
overwrite
=
True
)
self
.
action
(
fs
,
path
,
self
.
dest_fs
,
dest_path
,
overwrite
=
True
)
...
@@ -43,7 +43,7 @@ class FileOpThread(threading.Thread):
...
@@ -43,7 +43,7 @@ class FileOpThread(threading.Thread):
except
Exception
,
e
:
except
Exception
,
e
:
self
.
on_error
(
e
)
self
.
on_error
(
e
)
class
FS
Copy
(
Command
):
class
FS
cp
(
Command
):
DIR
,
FILE
=
0
,
1
DIR
,
FILE
=
0
,
1
...
@@ -54,7 +54,7 @@ Copy SOURCE to DESTINATION"""
...
@@ -54,7 +54,7 @@ Copy SOURCE to DESTINATION"""
return
copyfile
return
copyfile
def
get_optparse
(
self
):
def
get_optparse
(
self
):
optparse
=
super
(
FS
Copy
,
self
)
.
get_optparse
()
optparse
=
super
(
FS
cp
,
self
)
.
get_optparse
()
optparse
.
add_option
(
'-p'
,
'--progress'
,
dest
=
'progress'
,
action
=
"store_true"
,
default
=
False
,
optparse
.
add_option
(
'-p'
,
'--progress'
,
dest
=
'progress'
,
action
=
"store_true"
,
default
=
False
,
help
=
"show progress"
,
metavar
=
"PROGRESS"
)
help
=
"show progress"
,
metavar
=
"PROGRESS"
)
optparse
.
add_option
(
'-t'
,
'--threads'
,
dest
=
'threads'
,
action
=
"store"
,
default
=
1
,
optparse
.
add_option
(
'-t'
,
'--threads'
,
dest
=
'threads'
,
action
=
"store"
,
default
=
1
,
...
@@ -100,8 +100,9 @@ Copy SOURCE to DESTINATION"""
...
@@ -100,8 +100,9 @@ Copy SOURCE to DESTINATION"""
if
src_fs
.
isdir
(
src_path
):
if
src_fs
.
isdir
(
src_path
):
self
.
root_dirs
.
append
((
src_fs
,
src_path
))
self
.
root_dirs
.
append
((
src_fs
,
src_path
))
src_sub_fs
=
src_fs
.
opendir
(
src_path
)
src_sub_fs
=
src_fs
.
opendir
(
src_path
)
for
dir_path
,
file_paths
in
src_sub_fs
.
walk
():
for
dir_path
,
file_paths
in
src_sub_fs
.
walk
():
copy_fs_paths
.
append
((
self
.
DIR
,
src_sub_fs
,
dir_path
,
dir_path
))
if
dir_path
not
in
(
''
,
'/'
):
copy_fs_paths
.
append
((
self
.
DIR
,
src_sub_fs
,
dir_path
,
dir_path
))
sub_fs
=
src_sub_fs
.
opendir
(
dir_path
)
sub_fs
=
src_sub_fs
.
opendir
(
dir_path
)
for
file_path
in
file_paths
:
for
file_path
in
file_paths
:
copy_fs_paths
.
append
((
self
.
FILE
,
sub_fs
,
file_path
,
pathjoin
(
dir_path
,
file_path
)))
copy_fs_paths
.
append
((
self
.
FILE
,
sub_fs
,
file_path
,
pathjoin
(
dir_path
,
file_path
)))
...
@@ -111,8 +112,7 @@ Copy SOURCE to DESTINATION"""
...
@@ -111,8 +112,7 @@ Copy SOURCE to DESTINATION"""
else
:
else
:
self
.
error
(
'
%
s is not a file or directory
\n
'
%
src_path
)
self
.
error
(
'
%
s is not a file or directory
\n
'
%
src_path
)
return
1
return
1
if
self
.
options
.
threads
>
1
:
if
self
.
options
.
threads
>
1
:
copy_fs_dirs
=
[
r
for
r
in
copy_fs_paths
if
r
[
0
]
==
self
.
DIR
]
copy_fs_dirs
=
[
r
for
r
in
copy_fs_paths
if
r
[
0
]
==
self
.
DIR
]
copy_fs_paths
=
[
r
for
r
in
copy_fs_paths
if
r
[
0
]
==
self
.
FILE
]
copy_fs_paths
=
[
r
for
r
in
copy_fs_paths
if
r
[
0
]
==
self
.
FILE
]
...
@@ -150,8 +150,7 @@ Copy SOURCE to DESTINATION"""
...
@@ -150,8 +150,7 @@ Copy SOURCE to DESTINATION"""
# caught until the queue is finished
# caught until the queue is finished
#file_queue.join()
#file_queue.join()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
"!"
options
.
progress
=
False
options
.
progress
=
False
if
self
.
action_error
:
if
self
.
action_error
:
self
.
error
(
self
.
wrap_error
(
unicode
(
self
.
action_error
))
+
'
\n
'
)
self
.
error
(
self
.
wrap_error
(
unicode
(
self
.
action_error
))
+
'
\n
'
)
...
@@ -229,7 +228,7 @@ Copy SOURCE to DESTINATION"""
...
@@ -229,7 +228,7 @@ Copy SOURCE to DESTINATION"""
return
bar
return
bar
def
run
():
def
run
():
return
FS
Copy
()
.
run
()
return
FS
cp
()
.
run
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
sys
.
exit
(
run
())
sys
.
exit
(
run
())
fs/commands/runner.py
View file @
f1f224c1
...
@@ -213,7 +213,7 @@ class Command(object):
...
@@ -213,7 +213,7 @@ class Command(object):
help
=
"make output verbose"
,
metavar
=
"VERBOSE"
)
help
=
"make output verbose"
,
metavar
=
"VERBOSE"
)
return
optparse
return
optparse
def
run
(
self
):
def
run
(
self
):
parser
=
self
.
get_optparse
()
parser
=
self
.
get_optparse
()
options
,
args
=
parser
.
parse_args
()
options
,
args
=
parser
.
parse_args
()
args
=
[
unicode
(
arg
,
sys
.
getfilesystemencoding
())
for
arg
in
args
]
args
=
[
unicode
(
arg
,
sys
.
getfilesystemencoding
())
for
arg
in
args
]
...
@@ -227,13 +227,15 @@ class Command(object):
...
@@ -227,13 +227,15 @@ class Command(object):
if
self
.
is_terminal
():
if
self
.
is_terminal
():
self
.
output
(
"
\n
"
)
self
.
output
(
"
\n
"
)
return
0
return
0
except
ValueError
:
pass
except
SystemExit
:
except
SystemExit
:
return
0
return
0
#
except IOError:
except
IOError
:
#
return 1
return
1
#
except Exception, e:
except
Exception
,
e
:
#
self.error(self.wrap_error('Internal Error - %s\n' % unicode(e)))
self
.
error
(
self
.
wrap_error
(
'Internal Error -
%
s
\n
'
%
unicode
(
e
)))
#
return 1
return
1
...
...
fs/opener.py
View file @
f1f224c1
...
@@ -157,9 +157,9 @@ class ZipOpener(Opener):
...
@@ -157,9 +157,9 @@ class ZipOpener(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
):
create_zip
=
fs_name_params
==
'new'
create_zip
=
fs_name_params
==
'new'
append_zip
=
fs_name_params
==
'append'
zip_file
=
None
zip_file
=
None
if
fs_path
.
startswith
(
'['
):
if
fs_path
.
startswith
(
'['
):
...
@@ -168,27 +168,33 @@ class ZipOpener(Opener):
...
@@ -168,27 +168,33 @@ class ZipOpener(Opener):
raise
OpenerError
(
"Not a file"
)
raise
OpenerError
(
"Not a file"
)
container_mode
=
'r+b'
container_mode
=
'r+b'
if
create_zip
:
if
create_zip
:
container_mode
=
'w+'
container_mode
=
'w+b'
zip_file
=
container_fs
.
open
(
container_path
,
mode
=
container_mode
)
elif
writeable
:
container_mode
=
'w+b'
zip_file
=
container_fs
.
open
(
container_path
,
mode
=
container_mode
)
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
username
,
password
,
fs_path
=
registry
.
parse_credentials
(
fs_path
)
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
create_zip
:
if
append_zip
:
mode
=
'a'
elif
create_zip
or
create
:
mode
=
'w'
mode
=
'w'
else
:
else
:
if
writeable
:
if
writeable
:
mode
=
'
a
'
mode
=
'
w
'
else
:
else
:
mode
=
'
r
'
mode
=
'
a
'
if
fs_name
==
'zip64'
:
if
fs_name
==
'zip64'
:
allow_zip_64
=
True
allow_zip_64
=
True
else
:
else
:
allow_zip_64
=
False
allow_zip_64
=
False
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
return
zipfs
...
@@ -280,7 +286,7 @@ class DebugOpener(Opener):
...
@@ -280,7 +286,7 @@ class DebugOpener(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.wrapfs.debugfs
import
DebugFS
from
fs.wrapfs.debugfs
import
DebugFS
if
fs_path
:
if
fs_path
:
fs
,
path
=
registry
.
parse
(
fs_path
)
fs
,
path
=
registry
.
parse
(
fs_path
,
writeable
=
writeable
,
create
=
create
)
return
DebugFS
(
fs
,
verbose
=
False
)
return
DebugFS
(
fs
,
verbose
=
False
)
if
fs_name_params
==
'ram'
:
if
fs_name_params
==
'ram'
:
from
fs.memoryfs
import
MemoryFS
from
fs.memoryfs
import
MemoryFS
...
...
fs/rpcfs.py
View file @
f1f224c1
...
@@ -20,10 +20,12 @@ from fs.filelike import StringIO
...
@@ -20,10 +20,12 @@ from fs.filelike import StringIO
def
re_raise_faults
(
func
):
def
re_raise_faults
(
func
):
"""Decorator to re-raise XML-RPC faults as proper exceptions."""
"""Decorator to re-raise XML-RPC faults as proper exceptions."""
def
wrapper
(
*
args
,
**
kwds
):
def
wrapper
(
*
args
,
**
kwds
):
try
:
try
:
return
func
(
*
args
,
**
kwds
)
return
func
(
*
args
,
**
kwds
)
except
xmlrpclib
.
Fault
,
f
:
except
xmlrpclib
.
Fault
,
f
:
import
traceback
traceback
.
print_exc
()
# Make sure it's in a form we can handle
# Make sure it's in a form we can handle
bits
=
f
.
faultString
.
split
(
" "
)
bits
=
f
.
faultString
.
split
(
" "
)
if
bits
[
0
]
not
in
[
"<type"
,
"<class"
]:
if
bits
[
0
]
not
in
[
"<type"
,
"<class"
]:
...
...
fs/zipfs.py
View file @
f1f224c1
...
@@ -105,7 +105,7 @@ class ZipFS(FS):
...
@@ -105,7 +105,7 @@ class ZipFS(FS):
raise
ValueError
(
"mode must be 'r', 'w' or 'a'"
)
raise
ValueError
(
"mode must be 'r', 'w' or 'a'"
)
self
.
zip_mode
=
mode
self
.
zip_mode
=
mode
self
.
encoding
=
encoding
self
.
encoding
=
encoding
if
isinstance
(
zip_file
,
basestring
):
if
isinstance
(
zip_file
,
basestring
):
zip_file
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
zip_file
))
zip_file
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
zip_file
))
...
@@ -171,25 +171,25 @@ class ZipFS(FS):
...
@@ -171,25 +171,25 @@ class ZipFS(FS):
self
.
zf
=
_ExceptionProxy
()
self
.
zf
=
_ExceptionProxy
()
@synchronize
@synchronize
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
path
=
normpath
(
relpath
(
path
))
path
=
normpath
(
relpath
(
path
))
if
'r'
in
mode
:
if
'r'
in
mode
:
if
self
.
zip_mode
not
in
'ra'
:
if
self
.
zip_mode
not
in
'ra'
:
raise
OperationFailedError
(
"open file"
,
raise
OperationFailedError
(
"open file"
,
path
=
path
,
path
=
path
,
msg
=
"Zip file must be opened for reading ('r') or appending ('a')"
)
msg
=
"
1
Zip file must be opened for reading ('r') or appending ('a')"
)
try
:
try
:
contents
=
self
.
zf
.
read
(
path
.
encode
(
self
.
encoding
))
contents
=
self
.
zf
.
read
(
path
.
encode
(
self
.
encoding
))
except
KeyError
:
except
KeyError
:
raise
ResourceNotFoundError
(
path
)
raise
ResourceNotFoundError
(
path
)
return
StringIO
(
contents
)
return
StringIO
(
contents
)
if
'w'
in
mode
:
if
'w'
in
mode
:
if
self
.
zip_mode
not
in
'wa'
:
if
self
.
zip_mode
not
in
'wa'
:
raise
OperationFailedError
(
"open file"
,
raise
OperationFailedError
(
"open file"
,
path
=
path
,
path
=
path
,
msg
=
"Zip file must be opened for writing ('w') or appending ('a')"
)
msg
=
"
2
Zip file must be opened for writing ('w') or appending ('a')"
)
dirname
,
filename
=
pathsplit
(
path
)
dirname
,
filename
=
pathsplit
(
path
)
if
dirname
:
if
dirname
:
self
.
temp_fs
.
makedir
(
dirname
,
recursive
=
True
,
allow_recreate
=
True
)
self
.
temp_fs
.
makedir
(
dirname
,
recursive
=
True
,
allow_recreate
=
True
)
...
@@ -211,7 +211,7 @@ class ZipFS(FS):
...
@@ -211,7 +211,7 @@ class ZipFS(FS):
except
KeyError
:
except
KeyError
:
raise
ResourceNotFoundError
(
path
)
raise
ResourceNotFoundError
(
path
)
except
RuntimeError
:
except
RuntimeError
:
raise
OperationFailedError
(
"read file"
,
path
=
path
,
msg
=
"
Zip file must be op
pened with 'r' or 'a' to read"
)
raise
OperationFailedError
(
"read file"
,
path
=
path
,
msg
=
"
3 Zip file must be o
pened with 'r' or 'a' to read"
)
return
contents
return
contents
@synchronize
@synchronize
...
@@ -220,8 +220,7 @@ class ZipFS(FS):
...
@@ -220,8 +220,7 @@ class ZipFS(FS):
self
.
zf
.
write
(
sys_path
,
filename
.
encode
(
self
.
encoding
))
self
.
zf
.
write
(
sys_path
,
filename
.
encode
(
self
.
encoding
))
def
desc
(
self
,
path
):
def
desc
(
self
,
path
):
return
"
%
s in zip file
%
s"
%
(
path
,
self
.
zip_path
)
return
"
%
s in zip file
%
s"
%
(
path
,
self
.
zip_path
)
def
isdir
(
self
,
path
):
def
isdir
(
self
,
path
):
return
self
.
_path_fs
.
isdir
(
path
)
return
self
.
_path_fs
.
isdir
(
path
)
...
@@ -236,7 +235,7 @@ class ZipFS(FS):
...
@@ -236,7 +235,7 @@ class ZipFS(FS):
def
makedir
(
self
,
dirname
,
recursive
=
False
,
allow_recreate
=
False
):
def
makedir
(
self
,
dirname
,
recursive
=
False
,
allow_recreate
=
False
):
dirname
=
normpath
(
dirname
)
dirname
=
normpath
(
dirname
)
if
self
.
zip_mode
not
in
"wa"
:
if
self
.
zip_mode
not
in
"wa"
:
raise
OperationFailedError
(
"create directory"
,
path
=
dirname
,
msg
=
"Zip file must be opened for writing ('w') or appending ('a')"
)
raise
OperationFailedError
(
"create directory"
,
path
=
dirname
,
msg
=
"
4
Zip file must be opened for writing ('w') or appending ('a')"
)
if
not
dirname
.
endswith
(
'/'
):
if
not
dirname
.
endswith
(
'/'
):
dirname
+=
'/'
dirname
+=
'/'
self
.
_add_resource
(
dirname
)
self
.
_add_resource
(
dirname
)
...
...
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