kojismokydingo.common¶
Koji Smoky Dingo - Common Utils
Some simple functions used by the other modules.
- author:
Christopher O'Brien <obriencj@gmail.com>
- license:
GPL v3
- chunkseq(seq, chunksize)[source]¶
Chop up a sequence into sub-sequences, each up to chunksize in length.
- escapable_replace(orig, character, replacement)[source]¶
Single-character string substitutions. Doubled sentinel characters can be used to represent that exact character.
Examples:
escapable_replace('Hello %', '%', 'World')
returns"Hello World"
escapable_replace('Hello %%', '%', 'World')
returns"Hello %"
- find_cache_dir(usage=None)[source]¶
The use cache dir for koji-smoky-dingo for the given usage (eg. repoquery). Attempts to use the
appdirs
package of it is available.
- find_config_dirs()[source]¶
The site and user configuration dirs for koji-smoky-dingo, as a tuple. Attempts to use the
appdirs
package if it is available.
- find_config_files(dirs=None)[source]¶
The ordered list of configuration files to be loaded.
If
dirs
is specified, it must be a sequence of directory names, from which conf files will be loaded in order. If unspecified, defaults to the result offind_config_dirs
Configuration files must have the extension
.conf
to be considered. The files will be listed in directory order, and then in alphabetical order from within each directory.
- fnmatches(value, patterns, ignore_case=False)[source]¶
Checks value against multiple glob patterns. Returns True if any match.
- get_plugin_config(conf, plugin, profile=None)[source]¶
Given a loaded configuration, return the section specific to the given plugin, and optionally profile-specific as well.
- globfilter(seq, patterns, key=None, invert=False, ignore_case=False)[source]¶
Generator yielding members of sequence seq which match any of the glob patterns specified.
Patterns must be a list of glob-style pattern strings.
If key is specified, it must be a unary callable which translates a given sequence item into a string for comparison with the patterns.
If invert is True, yields the non-matches rather than the matches.
If ignore_case is True, the pattern comparison is case normalized.
- Parameters:
seq (Iterable[GFT]) -- series of objects to be filtered. Normally strings, but may be any type provided the key parameter is specified to provide a string for matching based on the given object.
patterns (Iterable[str]) -- list of glob-style pattern strings. Members of seq which match any of these patterns are yielded.
key (Callable[[Any], Any] | Any | None) -- A unary callable which translates individual items on seq into the value to be matched against the patterns. Default, match against values in seq directly.
invert (bool) -- Invert the logic, yielding the non-matches rather than the matches. Default, yields matches
ignore_case (bool) -- pattern comparison is case normalized if True. Default, False
- Since:
1.0
- Return type:
Iterable[GFT]
- ichunkseq(seq, chunksize)[source]¶
Similar to chunkseq, but lazy. Note that each chunk must be exhausted before beginning a new chunk, as the chunks will be read from the original sequence only when they themselves are iterated over.
- itemsgetter(key, *keys)[source]¶
Similar to
operator.itemgetter
. However, the returned unary callable always returns a tuple of results, even if there's only one key.- Parameters:
- Returns:
a callabler getter which when called with a value will return the result of getting all of the specified keys, in a tuple.
- Since:
2.1
- Return type:
- load_full_config(config_files=None)[source]¶
Configuration object representing the full merged view of config files.
If
config_files
is None, use the results offind_config_files
. Otherwise,config_files
must be a sequence of filenames.- Parameters:
config_files (Iterable[str] | None) -- configuration files to be loaded, in order. If not specified, the results of
find_config_files
will be used.- Returns:
a configuration representing a merged view of all config files
- Since:
1.0
- Return type:
- load_plugin_config(plugin, profile=None)[source]¶
Configuration specific to a given plugin, and optionally specific to a given profile as well.
Profile-specific sections are denoted by a suffix on the section name, eg.
[my_plugin] # this setting is for my_plugin on all profiles setting = foo [my_plugin:testing] # this setting is for my_plugin on the testing profile setting = bar
- merge_extend(*dict_additions)[source]¶
Similar to
update_extend
but creates a new dict to hold results, and new initial lists to be extended, leaving all the arguments unaltered.
- parse_datetime(src, strict=True)[source]¶
Attempts to parse a datetime string in numerous ways based on pre-defined regex mappings
- Supported formats:
%Y-%m-%d %H:%M:%S.%f %Z
%Y-%m-%d %H:%M:%S.%f%z
%Y-%m-%d %H:%M:%S %Z
%Y-%m-%d %H:%M:%S%z
%Y-%m-%d %H:%M:%S
%Y-%m-%d %H:%M
%Y-%m-%d
%Y-%m
Plus integer timestamps and the string
"now"
Timezone offset formats (%z) may also be specified as either +HHMM or +HH:MM (the : will be removed)
- Parameters:
- Raises:
ValueError -- if strict and no src matches none of the pre-defined formats
- Since:
1.0
- Return type:
- unique(sequence, key=None)[source]¶
Given a sequence, de-duplicate it into a new list, preserving order.
In the event that the sequence contains non-hashable objects,
key
must be specified as a unary callable which produces a hashable unique identifier for the individual items in the sequence. This identifier is then used to perform the de-duplication.
- update_extend(dict_orig, *dict_additions)[source]¶
Extend the list values of the original dict with the list values of the additions dict.
eg.
A = {'a': [1, 2], 'b': [7], 'c': [10]} B = {'a': [3], 'b': [8, 9], 'd': [11]} update_extend(A, B) A >> {'a': [1, 2, 3], 'b': [7, 8, 9], 'c': [10], 'd': [11]}
The values of dict_orig must support an extend method.