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):
except
queue
.
Empty
:
continue
try
:
if
path_type
==
FS
Copy
.
DIR
:
if
path_type
==
FS
cp
.
DIR
:
self
.
dest_fs
.
makedir
(
path
,
recursive
=
True
,
allow_recreate
=
True
)
else
:
self
.
action
(
fs
,
path
,
self
.
dest_fs
,
dest_path
,
overwrite
=
True
)
...
...
@@ -43,7 +43,7 @@ class FileOpThread(threading.Thread):
except
Exception
,
e
:
self
.
on_error
(
e
)
class
FS
Copy
(
Command
):
class
FS
cp
(
Command
):
DIR
,
FILE
=
0
,
1
...
...
@@ -54,7 +54,7 @@ Copy SOURCE to DESTINATION"""
return
copyfile
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
,
help
=
"show progress"
,
metavar
=
"PROGRESS"
)
optparse
.
add_option
(
'-t'
,
'--threads'
,
dest
=
'threads'
,
action
=
"store"
,
default
=
1
,
...
...
@@ -100,8 +100,9 @@ Copy SOURCE to DESTINATION"""
if
src_fs
.
isdir
(
src_path
):
self
.
root_dirs
.
append
((
src_fs
,
src_path
))
src_sub_fs
=
src_fs
.
opendir
(
src_path
)
for
dir_path
,
file_paths
in
src_sub_fs
.
walk
():
copy_fs_paths
.
append
((
self
.
DIR
,
src_sub_fs
,
dir_path
,
dir_path
))
for
dir_path
,
file_paths
in
src_sub_fs
.
walk
():
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
)
for
file_path
in
file_paths
:
copy_fs_paths
.
append
((
self
.
FILE
,
sub_fs
,
file_path
,
pathjoin
(
dir_path
,
file_path
)))
...
...
@@ -111,8 +112,7 @@ Copy SOURCE to DESTINATION"""
else
:
self
.
error
(
'
%
s is not a file or directory
\n
'
%
src_path
)
return
1
if
self
.
options
.
threads
>
1
:
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
]
...
...
@@ -150,8 +150,7 @@ Copy SOURCE to DESTINATION"""
# caught until the queue is finished
#file_queue.join()
except
KeyboardInterrupt
:
print
"!"
except
KeyboardInterrupt
:
options
.
progress
=
False
if
self
.
action_error
:
self
.
error
(
self
.
wrap_error
(
unicode
(
self
.
action_error
))
+
'
\n
'
)
...
...
@@ -229,7 +228,7 @@ Copy SOURCE to DESTINATION"""
return
bar
def
run
():
return
FS
Copy
()
.
run
()
return
FS
cp
()
.
run
()
if
__name__
==
"__main__"
:
sys
.
exit
(
run
())
fs/commands/runner.py
View file @
f1f224c1
...
...
@@ -213,7 +213,7 @@ class Command(object):
help
=
"make output verbose"
,
metavar
=
"VERBOSE"
)
return
optparse
def
run
(
self
):
def
run
(
self
):
parser
=
self
.
get_optparse
()
options
,
args
=
parser
.
parse_args
()
args
=
[
unicode
(
arg
,
sys
.
getfilesystemencoding
())
for
arg
in
args
]
...
...
@@ -227,13 +227,15 @@ class Command(object):
if
self
.
is_terminal
():
self
.
output
(
"
\n
"
)
return
0
except
ValueError
:
pass
except
SystemExit
:
return
0
#
except IOError:
#
return 1
#
except Exception, e:
#
self.error(self.wrap_error('Internal Error - %s\n' % unicode(e)))
#
return 1
except
IOError
:
return
1
except
Exception
,
e
:
self
.
error
(
self
.
wrap_error
(
'Internal Error -
%
s
\n
'
%
unicode
(
e
)))
return
1
...
...
fs/opener.py
View file @
f1f224c1
...
...
@@ -157,9 +157,9 @@ class ZipOpener(Opener):
@classmethod
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
if
fs_path
.
startswith
(
'['
):
...
...
@@ -168,27 +168,33 @@ class ZipOpener(Opener):
raise
OpenerError
(
"Not a file"
)
container_mode
=
'r+b'
if
create_zip
:
container_mode
=
'w+'
zip_file
=
container_fs
.
open
(
container_path
,
mode
=
container_mode
)
container_mode
=
'w+b'
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
)
from
fs.zipfs
import
ZipFS
if
zip_file
is
None
:
zip_file
=
fs_path
if
create_zip
:
if
append_zip
:
mode
=
'a'
elif
create_zip
or
create
:
mode
=
'w'
else
:
if
writeable
:
mode
=
'
a
'
mode
=
'
w
'
else
:
mode
=
'
r
'
mode
=
'
a
'
if
fs_name
==
'zip64'
:
allow_zip_64
=
True
else
:
allow_zip_64
=
False
allow_zip_64
=
False
zipfs
=
ZipFS
(
zip_file
,
mode
=
mode
,
allow_zip_64
=
allow_zip_64
)
return
zipfs
...
...
@@ -280,7 +286,7 @@ class DebugOpener(Opener):
def
get_fs
(
cls
,
registry
,
fs_name
,
fs_name_params
,
fs_path
,
writeable
,
create
):
from
fs.wrapfs.debugfs
import
DebugFS
if
fs_path
:
fs
,
path
=
registry
.
parse
(
fs_path
)
fs
,
path
=
registry
.
parse
(
fs_path
,
writeable
=
writeable
,
create
=
create
)
return
DebugFS
(
fs
,
verbose
=
False
)
if
fs_name_params
==
'ram'
:
from
fs.memoryfs
import
MemoryFS
...
...
fs/rpcfs.py
View file @
f1f224c1
...
...
@@ -20,10 +20,12 @@ from fs.filelike import StringIO
def
re_raise_faults
(
func
):
"""Decorator to re-raise XML-RPC faults as proper exceptions."""
def
wrapper
(
*
args
,
**
kwds
):
def
wrapper
(
*
args
,
**
kwds
):
try
:
return
func
(
*
args
,
**
kwds
)
except
xmlrpclib
.
Fault
,
f
:
import
traceback
traceback
.
print_exc
()
# Make sure it's in a form we can handle
bits
=
f
.
faultString
.
split
(
" "
)
if
bits
[
0
]
not
in
[
"<type"
,
"<class"
]:
...
...
fs/zipfs.py
View file @
f1f224c1
...
...
@@ -105,7 +105,7 @@ class ZipFS(FS):
raise
ValueError
(
"mode must be 'r', 'w' or 'a'"
)
self
.
zip_mode
=
mode
self
.
encoding
=
encoding
self
.
encoding
=
encoding
if
isinstance
(
zip_file
,
basestring
):
zip_file
=
os
.
path
.
expanduser
(
os
.
path
.
expandvars
(
zip_file
))
...
...
@@ -171,25 +171,25 @@ class ZipFS(FS):
self
.
zf
=
_ExceptionProxy
()
@synchronize
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
def
open
(
self
,
path
,
mode
=
"r"
,
**
kwargs
):
path
=
normpath
(
relpath
(
path
))
if
'r'
in
mode
:
if
self
.
zip_mode
not
in
'ra'
:
raise
OperationFailedError
(
"open file"
,
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
:
contents
=
self
.
zf
.
read
(
path
.
encode
(
self
.
encoding
))
except
KeyError
:
raise
ResourceNotFoundError
(
path
)
return
StringIO
(
contents
)
if
'w'
in
mode
:
if
self
.
zip_mode
not
in
'wa'
:
if
'w'
in
mode
:
if
self
.
zip_mode
not
in
'wa'
:
raise
OperationFailedError
(
"open file"
,
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
)
if
dirname
:
self
.
temp_fs
.
makedir
(
dirname
,
recursive
=
True
,
allow_recreate
=
True
)
...
...
@@ -211,7 +211,7 @@ class ZipFS(FS):
except
KeyError
:
raise
ResourceNotFoundError
(
path
)
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
@synchronize
...
...
@@ -220,8 +220,7 @@ class ZipFS(FS):
self
.
zf
.
write
(
sys_path
,
filename
.
encode
(
self
.
encoding
))
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
):
return
self
.
_path_fs
.
isdir
(
path
)
...
...
@@ -236,7 +235,7 @@ class ZipFS(FS):
def
makedir
(
self
,
dirname
,
recursive
=
False
,
allow_recreate
=
False
):
dirname
=
normpath
(
dirname
)
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
(
'/'
):
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