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
0cae6ca1
Commit
0cae6ca1
authored
Feb 27, 2014
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for fs commands in PY3
parent
747c7b9b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
23 deletions
+39
-23
fs/commands/fsls.py
+6
-8
fs/commands/runner.py
+11
-9
fs/utils.py
+3
-6
tox.ini
+19
-0
No files found.
fs/commands/fsls.py
View file @
0cae6ca1
...
@@ -84,7 +84,7 @@ List contents of [PATH]"""
...
@@ -84,7 +84,7 @@ List contents of [PATH]"""
file_paths
=
filter
(
None
,
[
fs
.
getpathurl
(
path
,
allow_none
=
True
)
for
path
in
file_paths
])
file_paths
=
filter
(
None
,
[
fs
.
getpathurl
(
path
,
allow_none
=
True
)
for
path
in
file_paths
])
dirs
=
frozenset
(
dir_paths
)
dirs
=
frozenset
(
dir_paths
)
paths
=
sorted
(
dir_paths
+
file_paths
,
key
=
lambda
p
:
p
.
lower
())
paths
=
sorted
(
dir_paths
+
file_paths
,
key
=
lambda
p
:
p
.
lower
())
if
not
options
.
all
:
if
not
options
.
all
:
paths
=
[
path
for
path
in
paths
if
not
isdotfile
(
path
)]
paths
=
[
path
for
path
in
paths
if
not
isdotfile
(
path
)]
...
@@ -109,6 +109,7 @@ List contents of [PATH]"""
...
@@ -109,6 +109,7 @@ List contents of [PATH]"""
wrap_filename
=
self
.
wrap_filename
wrap_filename
=
self
.
wrap_filename
wrap_dirname
=
self
.
wrap_dirname
wrap_dirname
=
self
.
wrap_dirname
def
wrap
(
path
):
def
wrap
(
path
):
if
path
in
dirs
:
if
path
in
dirs
:
return
wrap_dirname
(
path
.
ljust
(
max_width
))
return
wrap_dirname
(
path
.
ljust
(
max_width
))
...
@@ -125,7 +126,6 @@ List contents of [PATH]"""
...
@@ -125,7 +126,6 @@ List contents of [PATH]"""
return
padded_columns
return
padded_columns
def
condense_columns
(
columns
):
def
condense_columns
(
columns
):
max_column_height
=
max
([
len
(
col
)
for
col
in
columns
])
max_column_height
=
max
([
len
(
col
)
for
col
in
columns
])
lines
=
[[]
for
_
in
xrange
(
max_column_height
)]
lines
=
[[]
for
_
in
xrange
(
max_column_height
)]
...
@@ -147,18 +147,18 @@ List contents of [PATH]"""
...
@@ -147,18 +147,18 @@ List contents of [PATH]"""
smallest_paths
=
min
(
path_widths
)
smallest_paths
=
min
(
path_widths
)
num_paths
=
len
(
paths
)
num_paths
=
len
(
paths
)
num_cols
=
min
(
terminal_width
/
(
smallest_paths
+
2
),
num_paths
)
num_cols
=
min
(
terminal_width
/
/
(
smallest_paths
+
2
),
num_paths
)
while
num_cols
:
while
num_cols
:
col_height
=
(
num_paths
+
num_cols
-
1
)
/
num_cols
col_height
=
(
num_paths
+
num_cols
-
1
)
/
/
num_cols
line_width
=
0
line_width
=
0
for
col_no
in
xrange
(
num_cols
):
for
col_no
in
xrange
(
num_cols
):
try
:
try
:
col_width
=
max
(
path_widths
[
col_no
*
col_height
:
(
col_no
+
1
)
*
col_height
])
col_width
=
max
(
path_widths
[
col_no
*
col_height
:
(
col_no
+
1
)
*
col_height
])
except
ValueError
:
except
ValueError
:
continue
continue
line_width
+=
col_width
line_width
+=
col_width
if
line_width
>
terminal_width
:
if
line_width
>
terminal_width
:
break
;
break
line_width
+=
2
line_width
+=
2
else
:
else
:
if
line_width
-
1
<=
terminal_width
:
if
line_width
-
1
<=
terminal_width
:
...
@@ -173,4 +173,3 @@ def run():
...
@@ -173,4 +173,3 @@ def run():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
sys
.
exit
(
run
())
sys
.
exit
(
run
())
\ No newline at end of file
fs/commands/runner.py
View file @
0cae6ca1
...
@@ -8,7 +8,7 @@ from fs.errors import FSError
...
@@ -8,7 +8,7 @@ from fs.errors import FSError
from
fs.path
import
splitext
,
pathsplit
,
isdotfile
,
iswildcard
from
fs.path
import
splitext
,
pathsplit
,
isdotfile
,
iswildcard
import
platform
import
platform
from
collections
import
defaultdict
from
collections
import
defaultdict
import
re
import
six
if
platform
.
system
()
==
'Windows'
:
if
platform
.
system
()
==
'Windows'
:
...
@@ -76,6 +76,10 @@ class Command(object):
...
@@ -76,6 +76,10 @@ class Command(object):
version
=
''
version
=
''
def
__init__
(
self
,
usage
=
''
,
version
=
''
):
def
__init__
(
self
,
usage
=
''
,
version
=
''
):
if
six
.
PY3
:
self
.
output_file
=
sys
.
stdout
.
buffer
self
.
error_file
=
sys
.
stderr
.
buffer
else
:
self
.
output_file
=
sys
.
stdout
self
.
output_file
=
sys
.
stdout
self
.
error_file
=
sys
.
stderr
self
.
error_file
=
sys
.
stderr
self
.
encoding
=
getattr
(
self
.
output_file
,
'encoding'
,
'utf-8'
)
or
'utf-8'
self
.
encoding
=
getattr
(
self
.
output_file
,
'encoding'
,
'utf-8'
)
or
'utf-8'
...
@@ -210,11 +214,9 @@ class Command(object):
...
@@ -210,11 +214,9 @@ class Command(object):
return
raw_input
(
'
%
s:
%
s '
%
(
self
.
name
,
msg
))
return
raw_input
(
'
%
s:
%
s '
%
(
self
.
name
,
msg
))
def
text_encode
(
self
,
text
):
def
text_encode
(
self
,
text
):
if
not
isinstance
(
text
,
unicode
):
if
not
isinstance
(
text
,
unicode
):
text
=
text
.
decode
(
'ascii'
,
'replace'
)
text
=
text
.
decode
(
'ascii'
,
'replace'
)
text
=
text
.
encode
(
self
.
encoding
,
'replace'
)
text
=
text
.
encode
(
self
.
encoding
,
'replace'
)
return
text
return
text
def
output
(
self
,
msgs
,
verbose
=
False
):
def
output
(
self
,
msgs
,
verbose
=
False
):
...
@@ -226,10 +228,8 @@ class Command(object):
...
@@ -226,10 +228,8 @@ class Command(object):
self
.
output_file
.
write
(
self
.
text_encode
(
msg
))
self
.
output_file
.
write
(
self
.
text_encode
(
msg
))
def
output_table
(
self
,
table
,
col_process
=
None
,
verbose
=
False
):
def
output_table
(
self
,
table
,
col_process
=
None
,
verbose
=
False
):
if
verbose
and
not
self
.
verbose
:
if
verbose
and
not
self
.
verbose
:
return
return
if
col_process
is
None
:
if
col_process
is
None
:
col_process
=
{}
col_process
=
{}
...
@@ -248,7 +248,9 @@ class Command(object):
...
@@ -248,7 +248,9 @@ class Command(object):
td
=
col_process
[
col_no
](
td
)
td
=
col_process
[
col_no
](
td
)
out_col
.
append
(
td
)
out_col
.
append
(
td
)
lines
.
append
(
self
.
text_encode
(
'
%
s
\n
'
%
' '
.
join
(
out_col
)
.
rstrip
()))
lines
.
append
(
self
.
text_encode
(
'
%
s
\n
'
%
' '
.
join
(
out_col
)
.
rstrip
()))
self
.
output
(
''
.
join
(
lines
))
for
l
in
lines
:
self
.
output_file
.
write
(
l
)
#self.output(''.join(lines))
def
error
(
self
,
*
msgs
):
def
error
(
self
,
*
msgs
):
for
msg
in
msgs
:
for
msg
in
msgs
:
...
@@ -275,7 +277,7 @@ class Command(object):
...
@@ -275,7 +277,7 @@ class Command(object):
desc
=
getattr
(
fs_opener
,
'desc'
,
''
)
desc
=
getattr
(
fs_opener
,
'desc'
,
''
)
opener_table
.
append
((
names
,
desc
))
opener_table
.
append
((
names
,
desc
))
opener_table
.
sort
(
key
=
lambda
r
:
r
[
0
])
opener_table
.
sort
(
key
=
lambda
r
:
r
[
0
])
def
wrap_line
(
text
):
def
wrap_line
(
text
):
...
@@ -298,14 +300,13 @@ class Command(object):
...
@@ -298,14 +300,13 @@ class Command(object):
for
names
,
desc
in
opener_table
:
for
names
,
desc
in
opener_table
:
self
.
output
((
'-'
*
self
.
terminal_width
,
'
\n
'
))
self
.
output
((
'-'
*
self
.
terminal_width
,
'
\n
'
))
proto
=
', '
.
join
([
n
+
'://'
for
n
in
names
])
proto
=
', '
.
join
([
n
+
'://'
for
n
in
names
])
self
.
output
((
self
.
wrap_dirname
(
'[
%
s]'
%
proto
),
'
\n\n
'
))
self
.
output
((
self
.
wrap_dirname
(
'[
%
s]'
%
proto
),
'
\n\n
'
))
if
not
desc
.
strip
():
if
not
desc
.
strip
():
desc
=
"No information available"
desc
=
"No information available"
wrap_line
(
desc
)
wrap_line
(
desc
)
self
.
output
(
'
\n
'
)
self
.
output
(
'
\n
'
)
def
run
(
self
):
def
run
(
self
):
parser
=
self
.
get_optparse
()
parser
=
self
.
get_optparse
()
options
,
args
=
parser
.
parse_args
()
options
,
args
=
parser
.
parse_args
()
...
@@ -340,6 +341,7 @@ class Command(object):
...
@@ -340,6 +341,7 @@ class Command(object):
opener
.
add
(
new_opener
)
opener
.
add
(
new_opener
)
if
not
six
.
PY3
:
args
=
[
unicode
(
arg
,
sys
.
getfilesystemencoding
())
for
arg
in
args
]
args
=
[
unicode
(
arg
,
sys
.
getfilesystemencoding
())
for
arg
in
args
]
self
.
verbose
=
options
.
verbose
self
.
verbose
=
options
.
verbose
try
:
try
:
...
...
fs/utils.py
View file @
0cae6ca1
...
@@ -18,15 +18,16 @@ __all__ = ['copyfile',
...
@@ -18,15 +18,16 @@ __all__ = ['copyfile',
'find_duplicates'
,
'find_duplicates'
,
'print_fs'
]
'print_fs'
]
import
os
import
sys
import
sys
import
stat
import
stat
import
six
from
fs.mountfs
import
MountFS
from
fs.mountfs
import
MountFS
from
fs.path
import
pathjoin
from
fs.path
import
pathjoin
from
fs.errors
import
DestinationExistsError
,
RemoveRootError
from
fs.errors
import
DestinationExistsError
,
RemoveRootError
from
fs.base
import
FS
from
fs.base
import
FS
def
copyfile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
overwrite
=
True
,
chunk_size
=
64
*
1024
):
def
copyfile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
overwrite
=
True
,
chunk_size
=
64
*
1024
):
"""Copy a file from one filesystem to another. Will use system copyfile, if both files have a syspath.
"""Copy a file from one filesystem to another. Will use system copyfile, if both files have a syspath.
Otherwise file will be copied a chunk at a time.
Otherwise file will be copied a chunk at a time.
...
@@ -491,7 +492,7 @@ def print_fs(fs,
...
@@ -491,7 +492,7 @@ def print_fs(fs,
terminal_colors
=
hasattr
(
file_out
,
'isatty'
)
and
file_out
.
isatty
()
terminal_colors
=
hasattr
(
file_out
,
'isatty'
)
and
file_out
.
isatty
()
def
write
(
line
):
def
write
(
line
):
file_out
.
write
(
line
.
encode
(
file_encoding
,
'replace'
)
+
'
\n
'
)
file_out
.
write
(
line
.
encode
(
file_encoding
,
'replace'
)
+
b
'
\n
'
)
def
wrap_prefix
(
prefix
):
def
wrap_prefix
(
prefix
):
if
not
terminal_colors
:
if
not
terminal_colors
:
...
@@ -511,11 +512,7 @@ def print_fs(fs,
...
@@ -511,11 +512,7 @@ def print_fs(fs,
def
wrap_filename
(
fname
):
def
wrap_filename
(
fname
):
if
not
terminal_colors
:
if
not
terminal_colors
:
return
fname
return
fname
# if '.' in fname:
# name, ext = os.path.splitext(fname)
# fname = '%s\x1b[36m%s\x1b[0m' % (name, ext)
if
fname
.
startswith
(
'.'
):
if
fname
.
startswith
(
'.'
):
#fname = '\x1b[2m%s\x1b[0m' % fname
fname
=
'
\x1b
[33m
%
s
\x1b
[0m'
%
fname
fname
=
'
\x1b
[33m
%
s
\x1b
[0m'
%
fname
return
fname
return
fname
dircount
=
[
0
]
dircount
=
[
0
]
...
...
tox.ini
View file @
0cae6ca1
...
@@ -15,6 +15,16 @@ changedir=.tox
...
@@ -15,6 +15,16 @@ changedir=.tox
commands
=
nosetests fs.tests -v
\
commands
=
nosetests fs.tests -v
\
[]
[]
[testenv:py31]
commands
=
nosetests fs.tests -v
\
[]
deps
=
distribute
six
dexml
nose
winpdb
[testenv:py32]
[testenv:py32]
commands
=
nosetests fs.tests -v
\
commands
=
nosetests fs.tests -v
\
[]
[]
...
@@ -24,3 +34,12 @@ deps = distribute
...
@@ -24,3 +34,12 @@ deps = distribute
nose
nose
winpdb
winpdb
[testenv:py33]
commands
=
nosetests fs.tests -v
\
[]
deps
=
distribute
six
dexml
nose
winpdb
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