Skip to content
This repository has been archived by the owner on Nov 4, 2018. It is now read-only.

Commit

Permalink
* s3cmd, run-tests.py: Make it work on Windows.
Browse files Browse the repository at this point in the history
git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@297 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed Dec 29, 2008
1 parent cf75d95 commit 9856527
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 27 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2008-12-29 Michal Ludvig <michal@logix.cz>

* s3cmd, run-tests.py: Make it work on Windows.

2008-12-26 Michal Ludvig <michal@logix.cz>

* setup.cfg: Remove explicit install prefix. That should fix
Expand Down
67 changes: 48 additions & 19 deletions run-tests.py
Expand Up @@ -7,6 +7,7 @@
## License: GPL Version 2

import sys
import os
import re
from subprocess import Popen, PIPE, STDOUT

Expand Down Expand Up @@ -76,7 +77,9 @@ def compile_list(_list, regexps = False):

def test_s3cmd(label, cmd_args = [], **kwargs):
if not cmd_args[0].endswith("s3cmd"):
cmd_args.insert(0, "./s3cmd")
cmd_args.insert(0, "python")
cmd_args.insert(1, "s3cmd")

return test(label, cmd_args, **kwargs)

test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'],
Expand All @@ -98,31 +101,56 @@ def test_s3cmd(label, cmd_args = [], **kwargs):
test_s3cmd("Buckets list", ["ls"],
must_find = [ "autotest-1", "autotest-2", "Autotest-3" ], must_not_find_re = "Autotest-EU")

test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt'])
if os.name != "nt":
## Full testsuite - POSIX (Unix, Linux, ...)
test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt'])

test_s3cmd("List bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/unicode/$" ],
must_not_find = [ u"ŪņЇЌœđЗ/☺ unicode € rocks ™" ])

test_s3cmd("List bucket recursive", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5",
u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ],
must_not_find = [ "logo.png" ])

# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])

test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])

test("Removing local target", ['rm', '-rf', 'testsuite-out'])

test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ])

test_s3cmd("Check bucket content (-r)", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
must_find = [ u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ],
must_not_find = [ "logo.png" ])
test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])

test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/unicode/$" ],
must_not_find = [ u"ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])

# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
else:
## Reduced testsuite - Windows NT+
test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--exclude', 'unicode/*', '--no-encrypt'])

test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
test_s3cmd("Check bucket content (-r)", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5" ],
must_not_find = [ "logo.png" ])

test("Removing local target", ['rm', '-rf', 'testsuite-out'])
test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/binary/$" ],
must_not_find = [ u"random-crap.md5" ])

test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])

test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
if os.path.isdir("testsuite-out"):
test("Removing local target", ['rmdir', '/s/q', 'testsuite-out'])

test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])
test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
must_find = [ "stored as testsuite-out/etc/logo.png " ])

## Common for POSIX and Win32
test_s3cmd("Rename within S3", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
must_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ])

Expand All @@ -142,8 +170,9 @@ def test_s3cmd(label, cmd_args = [], **kwargs):
test_s3cmd("Simple delete", ['del', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG deleted" ])

test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ])
if os.name != "nt":
test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ])

test_s3cmd("Recursive delete all", ['del', '--recursive', '--force', 's3://s3cmd-autotest-1'],
must_find_re = [ "Object.*binary/random-crap deleted" ])
Expand Down
29 changes: 21 additions & 8 deletions s3cmd
Expand Up @@ -11,7 +11,6 @@ import time
import os
import re
import errno
import pwd, grp
import glob
import traceback
import codecs
Expand Down Expand Up @@ -325,7 +324,7 @@ def cmd_object_get(args):

for item in remote_keys:
uri = item['remote_uri']
destination = item['local_filename']
destination = item['local_filename']

start_position = 0

Expand Down Expand Up @@ -466,7 +465,7 @@ def _get_filelist_local(local_uri):
loc_base = os.path.join(local_path, "")
filelist = os.walk(local_path)
else:
loc_base = "./"
loc_base = "." + os.path.sep
filelist = [( '.', [], [local_path] )]
loc_base_len = len(loc_base)
loc_list = {}
Expand Down Expand Up @@ -718,7 +717,8 @@ def cmd_sync_remote2local(src, dst):
info(outstr)

def cmd_sync_local2remote(src, dst):
def _build_attr_header(src):
def _build_attr_header(src):
import pwd, grp
attrs = {}
st = os.stat_result(os.stat(src))
for attr in cfg.preserve_attrs_list:
Expand Down Expand Up @@ -789,6 +789,7 @@ def cmd_sync_local2remote(src, dst):
src = loc_list[file]['full_name']
uri = S3Uri(dst_base + file)
seq_label = "[%d of %d]" % (seq, total_count)
attr_header = None
if cfg.preserve_attrs:
attr_header = _build_attr_header(src)
debug(attr_header)
Expand Down Expand Up @@ -1071,10 +1072,13 @@ def main():
default_verbosity = Config().verbosity
optparser = OptionParser(option_class=OptionMimeType, formatter=MyHelpFormatter())
#optparser.disable_interspersed_args()

if os.getenv("HOME"):
optparser.set_defaults(config=os.getenv("HOME")+"/.s3cfg")


if os.getenv("HOME"):
config_file = os.path.join(os.getenv("HOME"), ".s3cfg")
elif os.name == "nt" and os.getenv("USERPROFILE"):
config_file = os.path.join(os.getenv("USERPROFILE"), "Application Data", "s3cmd.ini")

optparser.set_defaults(config=config_file)
optparser.set_defaults(verbosity = default_verbosity)

optparser.add_option( "--configure", dest="run_configure", action="store_true", help="Invoke interactive (re)configuration tool.")
Expand Down Expand Up @@ -1162,6 +1166,15 @@ def main():

## We may need a way to display progress meter on STDERR or somewhere else
Progress._stdout = _stdout

## Unsupported features on Win32 platform
if os.name == "nt":
if cfg.preserve_attrs:
error("Option --preserve is not yet supported on MS Windows platform. Assuming --no-preserve.")
cfg.preserve_attrs = False
if cfg.progress_meter:
error("Option --progress is not yet supported on MS Windows platform. Assuming --no-progress.")
cfg.progress_meter = False

## Update Config with other parameters
for option in cfg.option_list():
Expand Down

0 comments on commit 9856527

Please sign in to comment.