26
26
27
27
from __future__ import print_function
28
28
import boto3
29
+ import six
30
+ import sys
29
31
import os
30
32
import errno
31
33
import sys
44
46
log = logging .getLogger ('bigstash.upload' )
45
47
46
48
49
+ def smart_str (s ):
50
+ if isinstance (s , six .text_type ):
51
+ return s
52
+ return s .decode ('utf-8' )
53
+
54
+
47
55
class ProgressPercentage (object ):
48
56
def __init__ (self , filename ):
49
- self ._filename = filename
57
+ self ._filename = smart_str ( filename )
50
58
self ._size = os .path .getsize (filename )
51
59
self ._seen_so_far = 0
52
60
self ._lock = threading .Lock ()
@@ -55,7 +63,7 @@ def _write_progress(self, wrote, total):
55
63
percentage = 100
56
64
if total > 0 :
57
65
percentage = (wrote / float (total )) * 100
58
- sys .stdout .write ("\r {} {} / {} ({:.2f}%)" .format (
66
+ sys .stdout .write (u "\r {} {} / {} ({:.2f}%)" .format (
59
67
self ._filename , wrote , total , percentage ))
60
68
sys .stdout .flush ()
61
69
@@ -72,7 +80,12 @@ def __call__(self, bytes_amount):
72
80
73
81
74
82
def main ():
75
- args = docopt (__doc__ , version = __version__ )
83
+ argv = sys .argv
84
+ if not six .PY3 and os .name == 'nt' :
85
+ from BigStash .winargvfix import fix_argv_on_windows , fix_env_on_windows
86
+ argv = fix_argv_on_windows ()
87
+ fix_env_on_windows ()
88
+ args = docopt (__doc__ , argv = argv [1 :], version = __version__ )
76
89
77
90
settings = BigStashAPISettings .load_settings ()
78
91
BigStashAPI .setup_logging (settings )
@@ -145,15 +158,12 @@ def bgst_settings(args, settings):
145
158
146
159
def bgst_put (args , settings ):
147
160
try :
148
-
149
161
title = args ['--title' ] if args ['--title' ] else None
150
162
opt_silent = False if not args ['--silent' ] else True
151
163
opt_dont_wait = False if not args ['--dont-wait' ] else True
152
164
upload = None
153
- manifest , errors = Manifest .from_paths (
154
- paths = [f .decode ('utf-8' ) for f in args ['FILES' ]],
155
- title = title
156
- )
165
+ filepaths = map (smart_str , args ['FILES' ])
166
+ manifest , errors = Manifest .from_paths (paths = filepaths , title = title )
157
167
if errors :
158
168
errtext = [": " .join (e ) for e in errors ]
159
169
print ("\n " .join (["There were errors:" ] + errtext ))
0 commit comments