Exemple #1
0
def build(package_path, manifest, description, files=dict(),
          storage_factory=ZipFileStorage):
    ''' Build a OXT Package.

    :param package_path: path to an .oxt package to be built
    :param manifest: an instance of Manifest
    :param description: an instance of Description
    :param files: package files, in a form of (path, node) dict
    :param storage_factory: storage factory for the package.
                            Default to ZipFileStorage
    '''

    assert not any(node is None for node in files.values())
    assert all(path in files for path in manifest)
    assert all(path in files for path in description.required_files())

    logger.info('creating %s', package_path)
    with storage_factory(package_path, 'w') as stg:
        logger.info('writing %s', MANIFEST_PATH)
        manifest_node = makedirs_to_file(stg, MANIFEST_PATH)
        with manifest_node.open('w') as f:
            manifest.dump(f)

        logger.info('writing %s', DESCRIPTION_PATH)
        desc_node = makedirs_to_file(stg, DESCRIPTION_PATH)
        with desc_node.open('w') as f:
            description.write(f)

        for path in sorted(files):
            node = files[path]
            logger.info('writing %s', path)
            dest = makedirs_to_file(stg, path)
            copy_file(node, dest)
Exemple #2
0
def init_main():
    doc = '''Usage: oxt-pkg-init [options] <package-path>

    --help      Print this screen.
    '''

    from docopt import docopt
    args = docopt(doc)
    logging.basicConfig(level=logging.INFO)

    package_path = args['<package-path>']

    manifest = Manifest()
    description = Description()

    with open_storage(package_path, 'w') as stg:
        with makedirs_to_file(stg, MANIFEST_PATH).open('w') as f:
            manifest.dump(f)
        with makedirs_to_file(stg, DESCRIPTION_PATH).open('w') as f:
            description.write(f)
Exemple #3
0
def init_main():
    doc = '''Usage: oxt-pkg-init [options] <package-path>

    --help      Print this screen.
    '''

    from docopt import docopt
    args = docopt(doc)
    logging.basicConfig(level=logging.INFO)

    package_path = args['<package-path>']

    manifest = Manifest()
    description = Description()

    with open_storage(package_path, 'w') as stg:
        with makedirs_to_file(stg, MANIFEST_PATH).open('w') as f:
            manifest.dump(f)
        with makedirs_to_file(stg, DESCRIPTION_PATH).open('w') as f:
            description.write(f)
Exemple #4
0
def add_file(stg, manifest, path, full_path, media_type):
    ''' add a file into the storage and manifest.

    :param stg: a storage
    :param manifest: an instance of Manifest
    :param path: path to the file on the filesystem.
    :param full_path: ``manifest:full-path`` value of ``manifest:file-entry``
    :param media_type: ``manifest:media-type`` value of ``manifest:file-entry``
    '''
    node = makedirs_to_file(stg, full_path)
    put_file(node, path)
    manifest[full_path] = media_type
    return node
Exemple #5
0
def add_file(stg, manifest, path, full_path, media_type):
    ''' add a file into the storage and manifest.

    :param stg: a storage
    :param manifest: an instance of Manifest
    :param path: path to the file on the filesystem.
    :param full_path: ``manifest:full-path`` value of ``manifest:file-entry``
    :param media_type: ``manifest:media-type`` value of ``manifest:file-entry``
    '''
    node = makedirs_to_file(stg, full_path)
    put_file(node, path)
    manifest[full_path] = media_type
    return node
Exemple #6
0
def build(package_path,
          manifest,
          description,
          files=dict(),
          storage_factory=ZipFileStorage):
    ''' Build a OXT Package.

    :param package_path: path to an .oxt package to be built
    :param manifest: an instance of Manifest
    :param description: an instance of Description
    :param files: package files, in a form of (path, node) dict
    :param storage_factory: storage factory for the package.
                            Default to ZipFileStorage
    '''

    assert not any(node is None for node in files.values())
    assert all(path in files for path in manifest)
    assert all(path in files for path in description.required_files())

    logger.info('creating %s', package_path)
    with storage_factory(package_path, 'w') as stg:
        logger.info('writing %s', MANIFEST_PATH)
        manifest_node = makedirs_to_file(stg, MANIFEST_PATH)
        with manifest_node.open('w') as f:
            manifest.dump(f)

        logger.info('writing %s', DESCRIPTION_PATH)
        desc_node = makedirs_to_file(stg, DESCRIPTION_PATH)
        with desc_node.open('w') as f:
            description.write(f)

        for path in sorted(files):
            node = files[path]
            logger.info('writing %s', path)
            dest = makedirs_to_file(stg, path)
            copy_file(node, dest)