Sujet précédent

5.7. files

Sujet suivant

5.7.2. files.formats — Simple module to test if a file is a CAD file

Cette page

Autres langues

5.7.1. files.deletable – Module to get files to delete

Introduit dans la version 1.2.

Module to select which files should be deleted (physically removed) after:

Each case can have a different behaviour specified by:

These constants are lists of tuples (test, selector) where:

  • test is a function that takes a DocumentFile and returns True if selector applies to the given file
  • selector is an instance of Selector which returns a list of DocumentFile to be deleted.

They can be given to get_deletable_files() to retrieve the list of DocumentFile to delete.

class plmapp.files.deletable.KeepLastNFiles(count)[source]

Bases: plmapp.files.deletable.Selector

A selector which keeps only the last count revisions (last one include).

class plmapp.files.deletable.KeepAllFiles[source]

Bases: plmapp.files.deletable.Selector

A selector which keeps all files: get_deletable_files() always returns an empty list.

class plmapp.files.deletable.DeleteAllFiles(include_last_revision=False)[source]

Bases: plmapp.files.deletable.Selector

A selector which returns all undeleted files.

If include_last_revision is True, the given document file is also included in the returned list.

class plmapp.files.deletable.MaximumTotalSize(max_size, order='revision')[source]

Bases: plmapp.files.deletable.Selector

A selector which ensures that the size of files related to a revision does not exceed max_size.

Paramètres:
  • max_size – maximum size in bytes
  • order – ordering field used to select which files must be deleted if the total size exceeds max_size

Possible values for order are:

revision
first deletes the most recent revisions
-revision
first deletes the oldest revisions
size
first deletes the biggest files
-size
first deletes the smallest files
class plmapp.files.deletable.MaxPerDate(frequency, maximum)[source]

Bases: plmapp.files.deletable.Selector

A selector which keeps at most maximum per frequency (day, month, year).

If the number of revisions exceeds maximum, most recent revisions are first deleted.

class plmapp.files.deletable.Modulo(number, modulo=1)[source]

Bases: plmapp.files.deletable.Selector

A selector which only keeps revisions if the revision modulo number equals to modulo.

For example, Modulo(4, 1) keeps a revision of four, and the intial revision is kept.

class plmapp.files.deletable.YoungerThan(timedelta, incremental=True)[source]

Bases: plmapp.files.deletable.Selector

A selector which deletes too frequent updates.

A revision is deleted if the difference between the date of creation of the last revision and its creation time is lesser than timedelta (a datetime.timedelta object).

If incremental is True (the default), only the previous revision is tested. This behaviour should be used after a checkin.

plmapp.files.deletable.pattern(*patterns)[source]

Returns a function which takes a DocumentFile and returns True if its filename matches one of the given patterns (like *.txt). patterns are not case sensitive.

plmapp.files.deletable.yes(x)[source]

A simple function that always returns True

plmapp.files.deletable.get_deletable_files(doc_file, selectors)[source]

Returns the list of DocumentFile to delete.

Returns an empty list if settings.KEEP_ALL_FILES is True.

Paramètres:
  • doc_file – the last revision of the file
  • selectors – list of tuples (test, selector) to determine which selectors should be called
plmapp.files.deletable.ON_CHECKIN_SELECTORS = [(<function yes at 0xbd9b938>, <plmapp.files.deletable.KeepLastNFiles object at 0x8b06590>)]

default selectors called after a checkin

plmapp.files.deletable.ON_DELETE_SELECTORS = [(<function yes at 0xbd9b938>, <plmapp.files.deletable.DeleteAllFiles object at 0x98aee90>)]

default selectors called after a deletion

plmapp.files.deletable.ON_DEPRECATE_SELECTORS = [(<function yes at 0xbd9b938>, <plmapp.files.deletable.DeleteAllFiles object at 0x98aee50>)]

default selectors called after a deprecation

plmapp.files.deletable.ON_CANCEL_SELECTORS = [(<function yes at 0xbd9b938>, <plmapp.files.deletable.DeleteAllFiles object at 0x98aefd0>)]

default selectors called after a cancellation