Пример #1
0
def create_parent_article_file(file_path):
    source_replacer = SourceReplacer()
    reference_finder = ReferenceFinder()
    file_maker = FilesDirectoryMaker()
    article_register = ComponentRegistry()
    component_retriever = ComponentRetriever()

    source_code = SourceReader.get_source(file_path)
    hyperlink_details = reference_finder.get_links_details(source_code)
    avoided_file_list = DetailsKeeperDO.get_avoided_file_list(DetailsKeeperDO)
    for link_details in hyperlink_details:
        if not "No File" in link_details[1]:
            if not any(link_details[1] in avoided_file
                       for avoided_file in avoided_file_list):
                base_name = os.path.basename(link_details[1])
                file_name = os.path.splitext(base_name)
                link_string = link_details[2].split(">")
                article_id = component_retriever.get_article_id("Article " +
                                                                file_name[0])
                new_link_str = ' href="index.php?option=com_content&view=article&id=' + str(article_id) + ">" + \
                               link_string[1]
                source_code = source_code.replace(link_details[2],
                                                  new_link_str)
            # print(link_details[2])
    source_code = source_replacer.replace_session_management(source_code)
    source_code = source_replacer.replace_media_references(
        source_code, file_path, "/opt/lampp/htdocs/Blog")
    include_counter = reference_finder.has_include(file_path)
    if include_counter == 1:
        source_code = file_maker.replace_main_file_includes(source_code)
    article_base_name = os.path.basename(file_path)
    article_name = os.path.splitext(article_base_name)
    article_register.register_article(source_code, article_name[0])
Пример #2
0
def create_nested_hyperlinked_articles(file_path):
    global article_creation_tree
    global file_tree
    global created_article_details

    reference_finder = ReferenceFinder()

    avoided_file_list = DetailsKeeperDO.get_avoided_file_list(DetailsKeeperDO)
    source_code = SourceReader.get_source(file_path)
    hyperlink_details = reference_finder.get_links_details(source_code)
    if hyperlink_details.__len__() > 0:
        for link_details in hyperlink_details:
            # print(link_details)
            if not "No File" in link_details[1]:
                if any(link_details[1] in avoided_file
                       for avoided_file in avoided_file_list):
                    # print("avoided file")
                    pass
                else:
                    # print("not avoided file. File sent to create an article.")
                    linked_source_code = SourceReader.get_source(
                        link_details[1])
                    child_hyperlinks = reference_finder.get_links_details(
                        linked_source_code)
                    if child_hyperlinks.__len__() > 0:
                        file_tree.update({link_details[1]: file_path})
                        create_nested_hyperlinked_articles(link_details[1])
                    else:
                        file_tree.update({link_details[1]: file_path})
                        create_child_articles(link_details[1])
                        if file_path in article_creation_tree:
                            count = article_creation_tree[file_path]
                            count = count + 1
                            article_creation_tree.update({file_path: count})
                        else:
                            count = 1
                            article_creation_tree.update({file_path: count})
                    parent_file = file_tree[link_details[1]]
                    parent_article_count = article_creation_tree[parent_file]
                    if parent_article_count == hyperlink_details.__len__():
                        create_parent_article_file(parent_file)
                        if parent_file != check_root():
                            elder_file = file_tree[parent_file]
                            if elder_file in article_creation_tree:
                                elder_count = article_creation_tree[elder_file]
                                elder_count = elder_count + 1
                                article_creation_tree.update(
                                    {elder_file: elder_count})
                            else:
                                elder_count = 1
                                article_creation_tree.update(
                                    {elder_file: elder_count})
            else:
                # print("External file is referenced.")
                file_tree.update({link_details[1]: file_path})
                if file_path in article_creation_tree:
                    count = article_creation_tree[file_path]
                    count = count + 1
                    article_creation_tree.update({file_path: count})
                else:
                    count = 1
                    article_creation_tree.update({file_path: count})