Browse code

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

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@297 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2008/12/29 10:49:10
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+2008-12-29  Michal Ludvig  <michal@logix.cz>
2
+
3
+	* s3cmd, run-tests.py: Make it work on Windows.
4
+
1 5
 2008-12-26  Michal Ludvig  <michal@logix.cz>
2 6
 
3 7
 	* setup.cfg: Remove explicit install prefix. That should fix
... ...
@@ -7,6 +7,7 @@
7 7
 ## License: GPL Version 2
8 8
 
9 9
 import sys
10
+import os
10 11
 import re
11 12
 from subprocess import Popen, PIPE, STDOUT
12 13
 
... ...
@@ -76,7 +77,9 @@ def test(label, cmd_args = [], retcode = 0, must_find = [], must_not_find = [],
76 76
 
77 77
 def test_s3cmd(label, cmd_args = [], **kwargs):
78 78
 	if not cmd_args[0].endswith("s3cmd"):
79
-		cmd_args.insert(0, "./s3cmd")
79
+		cmd_args.insert(0, "python")
80
+		cmd_args.insert(1, "s3cmd")
81
+
80 82
 	return test(label, cmd_args, **kwargs)
81 83
 
82 84
 test_s3cmd("Remove test buckets", ['rb', '-r', 's3://s3cmd-autotest-1', 's3://s3cmd-autotest-2', 's3://s3cmd-Autotest-3'],
... ...
@@ -98,31 +101,56 @@ test_s3cmd("Invalid bucket name", ["mb", "--bucket-location=EU", "s3://s3cmd-Aut
98 98
 test_s3cmd("Buckets list", ["ls"], 
99 99
 	must_find = [ "autotest-1", "autotest-2", "Autotest-3" ], must_not_find_re = "Autotest-EU")
100 100
 
101
-test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt'])
101
+if os.name != "nt":
102
+	## Full testsuite - POSIX (Unix, Linux, ...)
103
+	test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--no-encrypt'])
104
+
105
+	test_s3cmd("List bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
106
+		must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/unicode/$" ],
107
+		must_not_find = [ u"ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
108
+
109
+	test_s3cmd("List bucket recursive", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
110
+		must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5",
111
+		              u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ],
112
+		must_not_find = [ "logo.png" ])
113
+
114
+	# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
115
+
116
+	test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
117
+		must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
118
+
119
+	test("Removing local target", ['rm', '-rf', 'testsuite-out'])
120
+
121
+	test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
122
+		must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
102 123
 
103
-test_s3cmd("Check bucket content (-r)", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
104
-	must_find = [ u"s3://s3cmd-autotest-1/xyz/unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ],
105
-	must_not_find = [ "logo.png" ])
124
+	test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
125
+		must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
106 126
 
107
-test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
108
-	must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/unicode/$" ],
109
-	must_not_find = [ u"ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
127
+	test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])
110 128
 
111
-# test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
129
+else:
130
+	## Reduced testsuite - Windows NT+
131
+	test_s3cmd("Sync to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '.svn/*', '--exclude', '*.png', '--exclude', 'unicode/*', '--no-encrypt'])
112 132
 
113
-test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
114
-	must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
133
+	test_s3cmd("Check bucket content (-r)", ['ls', '--recursive', 's3://s3cmd-autotest-1'],
134
+		must_find = [ u"s3://s3cmd-autotest-1/xyz/binary/random-crap.md5" ],
135
+		must_not_find = [ "logo.png" ])
115 136
 
116
-test("Removing local target", ['rm', '-rf', 'testsuite-out'])
137
+	test_s3cmd("Check bucket content", ['ls', 's3://s3cmd-autotest-1/xyz/'],
138
+		must_find_re = [ u"D s3://s3cmd-autotest-1/xyz/binary/$" ],
139
+		must_not_find = [ u"random-crap.md5" ])
117 140
 
118
-test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
119
-	must_find = [ "stored as testsuite-out/etc/logo.png ", u"unicode/ŪņЇЌœđЗ/☺ unicode € rocks ™" ])
141
+	test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
142
+		must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
120 143
 
121
-test("Retrieve public URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
122
-	must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
144
+	if os.path.isdir("testsuite-out"):
145
+		test("Removing local target", ['rmdir', '/s/q', 'testsuite-out'])
123 146
 
124
-test_s3cmd("Sync more to S3", ['sync', 'testsuite', 's3://s3cmd-autotest-1/xyz/', '--exclude', '*.png', '--no-encrypt'])
147
+	test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
148
+		must_find = [ "stored as testsuite-out/etc/logo.png " ])
125 149
 
150
+## Common for POSIX and Win32
126 151
 test_s3cmd("Rename within S3", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
127 152
 	must_find = [ 'Object s3://s3cmd-autotest-1/xyz/etc/logo.png moved to s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG' ])
128 153
 
... ...
@@ -142,8 +170,9 @@ test_s3cmd("Copy between buckets", ['cp', 's3://s3cmd-autotest-1/xyz/etc2/Logo.P
142 142
 test_s3cmd("Simple delete", ['del', 's3://s3cmd-autotest-1/xyz/etc2/Logo.PNG'],
143 143
 	must_find = [ "Object s3://s3cmd-autotest-1/xyz/etc2/Logo.PNG deleted" ])
144 144
 
145
-test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
146
-	must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ])
145
+if os.name != "nt":
146
+	test_s3cmd("Recursive delete", ['del', '--recursive', 's3://s3cmd-autotest-1/xyz/unicode'],
147
+		must_find_re = [ "Object.*unicode/ŪņЇЌœđЗ/.*deleted" ])
147 148
 
148 149
 test_s3cmd("Recursive delete all", ['del', '--recursive', '--force', 's3://s3cmd-autotest-1'],
149 150
 	must_find_re = [ "Object.*binary/random-crap deleted" ])
... ...
@@ -11,7 +11,6 @@ import time
11 11
 import os
12 12
 import re
13 13
 import errno
14
-import pwd, grp
15 14
 import glob
16 15
 import traceback
17 16
 import codecs
... ...
@@ -325,7 +324,7 @@ def cmd_object_get(args):
325 325
 
326 326
 	for item in remote_keys:
327 327
 		uri = item['remote_uri']
328
-		destination = item['local_filename']
328
+		destination = item['local_filename']
329 329
 
330 330
 		start_position = 0
331 331
 
... ...
@@ -466,7 +465,7 @@ def _get_filelist_local(local_uri):
466 466
 		loc_base = os.path.join(local_path, "")
467 467
 		filelist = os.walk(local_path)
468 468
 	else:
469
-		loc_base = "./"
469
+		loc_base = "." + os.path.sep
470 470
 		filelist = [( '.', [], [local_path] )]
471 471
 	loc_base_len = len(loc_base)
472 472
 	loc_list = {}
... ...
@@ -718,7 +717,8 @@ def cmd_sync_remote2local(src, dst):
718 718
 		info(outstr)
719 719
 
720 720
 def cmd_sync_local2remote(src, dst):
721
-	def _build_attr_header(src):
721
+	def _build_attr_header(src):
722
+		import pwd, grp
722 723
 		attrs = {}
723 724
 		st = os.stat_result(os.stat(src))
724 725
 		for attr in cfg.preserve_attrs_list:
... ...
@@ -789,6 +789,7 @@ def cmd_sync_local2remote(src, dst):
789 789
 		src = loc_list[file]['full_name']
790 790
 		uri = S3Uri(dst_base + file)
791 791
 		seq_label = "[%d of %d]" % (seq, total_count)
792
+		attr_header = None
792 793
 		if cfg.preserve_attrs:
793 794
 			attr_header = _build_attr_header(src)
794 795
 			debug(attr_header)
... ...
@@ -1071,10 +1072,13 @@ def main():
1071 1071
 	default_verbosity = Config().verbosity
1072 1072
 	optparser = OptionParser(option_class=OptionMimeType, formatter=MyHelpFormatter())
1073 1073
 	#optparser.disable_interspersed_args()
1074
-
1075
-	if os.getenv("HOME"):
1076
-		optparser.set_defaults(config=os.getenv("HOME")+"/.s3cfg")
1077
-
1074
+
1075
+	if os.getenv("HOME"):
1076
+		config_file = os.path.join(os.getenv("HOME"), ".s3cfg")
1077
+	elif os.name == "nt" and os.getenv("USERPROFILE"):
1078
+		config_file = os.path.join(os.getenv("USERPROFILE"), "Application Data", "s3cmd.ini")
1079
+
1080
+	optparser.set_defaults(config=config_file)
1078 1081
 	optparser.set_defaults(verbosity = default_verbosity)
1079 1082
 
1080 1083
 	optparser.add_option(      "--configure", dest="run_configure", action="store_true", help="Invoke interactive (re)configuration tool.")
... ...
@@ -1162,6 +1166,15 @@ def main():
1162 1162
 
1163 1163
 	## We may need a way to display progress meter on STDERR or somewhere else
1164 1164
 	Progress._stdout = _stdout
1165
+
1166
+	## Unsupported features on Win32 platform
1167
+	if os.name == "nt":
1168
+		if cfg.preserve_attrs:
1169
+			error("Option --preserve is not yet supported on MS Windows platform. Assuming --no-preserve.")
1170
+			cfg.preserve_attrs = False
1171
+		if cfg.progress_meter:
1172
+			error("Option --progress is not yet supported on MS Windows platform. Assuming --no-progress.")
1173
+			cfg.progress_meter = False
1165 1174
 
1166 1175
 	## Update Config with other parameters
1167 1176
 	for option in cfg.option_list():