File Handling Modules

hedwig.file.csv

hedwig.file.csv.encode_string(value)
hedwig.file.csv.encode_csv(value)

UTF-8 encode whole CSV file.

hedwig.file.csv.decode_csv(value)

UTF-8 decode whole CSV file.

hedwig.file.csv.decode_value(value)
class hedwig.file.csv.CSVDialect

Define the CSV “dialect” in which we wish to write CSV files.

delimiter = ','
doublequote = True
lineterminator = '\n'
quotechar = '"'
quoting = 2
class hedwig.file.csv.CSVWriter(dialect=<class 'hedwig.file.csv.CSVDialect'>)

CSV writing utility class.

This class sets up a CSV writer (using the standard library csv module) which writes to a StringIO or BytesIO (depending on Python version) buffer.

add_row(row)

Add a row to the CSV file.

get_csv()

Return the contents of the buffer.

hedwig.file.graphviz

hedwig.file.graphviz.graphviz_to_png(buff)

Convert a Graphviz file to an SVG file.

hedwig.file.image

hedwig.file.image.create_thumbnail_and_preview(image, max_thumb=None, max_preview=None)

Generate a thumbnail image and preview if necessary.

hedwig.file.image._read_image(image)

Construct an image object by reading the given buffer.

hedwig.file.image._write_image(image_obj)

Write image to a buffer and return it.

hedwig.file.image._calculate_size(max_size, orig_size, only_shrink=False)

Calculate (width, height) size tuple to which to scale image, or None if scaling isn’t necessary.

hedwig.file.info

hedwig.file.info.pdf_num_pages(r)
hedwig.file.info._pdf_page_sizes(r)
hedwig.file.info.determine_figure_type(buff)

Attempt to determine the figure type of an image file stored in a buffer.

Uses the magic module to try to determine the MIME type of the image and then converts that to a Hedwig FigureType enum value.

Raises a UserError exception if the determined MIME type is not recognised as a Hedwig figure type.

hedwig.file.info.determine_pdf_page_count(buff, with_max_size=False)

Determine the number of pages in a PDF file stored in a buffer.

Returns:

the number of pages if with_max_size is false, otherwise a tuple containing the number of pages and the maximum sizes as determined by the pdf_max_size function.

hedwig.file.info.pdf_max_size(r)

Determine the maximum major and minor dimension of the pages of a PDF file, given a PdfFileReader object.

Applies the scale factor to the width and height returned by _pdf_page_sizes for each page. Identifies the major (larger dimension) and minor (smaller dimension) axes. Returns the maximum values for the major and minor sizes.

Sizes should be returned in inches.

hedwig.file.moc

hedwig.file.moc.read_moc(file_=None, buff=None, max_order=None)

Construct a MOC object by reading the given file or buffer.

The MOC is then normalized to the given maximum order, if given.

hedwig.file.moc.write_moc(moc_object)

Write MOC to a buffer and return it.

hedwig.file.pdf

hedwig.file.pdf.pdf_merge(pdfs)

Merge a sequence of PDFs (supplied as buffers containing the PDF data) into a single document (returned also as a buffer).

hedwig.file.pdf.pdf_to_png(pdf, page_count=None, renderer='ghostscript', **kwargs)

Convert a PDF file to a list of PNG images.

The page count is determined automatically if not specified.

The PDF renderer can be either “ghostscript” or “pdftocairo”. The path to the selected program is looked up in the configuration file.

Any additional keyword arguments are passed on to _pdf_ps_to_png() (for “ghostscript”) or _pdf_to_cairo() (for “pdftocairo”).

hedwig.file.pdf.pdf_to_svg(pdf, page, **kwargs)

Convert a given page of the PDF file to SVG format.

hedwig.file.pdf.ps_to_png(ps, page_count=None, **kwargs)

Convert a PS or EPS image to a list of PNG images.

Currently assumes there is only one page if no page_count is given, so one PNG should be created in that case.

Any additional keyword arguments are passed on to _pdf_ps_to_png().

hedwig.file.pdf._pdf_ps_to_png(buff, page_count, resolution=100, downscale=4)

Implements PDF or PS conversion to PDF via Ghostscript.

hedwig.file.pdf._pdf_to_cairo(buff, type_, pages, resolution=100, downscale=None)

Process a PDF file using pdftocairo.

The arguments specify the desired figure type (PNG or SVG) and a list of the pages (by page number) to process.

The downscale argument is ignored (it is present for compatibility with the equivalent ghostscript-based method).

hedwig.file.poll

hedwig.file.poll.process_moc(db, dry_run=False)

Function to process new clash tool MOC files by importing their cells into the “moc_cell” database table in order to make them searchable.

hedwig.file.poll.process_proposal_figure(db, dry_run=False)

Function to process pending proposal figure uploads.

hedwig.file.poll.process_review_figure(db, dry_run=False)

Function to process pending review figure uploads.

hedwig.file.poll._process_figure(db, _type, dry_run=False)
hedwig.file.poll.process_proposal_pdf(db, dry_run=False)

Function to process pending proposal PDF uploads.