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
42856dfb
Commit
42856dfb
authored
Sep 19, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed fs.py to base.py after all. Added copydir and movedir functions to utils
parent
1fe2212c
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
120 additions
and
16 deletions
+120
-16
fs/__init__.py
+1
-1
fs/browsewin.py
+1
-1
fs/fs.py
+0
-0
fs/helpers.py
+13
-0
fs/memoryfs.py
+2
-2
fs/mountfs.py
+2
-1
fs/multifs.py
+2
-1
fs/objecttree.py
+1
-1
fs/osfs.py
+2
-1
fs/tests.py
+5
-4
fs/utils.py
+89
-3
fs/zipfs.py
+2
-1
No files found.
fs/__init__.py
View file @
42856dfb
...
@@ -7,7 +7,7 @@ __version__ = "0.1.0"
...
@@ -7,7 +7,7 @@ __version__ = "0.1.0"
__author__
=
"Will McGugan (will@willmcgugan.com)"
__author__
=
"Will McGugan (will@willmcgugan.com)"
from
fs
import
*
from
base
import
*
from
helpers
import
*
from
helpers
import
*
__all__
=
[
'memoryfs'
,
__all__
=
[
'memoryfs'
,
'mountfs'
,
'mountfs'
,
...
...
fs/browsewin.py
View file @
42856dfb
...
@@ -11,7 +11,7 @@ Requires wxPython.
...
@@ -11,7 +11,7 @@ Requires wxPython.
import
wx
import
wx
import
wx.gizmos
import
wx.gizmos
import
fs
import
base
as
fs
class
InfoFrame
(
wx
.
Frame
):
class
InfoFrame
(
wx
.
Frame
):
...
...
fs/fs.py
deleted
100644 → 0
View file @
1fe2212c
This diff is collapsed.
Click to expand it.
fs/helpers.py
View file @
42856dfb
...
@@ -2,6 +2,19 @@
...
@@ -2,6 +2,19 @@
from
itertools
import
chain
from
itertools
import
chain
def
_iteratepath
(
path
,
numsplits
=
None
):
path
=
resolvepath
(
path
)
if
not
path
:
return
[]
if
numsplits
==
None
:
return
filter
(
lambda
p
:
bool
(
p
),
path
.
split
(
'/'
))
else
:
return
filter
(
lambda
p
:
bool
(
p
),
path
.
split
(
'/'
,
numsplits
))
def
isabsolutepath
(
path
):
def
isabsolutepath
(
path
):
"""Returns True if a given path is absolute.
"""Returns True if a given path is absolute.
...
...
fs/memoryfs.py
View file @
42856dfb
...
@@ -6,8 +6,8 @@ A filesystem that exists only in memory, which obviously makes it very fast.
...
@@ -6,8 +6,8 @@ A filesystem that exists only in memory, which obviously makes it very fast.
import
os
import
os
import
datetime
import
datetime
from
f
s
import
_iteratepath
from
helper
s
import
_iteratepath
from
fs
import
*
from
base
import
*
try
:
try
:
from
cStringIO
import
StringIO
from
cStringIO
import
StringIO
...
...
fs/mountfs.py
View file @
42856dfb
#!/usr/bin/env python
#!/usr/bin/env python
from
fs
import
*
from
base
import
*
from
objecttree
import
ObjectTree
from
objecttree
import
ObjectTree
from
memoryfs
import
MemoryFS
from
memoryfs
import
MemoryFS
...
@@ -261,6 +261,7 @@ class MountFS(FS):
...
@@ -261,6 +261,7 @@ class MountFS(FS):
self
.
mount_tree
[
path
]
=
MountFS
.
DirMount
(
path
,
fs
)
self
.
mount_tree
[
path
]
=
MountFS
.
DirMount
(
path
,
fs
)
finally
:
finally
:
self
.
_lock
.
release
()
self
.
_lock
.
release
()
mount
=
mountdir
def
mountfile
(
self
,
path
,
open_callable
=
None
,
info_callable
=
None
):
def
mountfile
(
self
,
path
,
open_callable
=
None
,
info_callable
=
None
):
self
.
_lock
.
acquire
()
self
.
_lock
.
acquire
()
...
...
fs/multifs.py
View file @
42856dfb
#!/usr/in/env python
#!/usr/in/env python
from
fs
import
FS
,
FSError
from
base
import
FS
,
FSError
from
helpers
import
*
class
MultiFS
(
FS
):
class
MultiFS
(
FS
):
...
...
fs/objecttree.py
View file @
42856dfb
#!/usr/bin/env python
#!/usr/bin/env python
from
f
s
import
_iteratepath
,
pathsplit
from
helper
s
import
_iteratepath
,
pathsplit
class
_ObjectDict
(
dict
):
class
_ObjectDict
(
dict
):
pass
pass
...
...
fs/osfs.py
View file @
42856dfb
#!/usr/bin/env python
#!/usr/bin/env python
from
fs
import
*
from
base
import
*
from
helpers
import
*
class
OSFS
(
FS
):
class
OSFS
(
FS
):
...
...
fs/tests.py
View file @
42856dfb
#!/usr/bin/env python
#!/usr/bin/env python
import
unittest
import
unittest
import
fs
import
base
as
fs
from
helpers
import
*
from
helpers
import
*
from
helpers
import
_iteratepath
import
shutil
import
shutil
class
TestHelpers
(
unittest
.
TestCase
):
class
TestHelpers
(
unittest
.
TestCase
):
...
@@ -77,11 +78,11 @@ class TestHelpers(unittest.TestCase):
...
@@ -77,11 +78,11 @@ class TestHelpers(unittest.TestCase):
for
path
,
results
in
tests
:
for
path
,
results
in
tests
:
print
repr
(
path
),
results
print
repr
(
path
),
results
for
path_component
,
expected
in
zip
(
fs
.
_iteratepath
(
path
),
results
):
for
path_component
,
expected
in
zip
(
_iteratepath
(
path
),
results
):
self
.
assertEqual
(
path_component
,
expected
)
self
.
assertEqual
(
path_component
,
expected
)
self
.
assertEqual
(
list
(
fs
.
_iteratepath
(
"a/b/c/d"
,
1
)),
[
"a"
,
"b/c/d"
])
self
.
assertEqual
(
list
(
_iteratepath
(
"a/b/c/d"
,
1
)),
[
"a"
,
"b/c/d"
])
self
.
assertEqual
(
list
(
fs
.
_iteratepath
(
"a/b/c/d"
,
2
)),
[
"a"
,
"b"
,
"c/d"
])
self
.
assertEqual
(
list
(
_iteratepath
(
"a/b/c/d"
,
2
)),
[
"a"
,
"b"
,
"c/d"
])
def
test_pathsplit
(
self
):
def
test_pathsplit
(
self
):
tests
=
[
(
"a/b"
,
(
"a"
,
"b"
)),
tests
=
[
(
"a/b"
,
(
"a"
,
"b"
)),
...
...
fs/utils.py
View file @
42856dfb
"""Contains a number of high level utility functions for working with FS objects."""
"""Contains a number of high level utility functions for working with FS objects."""
import
shutil
import
shutil
from
mountfs
import
MountFS
def
copy
_
file
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
chunk_size
=
1024
*
16
):
def
copyfile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
chunk_size
=
1024
*
16
):
"""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.
...
@@ -42,9 +43,94 @@ def copy_file(src_fs, src_path, dst_fs, dst_path, chunk_size=1024*16):
...
@@ -42,9 +43,94 @@ def copy_file(src_fs, src_path, dst_fs, dst_path, chunk_size=1024*16):
if
dst
is
not
None
:
if
dst
is
not
None
:
dst
.
close
()
dst
.
close
()
def
get_total_data
(
count_fs
):
"""Returns the total number of bytes contained within files.
def
movefile
(
src_fs
,
src_path
,
dst_fs
,
dst_path
,
chunk_size
=
1024
*
16
):
"""Move 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.
src_fs -- Source filesystem object
src_path -- Source path
dst_fs -- Destination filesystem object
dst_path -- Destination filesystem object
chunk_size -- Size of chunks to move if system copyfile is not available (default 16K)
"""
src_syspath
=
src_fs
.
getsyspath
(
src_path
,
default
=
""
)
dst_syspath
=
dst_fs
.
getsyspath
(
dst_path
,
default
=
""
)
# System copy if there are two sys paths
if
src_syspath
and
dst_syspath
:
shutil
.
movefile
(
src_syspath
,
dst_syspath
)
return
src
,
dst
=
None
try
:
# Chunk copy
src
=
src_fs
.
open
(
src_path
,
'rb'
)
dst
=
dst_fs
.
open
(
dst_path
,
'wb'
)
while
True
:
chunk
=
src
.
read
(
chunk_size
)
if
not
chunk
:
break
dst
.
write
(
chunk
)
src_fs
.
remove
(
src
)
finally
:
if
src
is
not
None
:
src
.
close
()
if
dst
is
not
None
:
dst
.
close
()
def
movedir
(
fs1
,
fs2
,
ignore_errors
=
False
,
chunk_size
=
16384
):
"""Moves contents of a directory from one filesystem to another.
fs1 -- Source filesystem, or a tuple of (<filesystem>, <directory path>)
fs2 -- Destination filesystem, or a tuple of (<filesystem>, <directory path>)
ignore_errors -- If True, exceptions from file moves are ignored
chunk_size -- Size of chunks to move if a simple copy is used
"""
if
isinstance
(
fs1
,
tuple
):
fs1
,
dir1
=
fs1
fs1
=
fs1
.
opendir
(
dir1
)
if
isinstance
(
fs2
,
tuple
):
fs2
,
dir2
=
fs2
fs2
=
fs1
.
opendir
(
dir2
)
mount_fs
=
MountFS
()
mount_fs
.
mount
(
'dir1'
,
fs1
)
mount_fs
.
mount
(
'dir2'
,
fs2
)
mount_fs
.
movedir
(
'dir1'
,
'dir2'
,
ignore_errors
=
ignore_errors
,
chunk_size
=
chunk_size
)
def
copydir
(
fs1
,
fs2
,
ignore_errors
=
False
,
chunk_size
=
16384
):
"""Copies contents of a directory from one filesystem to another.
fs1 -- Source filesystem, or a tuple of (<filesystem>, <directory path>)
fs2 -- Destination filesystem, or a tuple of (<filesystem>, <directory path>)
ignore_errors -- If True, exceptions from file moves are ignored
chunk_size -- Size of chunks to move if a simple copy is used
"""
if
isinstance
(
fs1
,
tuple
):
fs1
,
dir1
=
fs1
fs1
=
fs1
.
opendir
(
dir1
)
if
isinstance
(
fs2
,
tuple
):
fs2
,
dir2
=
fs2
fs2
=
fs1
.
opendir
(
dir2
)
mount_fs
=
MountFS
()
mount_fs
.
mount
(
'dir1'
,
fs1
)
mount_fs
.
mount
(
'dir2'
,
fs2
)
mount_fs
.
movedir
(
'dir1'
,
'dir2'
,
ignore_errors
=
ignore_errors
,
chunk_size
=
chunk_size
)
def
countbytes
(
count_fs
):
"""Returns the total number of bytes contained within files in a filesystem.
count_fs -- A filesystem object
count_fs -- A filesystem object
...
...
fs/zipfs.py
View file @
42856dfb
#!/usr/bin/env python
#!/usr/bin/env python
from
fs
import
*
from
base
import
*
from
helpers
import
*
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
,
ZIP_STORED
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
,
ZIP_STORED
from
memoryfs
import
MemoryFS
from
memoryfs
import
MemoryFS
...
...
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