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

Allow accents in file names #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
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 self.args.transcode_names:
for i in archive_list:
print(i.encode(self.args.transcode_names))
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 self.args.transcode_names:
name = name.decode(self.args.transcode_names)
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 self.args.transcode_names:
name = name.decode(self.args.transcode_names)
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 self.args.transcode_names:
name = name.decode(self.args.transcode_names)
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('--transcode-names', metavar='CODEC',
help='encode name to CODEC before sending to Amazon, and decode from CODEC 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