summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-11-22 20:41:06 +0000
committerGerrit Code Review <review@openstack.org>2018-11-22 20:41:06 +0000
commit9491dcdae81470b04dae00b102fa59a409b36dc4 (patch)
treee4531fd9952a16cafc942c6ac2ec48ad464964a2
parent92c5348052cb726f6b3931b35ed2d06e369006a1 (diff)
parentbea47d5db293f6845bd9aec10eae3f73d8b69c6e (diff)
Merge "upload-logs-swift: Keep the FileList in the indexer class"
-rw-r--r--roles/upload-logs-swift/library/test_zuul_swift_upload.py18
-rwxr-xr-xroles/upload-logs-swift/library/zuul_swift_upload.py32
2 files changed, 29 insertions, 21 deletions
diff --git a/roles/upload-logs-swift/library/test_zuul_swift_upload.py b/roles/upload-logs-swift/library/test_zuul_swift_upload.py
index 24daf6e..be69c78 100644
--- a/roles/upload-logs-swift/library/test_zuul_swift_upload.py
+++ b/roles/upload-logs-swift/library/test_zuul_swift_upload.py
@@ -156,8 +156,8 @@ class TestFileList(testtools.TestCase):
156 '''Test index generation''' 156 '''Test index generation'''
157 with FileList() as fl: 157 with FileList() as fl:
158 fl.add(os.path.join(FIXTURE_DIR, 'logs')) 158 fl.add(os.path.join(FIXTURE_DIR, 'logs'))
159 ix = Indexer() 159 ix = Indexer(fl)
160 ix.make_indexes(fl) 160 ix.make_indexes()
161 161
162 self.assert_files(fl, [ 162 self.assert_files(fl, [
163 ('', 'application/directory', None), 163 ('', 'application/directory', None),
@@ -207,8 +207,8 @@ class TestFileList(testtools.TestCase):
207 '''Test index generation with a trailing slash''' 207 '''Test index generation with a trailing slash'''
208 with FileList() as fl: 208 with FileList() as fl:
209 fl.add(os.path.join(FIXTURE_DIR, 'logs/')) 209 fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
210 ix = Indexer() 210 ix = Indexer(fl)
211 ix.make_indexes(fl) 211 ix.make_indexes()
212 212
213 self.assert_files(fl, [ 213 self.assert_files(fl, [
214 ('', 'application/directory', None), 214 ('', 'application/directory', None),
@@ -257,9 +257,10 @@ class TestFileList(testtools.TestCase):
257 '''Test index generation creates topdir parent link''' 257 '''Test index generation creates topdir parent link'''
258 with FileList() as fl: 258 with FileList() as fl:
259 fl.add(os.path.join(FIXTURE_DIR, 'logs/')) 259 fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
260 ix = Indexer(create_parent_links=True, 260 ix = Indexer(fl,
261 create_parent_links=True,
261 create_topdir_parent_link=True) 262 create_topdir_parent_link=True)
262 ix.make_indexes(fl) 263 ix.make_indexes()
263 264
264 self.assert_files(fl, [ 265 self.assert_files(fl, [
265 ('', 'application/directory', None), 266 ('', 'application/directory', None),
@@ -311,9 +312,10 @@ class TestFileList(testtools.TestCase):
311 '''Test index generation creates topdir parent link''' 312 '''Test index generation creates topdir parent link'''
312 with FileList() as fl: 313 with FileList() as fl:
313 fl.add(os.path.join(FIXTURE_DIR, 'logs/')) 314 fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
314 ix = Indexer(create_parent_links=False, 315 ix = Indexer(fl,
316 create_parent_links=False,
315 create_topdir_parent_link=False) 317 create_topdir_parent_link=False)
316 ix.make_indexes(fl) 318 ix.make_indexes()
317 319
318 self.assert_files(fl, [ 320 self.assert_files(fl, [
319 ('', 'application/directory', None), 321 ('', 'application/directory', None),
diff --git a/roles/upload-logs-swift/library/zuul_swift_upload.py b/roles/upload-logs-swift/library/zuul_swift_upload.py
index 305a5d3..bac09cc 100755
--- a/roles/upload-logs-swift/library/zuul_swift_upload.py
+++ b/roles/upload-logs-swift/library/zuul_swift_upload.py
@@ -271,27 +271,32 @@ class FileList(Sequence):
271class Indexer(): 271class Indexer():
272 """generates index.html files if requested.""" 272 """generates index.html files if requested."""
273 273
274 def __init__(self, create_parent_links=True, 274 def __init__(self, file_list, create_parent_links=True,
275 create_topdir_parent_link=False, 275 create_topdir_parent_link=False,
276 append_footer='index_footer.html'): 276 append_footer='index_footer.html'):
277 '''
278 Args:
279 file_list (FileList): A FileList object to be updated
280 with index files for each directory.
281 create_parent_links (bool):
282 create_topdir_parent_link (bool):
283 append_footer (str):
284 '''
285 assert isinstance(file_list, FileList)
286 self.file_list = file_list
277 self.create_parent_links = create_parent_links 287 self.create_parent_links = create_parent_links
278 self.create_topdir_parent_link = create_topdir_parent_link 288 self.create_topdir_parent_link = create_topdir_parent_link
279 self.append_footer = append_footer 289 self.append_footer = append_footer
280 self.index_filename = 'index.html' 290 self.index_filename = 'index.html'
281 291
282 def make_indexes(self, file_list): 292 def make_indexes(self):
283 '''Make index files 293 '''Make index files
284 294
285 Args:
286 file_list (FileList): A FileList object to be updated
287 with index files for each directory.
288 Return: 295 Return:
289 No value, the file_list will be updated 296 No value, the self.file_list will be updated
290 ''' 297 '''
291 assert isinstance(file_list, FileList)
292
293 folders = collections.OrderedDict() 298 folders = collections.OrderedDict()
294 for f in file_list: 299 for f in self.file_list:
295 if f.folder: 300 if f.folder:
296 folders[f.relative_path] = [] 301 folders[f.relative_path] = []
297 folder = os.path.dirname(os.path.dirname( 302 folder = os.path.dirname(os.path.dirname(
@@ -325,7 +330,7 @@ class Indexer():
325 # for each directory. 330 # for each directory.
326 new_list = [] 331 new_list = []
327 last_dirname = None 332 last_dirname = None
328 for f in reversed(list(file_list)): 333 for f in reversed(list(self.file_list)):
329 if f.folder: 334 if f.folder:
330 relative_path = f.relative_path + '/' 335 relative_path = f.relative_path + '/'
331 else: 336 else:
@@ -340,7 +345,7 @@ class Indexer():
340 last_dirname = dirname 345 last_dirname = dirname
341 new_list.append(f) 346 new_list.append(f)
342 new_list.reverse() 347 new_list.reverse()
343 file_list.file_list = new_list 348 self.file_list.file_list = new_list
344 349
345 def make_index_file(self, folder_links, title): 350 def make_index_file(self, folder_links, title):
346 """Writes an index into a file for pushing""" 351 """Writes an index into a file for pushing"""
@@ -566,7 +571,8 @@ def run(cloud, container, files,
566 571
567 # Create the objects to make sure the arguments are sound. 572 # Create the objects to make sure the arguments are sound.
568 with FileList() as file_list: 573 with FileList() as file_list:
569 indexer = Indexer(create_parent_links=parent_links, 574 indexer = Indexer(file_list,
575 create_parent_links=parent_links,
570 create_topdir_parent_link=topdir_parent_link, 576 create_topdir_parent_link=topdir_parent_link,
571 append_footer=footer) 577 append_footer=footer)
572 578
@@ -576,7 +582,7 @@ def run(cloud, container, files,
576 582
577 # (Possibly) make indexes. 583 # (Possibly) make indexes.
578 if indexes: 584 if indexes:
579 indexer.make_indexes(file_list) 585 indexer.make_indexes()
580 586
581 logging.debug("List of files prepared to upload:") 587 logging.debug("List of files prepared to upload:")
582 for x in file_list: 588 for x in file_list: