Merge "upload-logs-swift: Keep the FileList in the indexer class"
This commit is contained in:
commit
9491dcdae8
@ -156,8 +156,8 @@ class TestFileList(testtools.TestCase):
|
|||||||
'''Test index generation'''
|
'''Test index generation'''
|
||||||
with FileList() as fl:
|
with FileList() as fl:
|
||||||
fl.add(os.path.join(FIXTURE_DIR, 'logs'))
|
fl.add(os.path.join(FIXTURE_DIR, 'logs'))
|
||||||
ix = Indexer()
|
ix = Indexer(fl)
|
||||||
ix.make_indexes(fl)
|
ix.make_indexes()
|
||||||
|
|
||||||
self.assert_files(fl, [
|
self.assert_files(fl, [
|
||||||
('', 'application/directory', None),
|
('', 'application/directory', None),
|
||||||
@ -207,8 +207,8 @@ class TestFileList(testtools.TestCase):
|
|||||||
'''Test index generation with a trailing slash'''
|
'''Test index generation with a trailing slash'''
|
||||||
with FileList() as fl:
|
with FileList() as fl:
|
||||||
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
||||||
ix = Indexer()
|
ix = Indexer(fl)
|
||||||
ix.make_indexes(fl)
|
ix.make_indexes()
|
||||||
|
|
||||||
self.assert_files(fl, [
|
self.assert_files(fl, [
|
||||||
('', 'application/directory', None),
|
('', 'application/directory', None),
|
||||||
@ -257,9 +257,10 @@ class TestFileList(testtools.TestCase):
|
|||||||
'''Test index generation creates topdir parent link'''
|
'''Test index generation creates topdir parent link'''
|
||||||
with FileList() as fl:
|
with FileList() as fl:
|
||||||
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
||||||
ix = Indexer(create_parent_links=True,
|
ix = Indexer(fl,
|
||||||
|
create_parent_links=True,
|
||||||
create_topdir_parent_link=True)
|
create_topdir_parent_link=True)
|
||||||
ix.make_indexes(fl)
|
ix.make_indexes()
|
||||||
|
|
||||||
self.assert_files(fl, [
|
self.assert_files(fl, [
|
||||||
('', 'application/directory', None),
|
('', 'application/directory', None),
|
||||||
@ -311,9 +312,10 @@ class TestFileList(testtools.TestCase):
|
|||||||
'''Test index generation creates topdir parent link'''
|
'''Test index generation creates topdir parent link'''
|
||||||
with FileList() as fl:
|
with FileList() as fl:
|
||||||
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
fl.add(os.path.join(FIXTURE_DIR, 'logs/'))
|
||||||
ix = Indexer(create_parent_links=False,
|
ix = Indexer(fl,
|
||||||
|
create_parent_links=False,
|
||||||
create_topdir_parent_link=False)
|
create_topdir_parent_link=False)
|
||||||
ix.make_indexes(fl)
|
ix.make_indexes()
|
||||||
|
|
||||||
self.assert_files(fl, [
|
self.assert_files(fl, [
|
||||||
('', 'application/directory', None),
|
('', 'application/directory', None),
|
||||||
|
@ -271,27 +271,32 @@ class FileList(Sequence):
|
|||||||
class Indexer():
|
class Indexer():
|
||||||
"""generates index.html files if requested."""
|
"""generates index.html files if requested."""
|
||||||
|
|
||||||
def __init__(self, create_parent_links=True,
|
def __init__(self, file_list, create_parent_links=True,
|
||||||
create_topdir_parent_link=False,
|
create_topdir_parent_link=False,
|
||||||
append_footer='index_footer.html'):
|
append_footer='index_footer.html'):
|
||||||
|
'''
|
||||||
|
Args:
|
||||||
|
file_list (FileList): A FileList object to be updated
|
||||||
|
with index files for each directory.
|
||||||
|
create_parent_links (bool):
|
||||||
|
create_topdir_parent_link (bool):
|
||||||
|
append_footer (str):
|
||||||
|
'''
|
||||||
|
assert isinstance(file_list, FileList)
|
||||||
|
self.file_list = file_list
|
||||||
self.create_parent_links = create_parent_links
|
self.create_parent_links = create_parent_links
|
||||||
self.create_topdir_parent_link = create_topdir_parent_link
|
self.create_topdir_parent_link = create_topdir_parent_link
|
||||||
self.append_footer = append_footer
|
self.append_footer = append_footer
|
||||||
self.index_filename = 'index.html'
|
self.index_filename = 'index.html'
|
||||||
|
|
||||||
def make_indexes(self, file_list):
|
def make_indexes(self):
|
||||||
'''Make index files
|
'''Make index files
|
||||||
|
|
||||||
Args:
|
|
||||||
file_list (FileList): A FileList object to be updated
|
|
||||||
with index files for each directory.
|
|
||||||
Return:
|
Return:
|
||||||
No value, the file_list will be updated
|
No value, the self.file_list will be updated
|
||||||
'''
|
'''
|
||||||
assert isinstance(file_list, FileList)
|
|
||||||
|
|
||||||
folders = collections.OrderedDict()
|
folders = collections.OrderedDict()
|
||||||
for f in file_list:
|
for f in self.file_list:
|
||||||
if f.folder:
|
if f.folder:
|
||||||
folders[f.relative_path] = []
|
folders[f.relative_path] = []
|
||||||
folder = os.path.dirname(os.path.dirname(
|
folder = os.path.dirname(os.path.dirname(
|
||||||
@ -325,7 +330,7 @@ class Indexer():
|
|||||||
# for each directory.
|
# for each directory.
|
||||||
new_list = []
|
new_list = []
|
||||||
last_dirname = None
|
last_dirname = None
|
||||||
for f in reversed(list(file_list)):
|
for f in reversed(list(self.file_list)):
|
||||||
if f.folder:
|
if f.folder:
|
||||||
relative_path = f.relative_path + '/'
|
relative_path = f.relative_path + '/'
|
||||||
else:
|
else:
|
||||||
@ -340,7 +345,7 @@ class Indexer():
|
|||||||
last_dirname = dirname
|
last_dirname = dirname
|
||||||
new_list.append(f)
|
new_list.append(f)
|
||||||
new_list.reverse()
|
new_list.reverse()
|
||||||
file_list.file_list = new_list
|
self.file_list.file_list = new_list
|
||||||
|
|
||||||
def make_index_file(self, folder_links, title):
|
def make_index_file(self, folder_links, title):
|
||||||
"""Writes an index into a file for pushing"""
|
"""Writes an index into a file for pushing"""
|
||||||
@ -566,7 +571,8 @@ def run(cloud, container, files,
|
|||||||
|
|
||||||
# Create the objects to make sure the arguments are sound.
|
# Create the objects to make sure the arguments are sound.
|
||||||
with FileList() as file_list:
|
with FileList() as file_list:
|
||||||
indexer = Indexer(create_parent_links=parent_links,
|
indexer = Indexer(file_list,
|
||||||
|
create_parent_links=parent_links,
|
||||||
create_topdir_parent_link=topdir_parent_link,
|
create_topdir_parent_link=topdir_parent_link,
|
||||||
append_footer=footer)
|
append_footer=footer)
|
||||||
|
|
||||||
@ -576,7 +582,7 @@ def run(cloud, container, files,
|
|||||||
|
|
||||||
# (Possibly) make indexes.
|
# (Possibly) make indexes.
|
||||||
if indexes:
|
if indexes:
|
||||||
indexer.make_indexes(file_list)
|
indexer.make_indexes()
|
||||||
|
|
||||||
logging.debug("List of files prepared to upload:")
|
logging.debug("List of files prepared to upload:")
|
||||||
for x in file_list:
|
for x in file_list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user