__init__.py
70 lines
| 2.2 KiB
| text/x-python
|
PythonLexer
/ vcsserver / __init__.py
r0 | # RhodeCode VCSServer provides access to different vcs backends via network. | |||
r1126 | # Copyright (C) 2014-2023 RhodeCode GmbH | |||
r0 | # | |||
# This program is free software; you can redistribute it and/or modify | ||||
# it under the terms of the GNU General Public License as published by | ||||
# the Free Software Foundation; either version 3 of the License, or | ||||
# (at your option) any later version. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU General Public License | ||||
# along with this program; if not, write to the Free Software Foundation, | ||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
r1188 | import os | |||
r0 | ||||
r1189 | __version__ = '' | |||
r0 | ||||
r1188 | def get_version(): | |||
r1189 | global __version__ | |||
if __version__: | ||||
return __version__ | ||||
r1188 | here = os.path.abspath(os.path.dirname(__file__)) | |||
ver_file = os.path.join(here, "VERSION") | ||||
with open(ver_file, "rt") as f: | ||||
version = f.read().strip() | ||||
r1189 | __version__ = version | |||
r1188 | return version | |||
r519 | ||||
# link to config for pyramid | ||||
CONFIG = {} | ||||
r1310 | ||||
class ConfigGet: | ||||
NotGiven = object() | ||||
def _get_val_or_missing(self, key, missing): | ||||
if key not in CONFIG: | ||||
if missing == self.NotGiven: | ||||
return missing | ||||
# we don't get key, we don't get missing value, return nothing similar as config.get(key) | ||||
return None | ||||
else: | ||||
val = CONFIG[key] | ||||
return val | ||||
def get_str(self, key, missing=NotGiven): | ||||
from vcsserver.lib.str_utils import safe_str | ||||
val = self._get_val_or_missing(key, missing) | ||||
return safe_str(val) | ||||
def get_int(self, key, missing=NotGiven): | ||||
from vcsserver.lib.str_utils import safe_int | ||||
val = self._get_val_or_missing(key, missing) | ||||
return safe_int(val) | ||||
def get_bool(self, key, missing=NotGiven): | ||||
from vcsserver.lib.type_utils import str2bool | ||||
val = self._get_val_or_missing(key, missing) | ||||
return str2bool(val) | ||||
r519 | # Populated with the settings dictionary from application init in | |||
# | ||||
PYRAMID_SETTINGS = {} | ||||