Skip to content

Commit

Permalink
allow accents in names of files
Browse files Browse the repository at this point in the history
this will encode name to utf8 before sending
closes: basak#16
  • Loading branch information
xsuchy committed Oct 23, 2013
1 parent b68835c commit b69e18f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions glacier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2012 Robie Basak
#
Expand Down Expand Up @@ -476,7 +477,11 @@ def archive_list(self):
archive_list = list(self.cache.get_archive_list(self.args.vault))

if archive_list:
print(*archive_list, sep="\n")
if args.convert_utf8:
for i in archive_list:
print(i.encode('utf-8'))
else:
print(*archive_list, sep="\n")

def archive_upload(self):
# XXX: "Leading whitespace in archive descriptions is removed."
Expand All @@ -493,6 +498,8 @@ def archive_upload(self):
raise RuntimeError('Archive name not specified. Use --name')
name = os.path.basename(full_name)

if not isinstance(name, unicode) and arg.convert_utf8:
name = name.decode('utf-8')
vault = self.connection.get_vault(self.args.vault)
archive_id = vault.create_archive_from_file(
file_obj=self.args.file, description=name)
Expand Down Expand Up @@ -555,22 +562,24 @@ def archive_retrieve_one(self, name):
complete_job = wait_until_job_completed(retrieval_jobs)
self._archive_retrieve_completed(self.args, complete_job, name)
else:
raise RetryConsoleError('job still pending for archive %r' % name)
raise RetryConsoleError(u'job still pending for archive %s' % name)
else:
# create an archive retrieval job
job = vault.retrieve_archive(archive_id)
if self.args.wait:
wait_until_job_completed([job])
self._archive_retrieve_completed(self.args, job, name)
else:
raise RetryConsoleError('queued retrieval job for archive %r' % name)
raise RetryConsoleError(u"queued retrieval job for archive %s" % name)

def archive_retrieve(self):
if len(self.args.names) > 1 and self.args.output_filename:
raise ConsoleError('cannot specify output filename with multi-archive retrieval')
success_list = []
retry_list = []
for name in self.args.names:
if args.convert_utf8:
name = name.decode('utf-8')
try:
self.archive_retrieve_one(name)
except RetryConsoleError, e:
Expand All @@ -583,13 +592,16 @@ def archive_retrieve(self):

def archive_delete(self):
try:
name = self.args.name
if args.convert_utf8:
name = name.decode('utf-8')
archive_id = self.cache.get_archive_id(
self.args.vault, self.args.name)
self.args.vault, name)
except KeyError:
raise ConsoleError('archive %r not found' % self.args.name)
raise ConsoleError('archive %r not found' % name)
vault = self.connection.get_vault(self.args.vault)
vault.delete_archive(archive_id)
self.cache.delete_archive(self.args.vault, self.args.name)
self.cache.delete_archive(self.args.vault, name)

def archive_checkpresent(self):
try:
Expand Down Expand Up @@ -644,6 +656,8 @@ def too_old(last_seen):
def parse_args(self, args=None):
parser = argparse.ArgumentParser()
parser.add_argument('--region', default='us-east-1')
parser.add_argument('--convert-utf8', action='store_true',
help='encode name to UTF-8 before sending to Amazon, and decode from UTF-8 when retrieving')
subparsers = parser.add_subparsers()
vault_subparser = subparsers.add_parser('vault').add_subparsers()
vault_subparser.add_parser('list').set_defaults(func=self.vault_list)
Expand Down

0 comments on commit b69e18f

Please sign in to comment.