mini_buildd.misc module¶
- mini_buildd.misc.singularize(s)¶
Singularize some english nouns from plural.
- class mini_buildd.misc.Datetime¶
Bases:
object
Datetime tools – always use same/comparable (aware && UTC) datetime objects.
- EPOCH = datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)¶
- SINCE_OPTIONS = ['1 hour ago', '1 day ago', '1 week ago', '1 month ago', '1 year ago', 'epoch']¶
- classmethod now()¶
Shortcut to be used for all internal UTC stamps.
- classmethod from_stamp(stamp)¶
- classmethod from_iso(isostr)¶
- classmethod from_path(path)¶
- classmethod timecode(stamp=None)¶
Timecode string from current timestamp.
- classmethod is_naive(date_obj)¶
- classmethod check_aware(date_obj)¶
- classmethod parse(date_string, default=None)¶
Use keyword ‘epoch’ for a big-bang timestamp. Otherwise most formats should work (like ‘2 weeks ago’).
- class mini_buildd.misc.Snake(name)¶
Bases:
object
Case style conversion to (lowercase) snake.
>>> Snake("CamelCase").from_camel() 'camel_case' >>> Snake("Kebab-Case").from_kebab() 'kebab_case'
- from_camel()¶
- from_kebab()¶
- class mini_buildd.misc.Field(field)¶
Bases:
object
Changes field name handling (custom prefix && (snake) name conversion).
- CPREFIX = 'X-Mini-Buildd-'¶
- class mini_buildd.misc.TmpDir(**kwargs)¶
Bases:
object
Temporary dir class (use with
with contextlib.closing()...
, or as mixin class)- close()¶
- mini_buildd.misc.tmp_dir(**kwargs)¶
Temporary dir context manager (use with
with
)
- mini_buildd.misc.nop(*_args, **_kwargs)¶
- mini_buildd.misc.attempt(func, *args, retval_on_failure=None, **kwargs)¶
Run function, warn-log exception on error, but continue.
>>> attempt(lambda x: x, "ypsilon") 'ypsilon' >>> attempt(lambda x: x, "ypsilon", retval_on_failure="xylophon", unknown_arg="xanthippe") 'xylophon' >>> attempt(lambda x: x/0, "ypsilon", retval_on_failure="xylophon") 'xylophon'
- mini_buildd.misc.measure(func, *args, **kwargs)¶
- mini_buildd.misc.strip_epoch(version)¶
Strip the epoch from a version string.
- mini_buildd.misc.guess_default_dirchroot_backend(overlay, aufs)¶
- mini_buildd.misc.subst_placeholders(template, placeholders)¶
Substitute placeholders in string from a dict.
>>> subst_placeholders("Repoversionstring: %IDENTITY%%CODEVERSION%", { "IDENTITY": "test", "CODEVERSION": "60" }) 'Repoversionstring: test60'
- class mini_buildd.misc.Hash(path)¶
Bases:
object
Shortcut to get hashsums from file.
>>> Hash("test-data/unix.txt").md5() 'cc3d5ed5fda53dfa81ea6aa951d7e1fe' >>> Hash("test-data/unix.txt").sha1() '8c84f6f36dd2230d3e9c954fa436e5fda90b1957'
- get(hash_type='md5')¶
Get any hash from file contents.
- md5()¶
- sha1()¶
- mini_buildd.misc.get_cpus()¶
- mini_buildd.misc.list_get(list_, index, default=None)¶
- mini_buildd.misc.rmdirs(path)¶
Remove path recursively. Succeed even if it does not exist in the first place.