def read_shortcut(content_path, tag, concept_node): """Read a Shortcut object from a directory which contains dependencies.txt and resources.txt, and optionally questions.txt.""" # process goals goals = [] if os.path.exists(shortcut_goals_file(content_path, tag)): goals = formats.read_nested_list( open(shortcut_goals_file(content_path, tag))) # process resources if not os.path.exists(shortcut_resources_file(content_path, tag)): raise DatabaseFormatError('Missing resources file for shortcut %s' % tag) shortcut_resources = formats.read_node_resources( open(shortcut_resources_file(content_path, tag))) # process dependencies if not os.path.exists(shortcut_resources_file(content_path, tag)): raise DatabaseFormatError('Missing dependencies file for shortcut %s' % tag) dependencies = formats.read_dependencies( open(shortcut_dependencies_file(content_path, tag))) # process questions if os.path.exists(shortcut_questions_file(content_path, tag)): questions = formats.read_questions( open(shortcut_questions_file(content_path, tag))) else: questions = [] return concepts.Shortcut(concept_node, goals, dependencies, shortcut_resources, questions)
def read_shortcut(content_path, tag, concept_node): """Read a Shortcut object from a directory which contains dependencies.txt and resources.txt, and optionally questions.txt.""" # process goals goals = [] if os.path.exists(shortcut_goals_file(content_path, tag)): goals = formats.read_nested_list(open(shortcut_goals_file(content_path, tag))) # process resources if not os.path.exists(shortcut_resources_file(content_path, tag)): raise DatabaseFormatError('Missing resources file for shortcut %s' % tag) shortcut_resources = formats.read_node_resources(open(shortcut_resources_file(content_path, tag))) # process dependencies if not os.path.exists(shortcut_resources_file(content_path, tag)): raise DatabaseFormatError('Missing dependencies file for shortcut %s' % tag) dependencies = formats.read_dependencies(open(shortcut_dependencies_file(content_path, tag))) # process questions if os.path.exists(shortcut_questions_file(content_path, tag)): questions = formats.read_questions(open(shortcut_questions_file(content_path, tag))) else: questions = [] return concepts.Shortcut(concept_node, goals, dependencies, shortcut_resources, questions)
def read_node(content_path, tag): """Read a Concept object from a directory which optionally contains title.txt, dependencies.txt, key.txt, references.txt, summary.txt, and see-also.txt.""" # TODO: normalize string cleaning (get rid of double quotes that mess up json) ### process title if os.path.exists(title_file(content_path, tag)): title = formats.read_title(open(title_file(content_path, tag))) else: title = None ### process ID if os.path.exists(id_file(content_path, tag)): node_id = formats.read_id(open(id_file(content_path, tag))) else: node_id = None ### process summary summary = "" usewiki = False sfile = None if os.path.exists(summary_file(content_path, tag)): sfile = summary_file(content_path, tag) elif os.path.exists(wiki_summary_file(content_path, tag)): sfile = wiki_summary_file(content_path, tag) usewiki = True if sfile: summary = formats.read_summary(open(sfile)) if usewiki and len(summary): summary = formats.mark_wiki(summary) # process resources if os.path.exists(node_resources_file(content_path, tag)): node_resources = formats.read_node_resources( open(node_resources_file(content_path, tag))) else: node_resources = [] ### process questions if os.path.exists(questions_file(content_path, tag)): questions = formats.read_questions( open(questions_file(content_path, tag))) else: questions = [] ### process dependencies if os.path.exists(dependencies_file(content_path, tag)): dependencies = formats.read_dependencies( open(dependencies_file(content_path, tag))) else: dependencies = [] ### process see-also pointers = [] if os.path.exists(see_also_file(content_path, tag)): pointers = formats.read_nested_list( open(see_also_file(content_path, tag))) ### process goals goals = "" if os.path.exists(goals_file(content_path, tag)): goals = formats.read_nested_list(open(goals_file(content_path, tag))) ### process flags if os.path.exists(node_flags_file(content_path, tag)): flags = formats.read_node_flags( open(node_flags_file(content_path, tag))) else: flags = [] return concepts.Concept(tag, node_id, title, summary, goals, dependencies, pointers, node_resources, questions, flags)
def read_node(content_path, tag): """Read a Concept object from a directory which optionally contains title.txt, dependencies.txt, key.txt, references.txt, summary.txt, and see-also.txt.""" # TODO: normalize string cleaning (get rid of double quotes that mess up json) ### process title if os.path.exists(title_file(content_path, tag)): title = formats.read_title(open(title_file(content_path, tag))) else: title = None ### process ID if os.path.exists(id_file(content_path, tag)): node_id = formats.read_id(open(id_file(content_path, tag))) else: node_id = None ### process summary summary = "" usewiki = False sfile = None if os.path.exists(summary_file(content_path, tag)): sfile = summary_file(content_path, tag) elif os.path.exists(wiki_summary_file(content_path, tag)): sfile = wiki_summary_file(content_path, tag) usewiki = True if sfile: summary = formats.read_summary(open(sfile)) if usewiki and len(summary): summary = formats.mark_wiki(summary) # process resources if os.path.exists(node_resources_file(content_path, tag)): node_resources = formats.read_node_resources(open(node_resources_file(content_path, tag))) else: node_resources = [] ### process questions if os.path.exists(questions_file(content_path, tag)): questions = formats.read_questions(open(questions_file(content_path, tag))) else: questions = [] ### process dependencies if os.path.exists(dependencies_file(content_path, tag)): dependencies = formats.read_dependencies(open(dependencies_file(content_path, tag))) else: dependencies = [] ### process see-also pointers = [] if os.path.exists(see_also_file(content_path, tag)): pointers = formats.read_nested_list(open(see_also_file(content_path, tag))) ### process goals goals = "" if os.path.exists(goals_file(content_path, tag)): goals = formats.read_nested_list(open(goals_file(content_path, tag))) ### process flags if os.path.exists(node_flags_file(content_path, tag)): flags = formats.read_node_flags(open(node_flags_file(content_path, tag))) else: flags = [] return concepts.Concept(tag, node_id, title, summary, goals, dependencies, pointers, node_resources, questions, flags)