-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (22 loc) · 765 Bytes
/
utils.py
File metadata and controls
28 lines (22 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
import tomllib
with open("config.toml", mode="rb") as fp:
CONFIG = tomllib.load(fp)
def log(*args, **kwargs):
"""
A print replacement that prints to stderr.
"""
kwargs.setdefault('file', sys.stderr)
return print(*args, **kwargs)
def name_or_str(thing):
"""
Useful helper to convert various Hawkey/DNF objects to strings.
Returns the object's name attribute, falls back to the str representation.
"""
return getattr(thing, 'name', str(thing))
def stringify(lst, separator=', '):
"""
Converts a list of objects to a single string, using the name_or_str() function.
If no separator is given, separates the items by comma and space.
"""
return separator.join(name_or_str(i) for i in lst)