示例#1
0
def mint(set_name, count, *, labels, quiet):
    """
    Mint new identifiers and make barcode labels.

    <set name> is an existing identifier set, e.g. as output by the `id3c
    identifier set ls` command.

    <count> is the number of new identifiers to mint.

    If --labels are requested, a PDF of printable barcode labels is generated
    using the Lab Labels¹ instance <https://backoffice.seattleflu.org/labels/>.
    An alternative instance may be used by setting the LABEL_API environment
    variable to the instance URL.

    ¹ https://github.com/MullinsLab/Lab-Labels
    """
    session = DatabaseSession()
    minted = db.mint_identifiers(session, set_name, count)

    if not quiet:
        for identifier in minted:
            print(identifier.barcode, identifier.uuid, sep = "\t")

    if labels:
        layout = labelmaker.layout_identifiers(set_name, minted)
        pdf = labelmaker.generate_pdf(layout)
        labels.write(pdf)
示例#2
0
def mint(set_name, count, *, labels, layout, quiet, dry_run):
    """
    Mint new identifiers and make barcode labels.

    <set name> is an existing identifier set, e.g. as output by the `id3c
    identifier set ls` command.

    <count> is the number of new identifiers to mint.

    If --labels are requested, a PDF of printable barcode labels is generated
    using the Lab Labels¹ instance <https://backoffice.seattleflu.org/labels/>.
    An alternative instance may be used by setting the LABEL_API environment
    variable to the instance URL.

    If --layout is requested, the printable barcode labels will use the given
    version of the layout, if available.

    ¹ https://github.com/MullinsLab/Lab-Labels
    """
    session = DatabaseSession()

    with session:
        minted = db.mint_identifiers(session, set_name, count)

        if dry_run:
            LOG.info("Rolling back all changes; the database will not be modified")
            session.rollback()

    if not quiet:
        for identifier in minted:
            print(identifier.barcode, identifier.uuid, sep = "\t")

    if labels:
        label_layout = labelmaker.layout_identifiers(set_name, minted, layout)
        pdf = labelmaker.generate_pdf(label_layout)
        labels.write(pdf)
示例#3
0
def labels(filename, layout: str='default'):
    """
    Make barcode labels for an existing batch of identifiers.

    A PDF of printable barcode labels is generated using the Lab Labels¹
    instance <https://backoffice.seattleflu.org/labels/>.  An alternative
    instance may be used by setting the LABEL_API environment variable to the
    instance URL.

    The batch of identifiers to make labels for is selected interactively based
    on the identifier set and time of original generation.

    If --layout is requested, the printable barcode labels will use the given
    version of the layout, if available.

    ¹ https://github.com/MullinsLab/Lab-Labels
    """
    session = DatabaseSession()

    # Fetch batches of identifiers
    with session.cursor() as cursor:
        cursor.execute("""
            select identifier_set.name as set_name,
                   to_char(generated, 'FMDD Mon YYYY') as generated_date,
                   generated,
                   count(*)
              from warehouse.identifier
              join warehouse.identifier_set using (identifier_set_id)
             group by generated, identifier_set.name
             order by generated, identifier_set.name
            """)

        batches = list(cursor)

    # Print batches for selection
    click.echo("\nThe following batches of identifiers exist:\n")

    for index, batch in enumerate(batches, 1):
        click.secho(f"{index:2d}) ", bold = True, nl = False)
        click.echo(f"{batch.generated_date:>11} — {batch.count:>5,} {batch.set_name}")

    # Which batch do we want?
    choice = click.prompt(
        "\nFor which batch would you like to make labels",
        prompt_suffix = "? ",
        type = click.IntRange(1, len(batches)),
        default = str(len(batches)))

    chosen_batch = batches[int(choice) - 1]

    # Fetch identifiers for the chosen batch
    with session.cursor() as cursor:
        cursor.execute("""
            select uuid, barcode
              from warehouse.identifier
              join warehouse.identifier_set using (identifier_set_id)
             where identifier_set.name = %s
               and generated = %s
            """, (chosen_batch.set_name, chosen_batch.generated))

        identifiers = list(cursor)

    assert len(identifiers) == chosen_batch.count

    label_layout = labelmaker.layout_identifiers(chosen_batch.set_name, identifiers, layout)
    pdf = labelmaker.generate_pdf(label_layout)
    filename.write(pdf)