__init__.py
49 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
r2 | # -*- coding: utf-8 -*- | |||
r112 | # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors | |||
r2 | # | |||
r112 | # Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | ||||
# You may obtain a copy of the License at | ||||
r2 | # | |||
r112 | # http://www.apache.org/licenses/LICENSE-2.0 | |||
r2 | # | |||
r112 | # Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
# See the License for the specific language governing permissions and | ||||
# limitations under the License. | ||||
r2 | ||||
"""Miscellaneous support packages for {{project}}. | ||||
""" | ||||
import random | ||||
import string | ||||
import importlib | ||||
from appenlight_client.exceptions import get_current_traceback | ||||
def generate_random_string(chars=10): | ||||
r153 | return "".join(random.sample(string.ascii_letters * 2 + string.digits, chars)) | |||
r2 | ||||
def to_integer_safe(input): | ||||
try: | ||||
return int(input) | ||||
r153 | except (TypeError, ValueError): | |||
r2 | return None | |||
r21 | ||||
r2 | def print_traceback(log): | |||
r153 | traceback = get_current_traceback( | |||
skip=1, show_hidden_frames=True, ignore_system_exceptions=True | ||||
) | ||||
r2 | exception_text = traceback.exception | |||
log.error(exception_text) | ||||
log.error(traceback.plaintext) | ||||
del traceback | ||||
r21 | ||||
r2 | def get_callable(import_string): | |||
r153 | import_module, indexer_callable = import_string.split(":") | |||
return getattr(importlib.import_module(import_module), indexer_callable) | ||||