本文整理汇总了Python中utool.printex函数的典型用法代码示例。如果您正苦于以下问题:Python printex函数的具体用法?Python printex怎么用?Python printex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_process_title
def set_process_title(title):
try:
import setproctitle
setproctitle.setproctitle(title)
except ImportError as ex:
import utool
utool.printex(ex, iswarning=True)
示例2: paint
def paint(dgt, painter, option, qtindex):
"""
TODO: prevent recursive paint
"""
view = dgt.parent()
offset = view.verticalOffset() + option.rect.y()
# Check if still in viewport
if view_would_not_be_visible(view, offset):
return None
try:
thumb_path = dgt.get_thumb_path_if_exists(view, offset, qtindex)
if thumb_path is not None:
# Check if still in viewport
if view_would_not_be_visible(view, offset):
return None
# Read the precomputed thumbnail
qimg = read_thumb_as_qimg(thumb_path)
width, height = qimg.width(), qimg.height()
# Adjust the cell size to fit the image
dgt.adjust_thumb_cell_size(qtindex, width, height)
# Check if still in viewport
if view_would_not_be_visible(view, offset):
return None
# Paint image on an item in some view
painter.save()
painter.setClipRect(option.rect)
painter.translate(option.rect.x(), option.rect.y())
painter.drawImage(QtCore.QRectF(0, 0, width, height), qimg)
painter.restore()
except Exception as ex:
# PSA: Always report errors on Exceptions!
print('Error in APIThumbDelegate')
ut.printex(ex, 'Error in APIThumbDelegate')
painter.save()
painter.restore()
示例3: show_matches
def show_matches(qres, ibs, aid, qreq_=None, *args, **kwargs):
from ibeis.viz import viz_matches
try:
return viz_matches.show_matches(ibs, qres, aid, *args, qreq_=qreq_, **kwargs)
except Exception as ex:
ut.printex(ex, 'failed in qres.show_matches', keys=['aid', 'qreq_'])
raise
示例4: update_query_cfg
def update_query_cfg(query_cfg, **cfgdict):
# Each config paramater should be unique
# So updating them all should not cause conflicts
# FIXME: Should be able to infer all the children that need updates
#
# apply codename before updating subconfigs
query_cfg.apply_codename(cfgdict.get('codename', None))
# update subconfigs
query_cfg.nn_cfg.update(**cfgdict)
query_cfg.nnweight_cfg.update(**cfgdict)
query_cfg.sv_cfg.update(**cfgdict)
query_cfg.agg_cfg.update(**cfgdict)
query_cfg.flann_cfg.update(**cfgdict)
query_cfg.smk_cfg.update(**cfgdict)
query_cfg.smk_cfg.vocabassign_cfg.update(**cfgdict)
query_cfg.smk_cfg.vocabtrain_cfg.update(**cfgdict)
query_cfg.rrvsone_cfg.update(**cfgdict)
query_cfg._featweight_cfg.update(**cfgdict)
query_cfg._featweight_cfg._feat_cfg.update(**cfgdict)
query_cfg._featweight_cfg._feat_cfg._chip_cfg.update(**cfgdict)
query_cfg.update(**cfgdict)
# Ensure feasibility of the configuration
try:
query_cfg.make_feasible()
except AssertionError as ex:
print(ut.dict_str(cfgdict, sorted_=True))
ut.printex(ex)
raise
示例5: _get_data
def _get_data(model, qtindex, **kwargs):
#row = qtindex.row()
col = qtindex.column()
row_id = model._get_row_id(qtindex) # row_id w.r.t. to sorting
getter = model.col_getter_list[col] # getter for this column
# Using this getter may not be thread safe
try:
# Should this work around decorators?
#data = getter((row_id,), **kwargs)[0]
data = getter(row_id, **kwargs)
except Exception as ex:
ut.printex(
ex,
'[api_item_model] problem getting in column %r' % (col,),
keys=['model.name', 'getter', 'row_id', 'col', 'qtindex'])
#getting from: %r' % ut.util_str.get_callable_name(getter))
raise
# <HACK: MODEL_CACHE>
#cachekey = (row_id, col)
#try:
# if True: # Cache is disabled
# raise KeyError('')
# #data = model.cache[cachekey]
#except KeyError:
# data = getter(row_id)
# #model.cache[cachekey] = data
# </HACK: MODEL_CACHE>
return data
示例6: package_installer
def package_installer():
"""
system dependent post pyinstaller step
"""
print('[installer] +--- PACKAGE_INSTALLER ---')
#build_win32_inno_installer()
cwd = get_setup_dpath()
# Build the os-appropriate package
if sys.platform.startswith('win32'):
installer_src = build_win32_inno_installer()
installer_fname_fmt = 'ibeis-win32-install-{timestamp}.exe'
elif sys.platform.startswith('darwin'):
installer_src = build_osx_dmg_installer()
installer_fname_fmt = 'ibeis-osx-install-{timestamp}.dmg'
elif sys.platform.startswith('linux'):
installer_src = build_linux_zip_binaries()
installer_fname_fmt = 'ibeis-linux-binary-{timestamp}.zip'
#try:
# raise NotImplementedError('no linux packager (rpm or deb) supported. try running with --build')
#except Exception as ex:
# ut.printex(ex)
#pass
# timestamp the installer name
installer_fname = installer_fname_fmt.format(timestamp=ut.get_timestamp())
installer_dst = join(cwd, 'dist', installer_fname)
try:
ut.move(installer_src, installer_dst)
except Exception as ex:
ut.printex(ex, 'error moving setups', iswarning=True)
print('[installer] L___ FINISH PACKAGE_INSTALLER ___')
示例7: test_ignore_exec_traceback
def test_ignore_exec_traceback():
r"""
CommandLine:
python -m utool.util_decor --test-test_ignore_exec_traceback
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_decor import * # NOQA
>>> result = test_ignore_exec_traceback()
>>> print(result)
"""
import utool as ut
@ut.indent_func
def foobar():
print('foobar')
raise Exception('foobar')
try:
print('printing foobar')
foobar()
except Exception as ex:
#import sys
#exc_type, exc_value, exc_traceback = sys.exc_info()
#print(exc_traceback)
# TODO: ensure decorators are not printed in stack trace
ut.printex(ex, tb=True)
示例8: aggregate_descriptors
def aggregate_descriptors(ibs, aid_list):
""" Aggregates descriptors with inverted information
Return agg_index to(2) -> desc (descriptor)
aid (annotation rowid)
fx (feature index w.r.t. aid)
</CYTH> """
print('[agg_desc] stacking descriptors from %d annotations' % len(aid_list))
desc_list = ibs.get_annot_desc(aid_list)
# Build inverted index of (aid, fx) pairs
aid_nFeat_iter = izip(aid_list, imap(len, desc_list))
nFeat_iter = imap(len, desc_list)
# generate aid inverted index for each feature in each annotation
_ax2_aid = ([aid] * nFeat for (aid, nFeat) in aid_nFeat_iter)
# generate featx inverted index for each feature in each annotation
_ax2_fx = (xrange(nFeat) for nFeat in nFeat_iter)
# Flatten generators into the inverted index
dx2_aid = np.array(list(chain.from_iterable(_ax2_aid)))
dx2_fx = np.array(list(chain.from_iterable(_ax2_fx)))
try:
# Stack descriptors into numpy array corresponding to inverted inexed
dx2_desc = np.vstack(desc_list)
print('[agg_desc] stacked %d descriptors from %d annotations' % (len(dx2_desc), len(aid_list)))
except MemoryError as ex:
utool.printex(ex, 'cannot build inverted index', '[!memerror]')
raise
return dx2_desc, dx2_aid, dx2_fx
示例9: build_flann_inverted_index
def build_flann_inverted_index(ibs, aid_list):
"""
Build a inverted index (using FLANN)
</CYTH> """
try:
if len(aid_list) == 0:
msg = ('len(aid_list) == 0\n'
'Cannot build inverted index without features!')
raise AssertionError(msg)
dx2_desc, dx2_aid, dx2_fx = aggregate_descriptors(ibs, aid_list)
except Exception as ex:
intostr = ibs.get_infostr() # NOQA
dbname = ibs.get_dbname() # NOQA
num_images = ibs.get_num_images() # NOQA
num_annotations = ibs.get_num_annotations() # NOQA
num_names = ibs.get_num_names() # NOQA
utool.printex(ex, '', 'cannot build inverted index', locals().keys())
raise
# Build/Load the flann index
flann_cfgstr = get_flann_cfgstr(ibs, aid_list)
flann_params = {'algorithm': 'kdtree', 'trees': 4}
precomp_kwargs = {'cache_dir': ibs.get_flann_cachedir(),
'cfgstr': flann_cfgstr,
'flann_params': flann_params,
'force_recompute': NOCACHE_FLANN}
flann = nntool.flann_cache(dx2_desc, **precomp_kwargs)
return dx2_desc, dx2_aid, dx2_fx, flann
示例10: add_annot_chips
def add_annot_chips(ibs, aid_list, qreq_=None):
"""
FIXME: This is a dirty dirty function
Adds chip data to the ANNOTATION. (does not create ANNOTATIONs. first use add_annots
and then pass them here to ensure chips are computed) """
# Ensure must be false, otherwise an infinite loop occurs
from ibeis.model.preproc import preproc_chip
cid_list = ibs.get_annot_chip_rowids(aid_list, ensure=False)
dirty_aids = ut.get_dirty_items(aid_list, cid_list)
if len(dirty_aids) > 0:
if ut.VERBOSE:
print('[ibs] adding chips')
try:
# FIXME: Cant be lazy until chip config / delete issue is fixed
preproc_chip.compute_and_write_chips(ibs, aid_list)
#preproc_chip.compute_and_write_chips_lazy(ibs, aid_list)
params_iter = preproc_chip.add_annot_chips_params_gen(ibs, dirty_aids)
except AssertionError as ex:
ut.printex(ex, '[!ibs.add_annot_chips]')
print('[!ibs.add_annot_chips] ' + ut.list_dbgstr('aid_list'))
raise
colnames = (ANNOT_ROWID, 'config_rowid', 'chip_uri', 'chip_width', 'chip_height',)
get_rowid_from_superkey = functools.partial(ibs.get_annot_chip_rowids, ensure=False, qreq_=qreq_)
cid_list = ibs.dbcache.add_cleanly(const.CHIP_TABLE, colnames, params_iter, get_rowid_from_superkey)
return cid_list
示例11: all_figures_bring_to_front
def all_figures_bring_to_front():
try:
all_figures = get_all_figures()
for fig in iter(all_figures):
bring_to_front(fig)
except Exception as ex:
ut.printex(ex)
示例12: _new_image_hesaff
def _new_image_hesaff(img, **kwargs):
""" Creates new detector object which reads the image """
hesaff_params = _make_hesaff_cpp_params(kwargs)
if __DEBUG__:
print('[hes] New Hesaff')
print('[hes] hesaff_params=%r' % (hesaff_params,))
hesaff_args = hesaff_params.values() # pass all parameters to HESAFF_CLIB
rows, cols = img.shape[0:2]
if len(img.shape) == 2:
channels = 1
else:
channels = img.shape[2]
try:
hesaff_ptr = HESAFF_CLIB.new_hesaff_image(
img, rows, cols, channels, *hesaff_args)
except Exception as ex:
msg = ('hesaff_ptr = '
'HESAFF_CLIB.new_hesaff_image(img_realpath, *hesaff_args)')
print(msg)
print('hesaff_args = ')
print(hesaff_args)
import utool
utool.printex(ex, msg, keys=['hesaff_args'])
raise
return hesaff_ptr
示例13: _get_qx2_besrank_iterative
def _get_qx2_besrank_iterative(ibs, qreq, nTotalQueries, nPrevQueries, cfglbl=''):
# TODO: INCORPORATE MINIBATCH SIZE TO MATCH_CHIPS3 AND DEPRICATE THIS
print('[harn] querying one query at a time')
# Make progress message
msg = textwrap.dedent('''
---------------------
[harn] TEST %d/%d ''' + cfglbl + '''
---------------------''')
qx2_bestranks = []
qaids = qreq.qaids # Query one ANNOTATION at a time
mark_prog = utool.simple_progres_func(TESTRES_VERBOSITY, msg, '.')
# Query Chip / Row Loop
for qx, qaid in enumerate(qaids):
mark_prog(qx + nPrevQueries, nTotalQueries)
try:
qreq.qaids = [qaid] # hacky
qaid2_qres = mc3.process_query_request(ibs, qreq, safe=False)
except mf.QueryException as ex:
utool.printex(ex, 'Harness caught Query Exception')
qx2_bestranks.append([-1])
if not STRICT:
continue
raise
try:
assert len(qaid2_qres) == 1, ''
except AssertionError as ex:
utool.printex(ex, key_list=['qaid2_qres'])
raise
# record the best rank from this groundtruth
best_rank = qaid2_qres[qaid].get_best_gt_rank(ibs)
qx2_bestranks.append([best_rank])
qreq.qaids = qaids # fix previous hack
return qx2_bestranks
示例14: cached_wraper
def cached_wraper(*args, **kwargs):
try:
if True:
print('[utool] computing cached function fname_=%s' % (fname_,))
# Implicitly adds use_cache to kwargs
cfgstr = get_cfgstr_from_args(func, args, kwargs, key_argx,
key_kwds, kwdefaults, argnames)
assert cfgstr is not None, 'cfgstr=%r cannot be None' % (cfgstr,)
if kwargs.get('use_cache', use_cache_):
# Make cfgstr from specified input
data = cacher.tryload(cfgstr)
if data is not None:
return data
# Cached missed compute function
data = func(*args, **kwargs)
# Cache save
cacher.save(data, cfgstr)
return data
except Exception as ex:
import utool
_dbgdict2 = dict(key_argx=key_argx, lenargs=len(args), lenkw=len(kwargs),)
msg = '\n'.join([
'+--- UTOOL --- ERROR IN CACHED FUNCTION',
#'dbgdict = ' + utool.dict_str(_dbgdict),
'dbgdict2 = ' + utool.dict_str(_dbgdict2),
])
utool.printex(ex, msg)
raise
示例15: translated_call
def translated_call(**kwargs):
try:
resp_tup = translate_ibeis_webcall(func, **kwargs)
rawreturn, success, code, message, jQuery_callback = resp_tup
except WebException as webex:
ut.printex(webex)
rawreturn = ''
if DEBUG_PYTHON_STACK_TRACE_JSON_RESPONSE:
rawreturn = str(traceback.format_exc())
success = False
code = webex.code
message = webex.message
jQuery_callback = None
except Exception as ex:
ut.printex(ex)
rawreturn = ''
if DEBUG_PYTHON_STACK_TRACE_JSON_RESPONSE:
rawreturn = str(traceback.format_exc())
success = False
code = 500
message = 'API error, Python Exception thrown: %r' % (str(ex))
if "'int' object is not iterable" in message:
rawreturn = (
'HINT: the input for this call is most likely '
'expected to be a list. Try adding a comma at '
'the end of the input (to cast the conversion '
'into a list) or encapsualte the input with '
'[].')
jQuery_callback = None
webreturn = translate_ibeis_webreturn(rawreturn, success,
code, message,
jQuery_callback)
return flask.make_response(webreturn, code)