From e52bb012805b6bcd01cb7f4a7e2f20f2bf2eab6e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 17 Aug 2018 11:31:21 +1000 Subject: [PATCH] upload-logs-swift: Use collections Sequence for FileList This is implementing a Sequence, so let's use the ABC template Change-Id: I45d06fa94b20734bb423c12e0e177ea8a6f87218 --- .../library/zuul_swift_upload.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/roles/upload-logs-swift/library/zuul_swift_upload.py b/roles/upload-logs-swift/library/zuul_swift_upload.py index ad1d1a629..5c1ca25bf 100755 --- a/roles/upload-logs-swift/library/zuul_swift_upload.py +++ b/roles/upload-logs-swift/library/zuul_swift_upload.py @@ -37,12 +37,18 @@ import time import zlib import collections -from ansible.module_utils.basic import AnsibleModule import openstack import requests import requests.exceptions import requestsexceptions +from ansible.module_utils.basic import AnsibleModule + +try: + # Python 3.3+ + from collections.abc import Sequence +except ImportError: + from collections import Sequence mimetypes.init() mimetypes.add_type('text/plain', '.yaml') @@ -175,16 +181,16 @@ class FileDetail(): return '<%s %s>' % (t, self.relative_path) -class FileList(): +class FileList(Sequence): def __init__(self): self.file_list = [] self.file_list.append(FileDetail(None, '', '')) - def __iter__(self): - return iter(self.file_list) + def __getitem__(self, item): + return self.file_list.__getitem__(item) def __len__(self): - return len(self.file_list) + return self.file_list.__len__() @staticmethod def _path_in_tree(root, path):