Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cf.move(s), cf.touch methods and cli mv, touch commands #107

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
CHANGES
=======

* fix: add drop table stats
* perf: add in stats table for faster xfer performance
* feat: import improvements to ResumableFileSet from transcoder
* fix: release in xfer
* fix: leasing was broken
* feat: add middleauth+https paths indicate CAVE interface (#106)

4.26.0
------

* feat: make it possible to normalize e.g. zarr2://./helloworld
* feat: add all current neuroglancer formats to parsing list

4.25.0
------

* feat: list for apache servers (#104)

4.24.2
------

* feat: add size operator to CloudFiles for HTTP interface

4.24.1
------

* fix: close unused connections for HTTP interface

4.24.0
------

* fix: check for 404 and use proper key variable
* test: modify dne test
* docs: update authors, changelog
* feat: add support for allow\_missing to interfaces
* test: check to see if allow\_missing works
* feat: add allow\_missing to transfer\_to/from

4.23.0
------

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ cf.delete(paths, parallel=2) # threaded + two processes
boolean = cf.exists('filename')
results = cf.exists([ 'filename_1', ... ]) # threaded

cf.move("a", "gs://bucket/b")
cf.moves("gs://bucket/", [ ("a", "b") ])

cf.touch("example")
cf.touch([ "example", "example2" ])

# for single files
cf = CloudFile("gs://bucket/file1")
info = cf.head()
Expand Down Expand Up @@ -414,6 +420,10 @@ cloudfiles -p 2 cp --progress -r s3://bkt/ gs://bkt2/
cloudfiles cp -c br s3://bkt/file.txt gs://bkt2/
# decompress
cloudfiles cp -c none s3://bkt/file.txt gs://bkt2/
# move or rename files
cloudfiles mv s3://bkt/file.txt gs://bkt2/
# create an empty file if not existing
cloudfiles touch s3://bkt/empty.txt
# pass from stdin (use "-" for source argument)
find some_dir | cloudfiles cp - s3://bkt/
# resumable transfers
Expand Down
89 changes: 89 additions & 0 deletions automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,92 @@ def test_lock_clearing():
assert len(lst) == 0


@pytest.mark.parametrize("protocol", ('mem', 'file', 's3'))
def test_move(s3, protocol):
from cloudfiles import CloudFiles

url = compute_url(protocol, "move")

cf = CloudFiles(url)
cf.puts([
('hello', b'world'),
('lamp', b'emporium'),
])
cf.move("hello", f"{url}/hola")

assert all(cf.exists(["hola"]).values()) == True
assert all(cf.exists(["hello"]).values()) == False

cf.puts([
('hello', b'world'),
('lamp', b'emporium'),
])

cf.delete("hola")

cf.moves(f"{url}", [
("hello", f"hola"),
("lamp", f"lampara"),
])

assert all(cf.exists(["hola", "lampara"]).values()) == True
assert all(cf.exists(["hello", "lamp"]).values()) == False

cf.delete([ "hola", "hello", "lamp", "lampara" ])

@pytest.mark.parametrize("protocol", ["file", "s3"])
def test_cli_move_python(s3, protocol):
from cloudfiles_cli.cloudfiles_cli import _mv_single
from cloudfiles import CloudFiles, exceptions

test_dir = compute_url(protocol, "cli_mv_python")
test_dir2 = compute_url(protocol, "cli_mv_python2")
cf = CloudFiles(test_dir)

N = 100

def mkfiles():
cf.delete(cf.list())
for i in range(N):
cf[str(i)] = b"hello world"

def run_mv(src, dest):
_mv_single(
src, dest,
progress=False, block_size=5,
part_bytes=int(100e6), no_sign_request=True,
parallel=1
)

mkfiles()
run_mv(test_dir, test_dir2)
assert sorted(list(cf)) == []

cf2 = CloudFiles(test_dir2)
print(sorted(list(cf2)))
assert sorted(list(cf2)) == sorted([ f'{i}' for i in range(N) ])

mkfiles()
run_mv(f"{test_dir}/*", f"{test_dir}/move/")
assert sorted(list(cf.list(prefix="move"))) == sorted([ f'move/{i}' for i in range(N) ])

mkfiles()
run_mv(f"{test_dir}/1", f"{test_dir}/move/1")
assert cf.exists("move/1") == True
assert cf.exists("1") == False

@pytest.mark.parametrize("protocol", ["file", "mem", "s3"])
def test_touch(s3, protocol):
from cloudfiles import CloudFiles

url = compute_url(protocol, "touch")

cf = CloudFiles(url)

cf.touch([ str(i) for i in range(20) ])

assert sorted(list(cf)) == sorted([ str(i) for i in range(20) ])

cf.touch([ str(i) for i in range(20) ])

assert sorted(list(cf)) == sorted([ str(i) for i in range(20) ])
Loading
Loading