45 lines
924 B
Python
45 lines
924 B
Python
import enum
|
|
import functools
|
|
import operator
|
|
import sys
|
|
import typing
|
|
|
|
from os.path import basename
|
|
|
|
|
|
def clsname(obj) -> str:
|
|
'''
|
|
Get the class name of an object
|
|
|
|
:param typing.Union[type, object] obj: Object or type to get the name of
|
|
'''
|
|
try:
|
|
return obj.__class__.__name__
|
|
|
|
except AttributeError:
|
|
return obj.__name__
|
|
|
|
|
|
# might not use this
|
|
def manifest_to_flag(enum: 'enum.Flag', values: 'list[str]'):
|
|
items = tuple(getattr(enum, item) for item in values)
|
|
return combine_flags(items)
|
|
|
|
|
|
def combine_flags(*items) -> enum.Flag:
|
|
'''
|
|
Combine multiple :class:`enum.Flag` objects into one
|
|
|
|
:param list[str,enum.Flag] items:
|
|
'''
|
|
if len(items) > 1:
|
|
return functools.reduce(operator.or_, items)
|
|
|
|
elif len(items) == 1:
|
|
return items[0]
|
|
|
|
|
|
def is_in_game() -> bool:
|
|
'Return ``True`` if Python is currently running within a Borderlands game'
|
|
return not basename(sys.executable).lower().startswith('python')
|