Sujet précédent

5.16.7. thumbnailers.sw — Thumbnailer for SolidWorks files

Sujet suivant

5.17.1. archive — Module to stream tar and zip archives

Cette page

Autres langues

5.17. utils — Utilities

This module contains some functions which may be useful.

class plmapp.utils.SeekedFile(file)[source]

Bases: object

Introduit dans la version 1.1.

A file-like object that wraps an already opened and seeked file.

This file-like can be read by PIL and is used to open an image contained in another file.

read(*args)[source]
readline(*args)[source]
readlines(*args)[source]
tell()[source]
seek(offset, whence=0)[source]
plmapp.utils.next_in_seq(seq, value)[source]

Returns item next to value in the sequence seq

Example:

>>> next_in_seq("abcd", "b")
'c'
>>> next_in_seq(range(5), 2)
3
plmapp.utils.get_next_revision(revision)[source]

Returns next revision for revision. For example, if revision represents an int, it returns a string of the value + 1.

If it can not find a new revision, it returns “”

Example:

>>> get_next_revision("a")
'b'
>>> get_next_revision("r")
's'
>>> get_next_revision("z")
'aa'
>>> get_next_revision("A")
'B'
>>> get_next_revision("R")
'S'
>>> get_next_revision("Z")
'AA'
>>> get_next_revision("1")
'2'
>>> get_next_revision("41")
'42'
>>> get_next_revision("0041")
'0042'
>>> get_next_revision("a.b")
'a.c'
>>> get_next_revision("a-a")
'a-b'
>>> get_next_revision("a,a")
'a,b'
>>> get_next_revision("a.3")
'a.4'
>>> get_next_revision("a.b.1")
'a.b.2'
>>> get_next_revision("plop")
''
>>> get_next_revision("a.plop")
''
>>> get_next_revision("")
''
plmapp.utils.convert(value, from_, to)[source]

Convert value from from_ unit to to unit.

Example:

>>> "%.3f" % convert(10, "cm", "mm")
'100.000'
>>> "%.3f" % convert(10, "mm", "cm")
'1.000'
>>> "%.3f" % convert(10, "in", "cm")
'25.400'
>>> "%.3f" % convert(72, "pt", "in")
'1.000'
>>> "%.3f" % convert(72, "pc", "in")
'12.000'
plmapp.utils.normalize_length(length)[source]

Converts length to a length in mm, formatted as %.1f

Example

>>> normalize_length("29.7cm")
'297.0'
>>> normalize_length("21.00001cm")
'210.0'
>>> normalize_length("7.5in")
'190.5'
plmapp.utils.size_to_format(width_lg, height_lg)[source]

Converts a size to a page format

Example:

>>> size_to_format("29.7cm", "21cm")
'Other'
>>> size_to_format("21cm", "29.7cm")
'A4'
plmapp.utils.level_to_sign_str(level)[source]

Converts a level (int, starting from 0) to a sign role

Example:

>>> level_to_sign_str(0)
'sign_1st_level'
>>> level_to_sign_str(1)
'sign_2nd_level'
>>> level_to_sign_str(2)
'sign_3rd_level'
>>> level_to_sign_str(3)
'sign_4th_level'
>>> level_to_sign_str(4)
'sign_5th_level'
>>> level_to_sign_str(10)
'sign_11th_level'
plmapp.utils.memoize_noarg(func)[source]

Decorator which memoize result of func. func must not take arguments

plmapp.utils.generate_password(length=12)[source]

Generates a random password of length characters.

plmapp.utils.can_generate_pdf()[source]

Returns True if openPLM can generate pdf files, i.e, pisa (xhtml2pdf) is installed.

plmapp.utils.get_ext(filename)[source]

Introduit dans la version 1.1.

Returns the extension of filename (dot include).

It stripped all ”.{number}” extensions if they are present.

Example:
>>> get_ext("filename.png")
'.png'
>>> get_ext("filename.prt.2")
'.prt'
>>> get_ext("filename.prt")
'.prt'
>>> get_ext("filename.1")
'.1'
plmapp.utils.get_pages_num(total_pages, current_page)[source]

Introduit dans la version 1.1.

Returns the pages to display for the pagination

plmapp.utils.filename_to_name(filename)[source]

Introduit dans la version 1.2.

Returns a clean version of a filename that should be more suitable as a document name.

Example:
>>> filename_to_name("/tmp/hello.pdf")
'hello'
>>> filename_to_name(u"/tmp/Hello_world.pdf")
u'Hello world'
>>> filename_to_name(u"/tmp/heLLoWorlD.xyz")
u'heLLoWorlD'
plmapp.utils.r2r(template, dictionary, request)[source]

Shortcut for:

render_to_response(template, dictionary,
                      context_instance=RequestContext(request))