Browse Source

Merge "upload-logs-swift: Keep the FileList in the indexer class"

Zuul 5 months ago
parent
commit
9491dcdae8

+ 10
- 8
roles/upload-logs-swift/library/test_zuul_swift_upload.py View File

@@ -156,8 +156,8 @@ class TestFileList(testtools.TestCase):
156 156
         '''Test index generation'''
157 157
         with FileList() as fl:
158 158
             fl.add(os.path.join(FIXTURE_DIR, 'logs'))
159
-            ix = Indexer()
160
-            ix.make_indexes(fl)
159
+            ix = Indexer(fl)
160
+            ix.make_indexes()
161 161
 
162 162
             self.assert_files(fl, [
163 163
                 ('', 'application/directory', None),
@@ -207,8 +207,8 @@ class TestFileList(testtools.TestCase):
207 207
         '''Test index generation with a trailing slash'''
208 208
         with FileList() as fl:
209 209
             fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
210
-            ix = Indexer()
211
-            ix.make_indexes(fl)
210
+            ix = Indexer(fl)
211
+            ix.make_indexes()
212 212
 
213 213
             self.assert_files(fl, [
214 214
                 ('', 'application/directory', None),
@@ -257,9 +257,10 @@ class TestFileList(testtools.TestCase):
257 257
         '''Test index generation creates topdir parent link'''
258 258
         with FileList() as fl:
259 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 262
                          create_topdir_parent_link=True)
262
-            ix.make_indexes(fl)
263
+            ix.make_indexes()
263 264
 
264 265
             self.assert_files(fl, [
265 266
                 ('', 'application/directory', None),
@@ -311,9 +312,10 @@ class TestFileList(testtools.TestCase):
311 312
         '''Test index generation creates topdir parent link'''
312 313
         with FileList() as fl:
313 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 317
                          create_topdir_parent_link=False)
316
-            ix.make_indexes(fl)
318
+            ix.make_indexes()
317 319
 
318 320
             self.assert_files(fl, [
319 321
                 ('', 'application/directory', None),

+ 19
- 13
roles/upload-logs-swift/library/zuul_swift_upload.py View File

@@ -271,27 +271,32 @@ class FileList(Sequence):
271 271
 class Indexer():
272 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 275
                  create_topdir_parent_link=False,
276 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 287
         self.create_parent_links = create_parent_links
278 288
         self.create_topdir_parent_link = create_topdir_parent_link
279 289
         self.append_footer = append_footer
280 290
         self.index_filename = 'index.html'
281 291
 
282
-    def make_indexes(self, file_list):
292
+    def make_indexes(self):
283 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 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 298
         folders = collections.OrderedDict()
294
-        for f in file_list:
299
+        for f in self.file_list:
295 300
             if f.folder:
296 301
                 folders[f.relative_path] = []
297 302
                 folder = os.path.dirname(os.path.dirname(
@@ -325,7 +330,7 @@ class Indexer():
325 330
         # for each directory.
326 331
         new_list = []
327 332
         last_dirname = None
328
-        for f in reversed(list(file_list)):
333
+        for f in reversed(list(self.file_list)):
329 334
             if f.folder:
330 335
                 relative_path = f.relative_path + '/'
331 336
             else:
@@ -340,7 +345,7 @@ class Indexer():
340 345
                     last_dirname = dirname
341 346
             new_list.append(f)
342 347
         new_list.reverse()
343
-        file_list.file_list = new_list
348
+        self.file_list.file_list = new_list
344 349
 
345 350
     def make_index_file(self, folder_links, title):
346 351
         """Writes an index into a file for pushing"""
@@ -566,7 +571,8 @@ def run(cloud, container, files,
566 571
 
567 572
     # Create the objects to make sure the arguments are sound.
568 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 576
                           create_topdir_parent_link=topdir_parent_link,
571 577
                           append_footer=footer)
572 578
 
@@ -576,7 +582,7 @@ def run(cloud, container, files,
576 582
 
577 583
         # (Possibly) make indexes.
578 584
         if indexes:
579
-            indexer.make_indexes(file_list)
585
+            indexer.make_indexes()
580 586
 
581 587
         logging.debug("List of files prepared to upload:")
582 588
         for x in file_list:

Loading…
Cancel
Save