コード例 #1
0
ファイル: publish.py プロジェクト: openstax/nebuchadnezzar
def parse_book_tree(bookdir):
    """Converts filesystem booktree back to a struct"""
    struct = []
    ex = [lambda filepath: '.sha1sum' in filepath.name]
    ex.extend([lambda filepath: 'metadata.json' in filepath.name])
    for dirname, subdirs, filenames in os.walk(str(bookdir)):
        if 'collection.xml' in filenames:
            path = Path(dirname)
            sha1s = get_sha1s_dict(path)
            struct.append((parse_collection(path, excludes=ex), sha1s))
        elif 'index.cnxml' in filenames:
            path = Path(dirname)
            sha1s = get_sha1s_dict(path)
            struct.append((parse_module(path, excludes=ex), sha1s))

    return struct
コード例 #2
0
ファイル: task_extensions.py プロジェクト: openstax/neb-tasks
def execute_task_actions(content_dir, task):
    before_action, module_action, collection_action = task

    before_action()

    content_dir = Path(content_dir).resolve()
    ex = [lambda filepath: '.sha1sum' in filepath.name]
    for dirname, subdirs, filenames in os.walk(str(content_dir)):
        path = Path(dirname)
        if 'collection.xml' in filenames:
            collection = parse_collection(path, excludes=ex)
            action_params = to_str_dict(collection)
            collection_action(**action_params)
        elif 'index.cnxml' in filenames:
            module = parse_module(path, excludes=ex)
            action_params = to_str_dict(module)
            module_action(**action_params)
コード例 #3
0
ファイル: test_collection.py プロジェクト: openstax/cnx-press
def test_parse_colletion_metdata_without_print_style(tmpdir,
                                                     litezip_valid_litezip):
    working_dir = tmpdir.mkdir('col')
    collection_file = working_dir.join('collection.xml')
    # Copy over and modify the collection.xml file.
    with (litezip_valid_litezip / 'collection.xml').open() as origin:
        xml = etree.parse(origin)
        elm = xml.xpath('//col:param[@name="print-style"]',
                        namespaces=COLLECTION_NSMAP)[0]
        elm.getparent().remove(elm)
        collection_file.write(etree.tounicode(xml).encode('utf8'))
    assert 'print-style' not in collection_file.read()

    # Test the parser doesn't error when a print-style is missing.
    # given a Collection object,
    model = parse_collection(Path(working_dir))
    # parse the metadata into a CollectionMetadata,
    md = parse_collection_metadata(model)
    assert md.print_style is None
コード例 #4
0
ファイル: test_collection.py プロジェクト: openstax/cnx-press
def test_parse_collection_metadata(litezip_valid_litezip):
    # given a Collection object,
    model = parse_collection(litezip_valid_litezip)
    # parse the metadata into a CollectionMetadata,
    md = parse_collection_metadata(model)
    # which we then test for data point information

    assert md.id == 'col11405'
    assert md.version == '1.2'
    assert md.created == '2011/05/24 10:31:56.888 GMT-5'
    assert md.revised == '2013/03/11 22:52:33.244 GMT-5'
    assert md.title == 'Intro to Computational Engineering: Elec 220 Labs'
    assert md.license_url == 'http://creativecommons.org/licenses/by/3.0/'
    assert md.language == 'en'

    assert md.authors == ('mwjhnsn', 'jedifan42')
    assert md.maintainers == ('mwjhnsn', 'jedifan42', 'cavallar')
    assert md.licensors == ('mwjhnsn', 'jedifan42', 'cavallar')

    assert md.keywords == (
        'Calculator',
        'Cavallaro',
        'Elec 220',
        'Gate',
        'Interrupt',
        'LC-3',
        'Loop',
        'Microcontroller',
        'MSP 430',
        'Rice',
    )
    assert md.subjects == ('Science and Technology', )

    assert md.abstract == ("This collection houses all the documentation "
                           "for the lab component of Rice Universities Elec "
                           "220 lab component.  The labs cover topics such "
                           "as gates, simulation, basic digital I/O, "
                           "interrupt driven embedded programming, C "
                           "language programming, and finally a/d "
                           "interfacing and touch sensors.")
    # This test case uses ``value=""`` in the xml, so a value is found.
    assert md.print_style is None