This module implements some utilities, mainly related to importing and exporting tourneys data in a portable format.
Scarry used an INI file and we had several drawbacks with it, mainly because sending them with e-mail would result in data corruption.
SoL uses YAML instead, by default compressing the outcome with gzip.
Save insertions, changes and deletions to the database.
Parameters: |
|
---|---|
Return type: | a tuple of three lists, respectively inserted, modified and deleted record IDs, grouped in a dictionary keyed on PK name. |
Dump almost everything in a ZIP file.
Parameters: |
|
---|---|
Return type: | a buffer containing the ZIP archive |
This function builds a ZIP archive containing both a standard .sol dump made with dump_sol() named everything.sol with all registered tourneys and all registered players (that is, not just those who actually played) and two subdirectories portraits and emblems, respectively containing the images associated to the players and to the clubs.
If location is given, it may be either the full path name of the output file where the backup will be written or the path of a directory. In the latter case the file name will be automatically computed using current time, giving something like sol-backup_2014-02-03T14:35:12.zip.
When keep_only_if_changed is ``True` (the default) and location is a directory, the newly generated backup will be compared with the previous one (if there is at least one, of course) and if nothing has changed it will be removed.
Restore everything from a backup.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | the list of loaded tourney instances and the number of skipped tourneys |
This reads the ZIP created by backup() and loads its content into the database, writing the images in the right place (pre-existing images won’t be overwritten, though).
Load the archive exported from SoL.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | the list of loaded tourney instances and number of skipped tournaments |
If content is not specified, it will be loaded with urlopen() from the given url.
Normally only missing data is updated, except when restore is True.
Dump tourneys as a YAML document.
Parameters: |
|
---|---|
Return type: | a YAML formatted string |
Serialize some SoL entities as flat dictionaries.
Serialize a championship, if not already done.
Parameters: | club – a sol.models.club.Championship instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given championship |
Serialize a club, if not already done.
Parameters: | club – a sol.models.club.Club instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given club |
Serialize a player, if not already done.
Parameters: | player – a sol.models.player.Player instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given player |
Serialize a rate, if not already done.
Parameters: | rate – a sol.models.rate.Rate instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given rate |
Serialize a rating, if not already done.
Parameters: | rating – a sol.models.rating.Rating instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given rating |
Serialize a tourney, if not already done.
Parameters: | tourney – a sol.models.tourney.Tourney instance |
---|---|
Return type: | int |
Returns: | an integer marker that identify the given tourney |
A list of serialized championships
A list of serialized clubs
An hash mapping a particular instance to its serial marker
Most recent modification timestamp of any serialized entity
A list of serialized players
A list of serialized rates
A list of serialized ratings
A list of serialized tourneys
Deserialize a flat representation of some SoL entities.
Deserialize a Championship.
Parameters: | schampionship – a dictionary containing the flatified representation |
---|---|
Return type: | Championship |
Returns: | either an existing or a new instance |
Deserialize a Club.
Parameters: | sclub – a dictionary containing the flatified representation |
---|---|
Return type: | Club |
Returns: | either an existing or a new instance |
Deserialize a Player.
Parameters: | splayer – a dictionary containing the flatified representation |
---|---|
Return type: | Player |
Returns: | either an existing or a new instance |
Deserialize a Rate.
Parameters: | srate – a dictionary containing the flatified representation |
---|---|
Return type: | Rate |
Returns: | either an existing or a new instance |
Deserialize a Rating.
Parameters: | srating – a dictionary containing the flatified representation |
---|---|
Return type: | Rating |
Returns: | either an existing or a new instance |
Deserialize a Tourney.
Parameters: | stourney – a dictionary containing the flatified representation |
---|---|
Return type: | Tourney |
Returns: | either an existing or a new instance |
A list of championship instances.
The SQLAlchemy session.
The number of skipped tournaments, because already present.
A boolean flag, whether only missing fields will be updated.