Common utilities
General functions and classes shared in the codebase
General functions
Filesystem
- xl.common.open_file_directory(path_or_uri: str) None[source]
Opens the parent directory of a file, selecting the file if possible.
- xl.common.walk(root: <mocks.MockGiModule object at 0x7f7211d0ded0>) MockGiModule object at 0x7f7211d0df10>][source]
Walk through a Gio directory, yielding each file
Files are enumerated in the following order: first the directory, then the files in that directory. Once one directory’s files have all been listed, it moves on to the next directory. Order of files within a directory and order of directory traversal is not specified.
- Parameters:
root – a
Gio.Filerepresenting the directory to walk through- Returns:
a generator object
Decorators
- xl.common.threaded(func)[source]
A decorator that will make any function run in a new thread
- Parameters:
func – the function to run threaded
- xl.common.synchronized(func)[source]
A decorator to make a function synchronized - which means only one thread is allowed to access it at a time.
This only works on class functions, and creates a variable in the instance called _sync_lock.
If this function is used on multiple functions in an object, they will be locked with respect to each other. The lock is re-entrant.
Classes
- class xl.common.LimitedCache(limit)[source]
Bases:
MutableMappingSimple cache that acts much like a dict, but has a maximum # of items
- class xl.common.TimeSpan(span)[source]
Calculates the number of days, hours, minutes, and seconds in a time span
- days = 0
number of days
- hours = 0
number of hours
- minutes = 0
number of minutes
- seconds = 0
number of seconds
- class xl.common.MetadataList(iterable=[], metadata=[])[source]
Like a list, but also associates an object of metadata with each entry.
(get|set|del)_meta_keyare the metadata interface - they allow the metadata to act much like a dictionary, with a few optimizations.- List aspects that are not supported:
sort
comparisons other than equality
multiply
- class xl.common.ProgressThread[source]
A basic thread with progress updates. The thread should emit the progress-update signal periodically. The contents must be number between 0 and 100, or a tuple of (n, total) where n is the current step.