spend package

Submodules

spend.Device module

spend.Spend module

spend.Volume module

spend.exceptions module

exception spend.exceptions.AsymetricEncryptionException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

PGP file encryption returns something else than OK

exception spend.exceptions.DeviceNotMountedException

Bases: BaseException

exception spend.exceptions.DeviceNotWritableException

Bases: BaseException

exception spend.exceptions.DisplayableException(*args, **kwargs)

Bases: Exception

Base class for Exceptions which could be displayed on the OLED display

as_message() → spend.display.Message.Message

Get exception as Message

Returns:
Return type:Message
get_duration()
exception spend.exceptions.GhostMountpointException

Bases: BaseException

exception spend.exceptions.MoreThanTwoDevicesException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

More than 2 devices found

exception spend.exceptions.NoDeviceFoundException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

No (interesting) device was found by DeviceScanner

exception spend.exceptions.NoTargetsFoundException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

One or more devices have been found, but DeviceInspector did not returned any file to be copied

exception spend.exceptions.NotEnoughtSpaceException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

No device have enough space to store files selected by DeviceInspector

exception spend.exceptions.SameDeviceAndNoEncryptionException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

Input and output have been set to the same device, and no encryption have been chosen. It fails as it does not makes sense to duplicate files

exception spend.exceptions.SymetricEncryptionException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

Error on volume creation

exception spend.exceptions.TargetOnBothSidesException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

Targets found in both devices

exception spend.exceptions.UnknownRecipientException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

PGP recipient specified in config is not present in PGP keyring

exception spend.exceptions.UpdateException(*args, **kwargs)

Bases: spend.exceptions.DisplayableException

spend.helpers module

spend.helpers.copy_files(files, to)
spend.helpers.debounce(s)

Decorator ensures function can only be called once every s seconds.

spend.helpers.get_child_processes(parent_id)
spend.helpers.get_config(filename='prod.ini')

Return ConfigObj :Parameters: filename (str Config filename (e.g test.ini))

Returns:
Return type:ConfigObj
spend.helpers.get_random_str(size)

Return x chars belonging to letters and digits.

Parameters:size (int Len of the returned string)
spend.helpers.get_resource_requirement() → pkg_resources.Requirement
spend.helpers.read_file_as_bool(filepath)
spend.helpers.read_file_content(filepath)

Lock the file and returns its content :Parameters: filepath (str File path to read)

Returns:
Return type:str
Raises:IOError: – Lock cannot be obtained
class spend.helpers.safeutil

Bases: object

This is a script designed to be “safe” drop-in replacements for the shutil move() and copyfile() functions. These functions are safe because they should never overwrite an existing file. In particular, if you try to move/copy to dst and there’s already a file at dst, these functions will attempt to copy to a slightly different (but free) filename, to avoid accidental data loss. More background here: http://alexwlchan.net/2015/06/safer-file-copying/

static _increment_filename(filename, marker='-')

Returns a generator that yields filenames with a counter. This counter is placed before the file extension, and incremented with every iteration. For example: f1 = increment_filename(“myimage.jpeg”) f1.next() # myimage-1.jpeg f1.next() # myimage-2.jpeg f1.next() # myimage-3.jpeg If the filename already contains a counter, then the existing counter is incremented on every iteration, rather than starting from 1. For example: f2 = increment_filename(“myfile-3.doc”) f2.next() # myfile-4.doc f2.next() # myfile-5.doc f2.next() # myfile-6.doc The default marker is an underscore, but you can use any string you like: f3 = increment_filename(“mymovie.mp4”, marker=”_”) f3.next() # mymovie_1.mp4 f3.next() # mymovie_2.mp4 f3.next() # mymovie_3.mp4 Since the generator only increments an integer, it is practically unlimited and will never raise a StopIteration exception.

static copyfile(src, dst)

Copies a file from path src to path dst. If a file already exists at dst, it will not be overwritten, but: * If it is the same as the source file, do nothing * If it is different to the source file, pick a new name for the copy that is distinct and unused, then copy the file there.

Returns the path to the copy.

static move(src, dst)

Moves a file from path src to path dst. If a file already exists at dst, it will not be overwritten, but: * If it is the same as the source file, do nothing * If it is different to the source file, pick a new name for the copy that is distinct and unused, then copy the file there.

Returns the path to the new file.

spend.helpers.shred_file(filename)

Shred designed file

Parameters:filename (str Path of the file to be shreded)
spend.helpers.toggle_state(_file)

Switch a file content from one to zero or inverse Make use of a Lock

Parameters:file (str File path)
Returns:
Return type:bool New value
spend.helpers.umount_devices(devices)

Unmount devices with pumount

Parameters:devices (List[str] List of strings understood by pumount as a device)
spend.helpers.write_file(filepath, data)

Write data to filepath. No exceptions catched. Parameters: ———– filepath: str File path data: str Data to be written in the file

spend.update module

Module contents

Copyright (C) 2019 spend

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.